-
Notifications
You must be signed in to change notification settings - Fork 220
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
Add new function esp_hal::try_init
#2618
base: main
Are you sure you want to change the base?
Conversation
58ceaff
to
6bfebd8
Compare
Thanks for the PR! What is the use case for this API? |
try_init
esp_hal::try_init
Still working on getting the functionality exactly how I want it, will update the thread shortly! |
6bfebd8
to
99c9ee4
Compare
Done! I'm ready to move this out of drafts, but please let me know if I need to implement more |
99c9ee4
to
45cb161
Compare
462b113
to
df22375
Compare
8397711
to
090b8b8
Compare
Is there a specific issue you were running into where using I have some thoughts on this, and sorry for the questions, I just need to understand the rationale for the PR. |
No worries! I'm happy to answer any and all questions. *or something else that causes the panic handler to spontaneously restart half way through execution (P.S. sorry, meant to post this reply last night and forgot to hit send) |
I still don't understand what you are trying to do. Why is |
It's not clear to me how calling |
@bugadani Its not that |
I don't think we can make any assumptions from the panic handler. Particularly if the panic is a result of UB (stack overflow corrupting some state etc) or a hardware fault and we're panicking from the exception handler. Calling I think the best course of action is to assume nothing and pretend to Thank you for the PR, I'm inclined to close this based on my reasoning above, but I'll wait a little while to be convinced otherwise if you have some more arguments for it :). |
@jessebraham It's not What I have introduced here with
|
Calling
This is why I used an
I'd be happy to do that if
If you'd still like to close it, go right ahead. I've already determined that I can implement what I want by taking advantage of the |
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
cargo xtask fmt-packages
command to ensure that all changed code is formatted correctly.CHANGELOG.md
in the proper section.Extra:
Pull Request Details 📖
Description
Adds a new function
esp_hal::try_init
. This function initializes the system only if it hasn't been already, then steals the peripherals and returns them.The main use case for this functionality is for panic handlers that require peripheral access (e.g. to notify the user that a panic has occurred on a hardware display). The panic handler should not rely on the prior initialization of the system. However, if it has not yet been initialized,
steal
ing the peripherals is insufficient. In contrast, trying to re-initialize the system from inside the panic handler causes the panic handler to get caught in a death loop if the main program has already calledinit
. Thetry_init
function will check if the system has already been initialized and, if not, will callinit_internal
(where I have moved the implementation ofinit
, aside from the taking of the peripherals). The output is always the stolen peripherals, and as such the function is marked asunsafe
.Previously,
Peripherals::take()
would unsafely check an unmangledstatic mut bool
. This PR replaces that with anAtomicBool
to ensure (attempt) safety.Testing
Some simple tests have been added to
hil-test
, but I cannot verify its success as I do not own a JTAG-compatible board.In lieu of this, I wrote a small crate to verify my changes worked as expected. The board used is the Wemos LOLIN32 with a built-in SSD1306 OLED display (unofficial info about the board can be found here, I cannot find any reference to it from Wemos themselves). The ESP module on the board is an ESP32-WROOM-32.
The
src/main.rs
(contents below) file contains several commented-outmain
functions with explanations as to what each one is for. Each one was flashed to the board and executed separately and successfully. I will continue to try to implement similar tests to the main functions above inhil-test
, but I'm still working out how I could do so in a board-agnostic fashion.