-
Notifications
You must be signed in to change notification settings - Fork 7.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TW#27664] esp_restart fails to work properly if hardware timers are used #2756
Comments
@X-Ryl669 Could you please post the log output, including restart messages, panic handler output and the subsequent backtraces, ideally decoded through idf_monitor? Also, can you say whether you are calling timer_isr_register on CPU0 or CPU1, and whether you are calling esp_restart on CPU0 or CPU1? Thanks. |
With timer_pause
With no timer pausing
Code for registering the timer is:
I've not pinned the http server task to any cpu, so I don't know which one's calling |
Is it possible that In IDF, global constructors are called before FreeRTOS scheduler has started. It seems like |
It works when powered up regularly. The code of the TimerISR is this:
The part that fails is in the
So it's not a global variable (I'm using singleton), it's created on first call ( The timers are created in The issue I experience is mainly that the timer is fired on reboot while it's not yet "created" (although Also, what is the second "double exception vector" that happens way after the application is started when the timers are paused on reboot ? |
With such code, are you sure that
I can't explain this part (how it is redirected to the right ISR before the ISR has been registered). The only possible explanation was that the ISR was registered from a global constructor, but if this isn't the case, that's puzzling. Do you think you can reduce the application to something that still reproduces the issue and that you might be able to share privately? |
I'm not sure, that's the issue. As I understand it, the ISR shouldn't be called while Side question: What is the first entry point I can override (before FreeRTOS is running) so I can dump the HW timer's register to check what's left or not after the reset ? Also, if I stop the timers, it does not happen or it's not visible it does (the app starts, but crash later on when the SNTP client sets the time). I'll try to strip this part to a simple app I can share. I'll need few days to make this. |
However this (theoretically) should not matter, since the CPU interrupt input for respective interrupt is only unmasked when There is a way to check this, though. First, set log level to "Debug" in menuconfig. Note the message similar to
at the start of esp_intr_alloc. |
Looking at the
You're not touching BIT15, Timer Group1 and BIT13, Timer Group0, only BIT0, Timers. Is it enough to reset all the timers registers to default value ? |
Ok, I'll try what you're asking to figure this out. As a side note, if I ask to reset the timer group like this:
before restarting, it should actually clean the HW timers's registers, right ? |
Just thought a bit more about this, that starts to make sense. My Timer constructor is like this:
The timer is not started when this is called, since there is no However, if, when calling this the timer is still running like you're saying (because the restart did not stop it), then it can happen that it fires right there after Logically, I have this in my
If the timer is running here before it's really started in the code, then yes, that's the issue, since it'll trigger before EventLoop queue is created. Shouldn't have |
Ok, I've just tested your idea, and it happens where it should (within app_main). I've checked that timer_init does not clear a pending interrupt (so if the timer triggers during restart, and the interrupt were disabled (as they are in IMHO it's a bug. I've tried to reset the HW timer (via The other bug I'm mentionning (double exception) is not due to timer (I've more informations), so I'll open another issue for this to avoid confusion. |
Yes, correct.
I agree, this would make sense. |
Hi, @X-Ryl669 Thanks in advance :-) |
Thanks, I'll let you know tomorrow after testing. |
Hi, @X-Ryl669 |
Well, sorry, I was busy with my other development. I've made a fix on my own before and I need to revert and use yours to check if it's working. I'll let you know ASAP. |
Ok, your code is working for me. |
Using lastest master as of writing, whenever I've started a timer with an installed interruption (in fact, I'm using 3 HW timers as I need precise ~90µs wake up) and call
esp_restart
, the system crash upon restart.The callstack contains my timer's ISR routine, and it crashes when it's trying to send an event to a FreeRTOS queue within ISR.
It seems the timer fired after the restart but before FreeRTOS was started correctly.
I've tried to disable all the timer's interrupt (via
timer_disable_intr
) and this does not make any change (and readingesp_restart_noos
code, that's what you're doing anyway).I wonder if, when the system is starting, if timer interrupt are re-enabled before the RTOS is correctly initialized, this would explain the behavior ?
If I pause all the timer before restarting, it restarts correctly for few seconds, but crash later on in
double exception vector
, (located in FreeRTOS's assembly, without a backtrace in that case).Restarting via the serial link always work correctly, so I wonder if there is a way to restart the complete CPU correctly (both core at the same time, with clean state), instead of having to deal with both core independently, and with left over peripherals messing things up ?
BTW, my code is too big now to isolate a working example.
The text was updated successfully, but these errors were encountered: