-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
fix(gptimer): race on FSM state in gptimer_start() (IDFGH-13929) #14767
base: master
Are you sure you want to change the base?
Conversation
👋 Hello Lsitar, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
sha=4fd888b7a9b58692f8c52370034e6f214fec626b |
@suda-morris do You know, or have estimate, when this will be pulled to master, or rejected? I ask because we are waiting with IDF update. I know I can modify the IDF another way, but I prefer to take a "clean" official revision to CI. |
Actual behaviour
gptimer_start()
may be interrupted between timer start and setting fsm state GPTIMER_FSM_RUN, so other functions may see wrong state of gptimer and misbehave,e.g.
gptimer_start()
may be interrupted by gptimer callback and in this callback calledgptimer_stop()
sees wrong fsm state.Expected behaviour
"APIs provided by the driver are guaranteed to be thread safe, (...) are allowed to run under ISR context."
as in https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/gptimer.html#thread-safety
Description
it is 6 months since I encountered and described the problem, but it got no attention.
https://esp32.com/viewtopic.php?f=13&t=39428
Now I need the newer ESP-IDF and therefore need to fix the race condition in gptimer, as described on the forum.
I'm sure there is race, but I'm not sure if my fix is the right one, as the issue is caused by FSM design and it may still have similar issues.
Testing
To reproduce this problem, it may be important that when this timer code is executed, simultaneously are received ADC samples at 16 kSPS, triggering gpio ISR at every sample. I tried it without doing SPI transfer and also without the ADC running, but the GPTimer race is the same.
There is alternative fix at application level: blocking sheduler while timer start fixes the race, actually masks the problem