-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
attachInterrupt(rxPin, onRx, FALLING) results in immediate reset after updating from 2.0.2 to 2.0.3 (and 2.0.4) #7202
Comments
Confirmed, I also see this error with my ESP32 Dev board. |
@P-R-O-C-H-Y, could you please check it out? I think you have been working on Timers, right? |
Hi @dagnall53, Timer functions cannot be called within ISR same will be with attachInterrupt as they don't have IRAM_ISR attribute. Related issue #6693. |
Hi @P-R-O-C-H-Y .. Thanks for looking at this. I realise that code with a SerialPrint inside the Interrupt is very bad, but it was one way to try and find out (in a huge program) why it would not run under 2.0.3 (+). This code fragment is essentially a UART and we have been using very similar code to swap between Edge Triggered Interrupt (to detect start of transmission) and timed interrupts (to get the actual data) very happily up until now!. Looking at esp32-hal-timer.c I see some big changes from 2.0.2 (left) to 2.0.4. (right). and Although I do not understand them, I wonder if these might be missing something? |
Hi @dagnall53, First about the change in code you sent 2.0.2 - 2.0.4. The Timer API got refactored to use ESP-IDF functions and the I will try to look more into that and find if there is a way to make it work is it was in 2.0.2. |
@P-R-O-C-H-Y . Thanks, it would be great if the original functionality could be retained. In the meantime, have been "playing" and I think that using a token (here "LookingForFalling" ) might be one way to this to possibly work with 2.0.4, by having the timing and edge sensing interrupts running concurrently, with simple switches in their routines. I would appreciate any insights.. EG.. to get the bit timing synchronous with the falling edge I propose to use timerWrite(My_Timer, 0); // reset bit timer?.. will this reset the timer as I expect it to? //This partial code now "Works" with 2.0.4 (or at least it does not crash!!) #define RX_ST_PIN 18 volatile byte rxBitCounter = 0; unsigned long previousMillis ; bool LookingForFalling = false; String debugString = ""; void IRAM_ATTR onRxFall() { void IRAM_ATTR onRxTimer() { if (rxBitCounter == 10) { void Setup_timer () { Setup_done=true; void setup() { Setup_done=false; void loop() { if (millis() >= (previousMillis +5000)){
delay(1); |
@P-R-O-C-H-Y .. After having read the ESP documents, (and maybe partially understanding them), I think that the new interrupt approach is using shared interrupts (?). And that this brings some critical limitations. I am not sure but, it appears one additional limitation appears to be that shared edge triggered interrupts become problematic, and so are converted to level interrupts (I may have seen a compiler verbose comment to this effect ? ) (Is this correct???) Since an edge triggered interrupt is key to timing accuracy in a UART, I am concerned about timing implications, and how to overcome them in a way compatible with 2.0.3 + compiler.. 1: Will all edge triggered interrupts now actually be programmed at assembler as a shared interrupt, LOW detect? If so, its going to make accurate detection of the falling edge exact time of occurance a big problem! 2: If I CAN ( ?how? ) still program a high priority edge triggered interrupt with the new compiler, I know (because it crashes!) that I cannot now do attach and detach inside another ISR. My ‘hack’ is to add a token and a minimal ISR addition that initially checks the token and rapidly returns if the Interrupt is not required. But this seems inelegant and will add a small timing penalty on every falling edge. - Unless there is some other way to switch on / off the interrupt when it is not needed? Comments much appreciated. |
I think that a possible solution for such a critical time application would be use some direct IDF or LL code to detach it, instead of Arduino Classic code... it may require more investigation. |
@P-R-O-C-H-Y / @SuGlider EDIT.. Sorry It would appear that 2.0.5 has not "solved" this problem- |
@SuGlider @P-R-O-C-H-Y This appears to be related to the "immediate trigger" issue discussed in I am assuming that the issue I had with the code was NOT therefore with the ATTACH interrupt, but was actually caused by the timer ? |
@dagnall53 all you did was add that one line? Could you send the whole code again? I am having trouble with ISRs as well. |
Closing this as its solved by refactored driver #7904. |
Board
ESP32 devboard
Device Description
The fault was noted in code that uses a software UART.
I have added a number of debug printlns to explore when and why the code resets repeatedly after being compiled with 2.0.3 (and 2.0.4).
These debug printlns appear to show that the code resets if attachInterrupt(rxPin, onRx, FALLING); is called from within a timer interrupt.
When compiled using 2.0.2, the code functions ok, and progresses past this point and then works fully.
I have made a much simplified code (below) that demonstrates this effect.
Hardware Configuration
Fault occurs with bare board. Resets during setup with 2.0.3 (+) revision compilers. but works with 2.0.2 and earlier.
Version
v2.0.4
IDE Name
Version: 2.0.0-rc9.2 Date: 2022-08-10T13:03:18.962Z CLI Version: 0.26.0-rc.1 [fc2ea723] Copyright © 2022 Arduino SA
Operating System
win10
Flash frequency
80Mhz
PSRAM enabled
no
Upload speed
115200
Description
The problem manifests as the Hardware resetting during code start-up.
BY adding debugprint lines I have traced the issue to a single line that attaches a falling edge interrupt as part of a Timer interrupt.
In "normal" use as compiled by earlier versions (eg 2.0.2), the code will setup a timerAlarmEnable(timer_1);, and do subsequent debug prints and will function as expected.
But with 2.0.3 (+) the code appears to fail and reset the ESP at this line.
This timer interrupt code does many things, but the FIRST time it is run, it stops the timer and Sets a falling edge interrupt. It is this element that appears to be failing.
The UART code was originally designed to overcome the (undocumented?) ESP32 hardware(?) issue that results in the FIRST timer interrupt always occurring immediately after the timer is setup. (If this 'first immediate trigger' was a SOFTWARE fault, it is possible that we can redesign the code to accept 2.0.3 on.. but I have not been able to explore this possibility)
I have sketched the key parts of the code below it does not "do" anything, but it does demonstrate how the code will not complete my setup with compiler 2.0.3 on.
.
Many thanks
Sketch
Debug Message
Other Steps to Reproduce
Code works with previous versions of compiler, its just versions after 2.0.3 that fail.
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: