-
Notifications
You must be signed in to change notification settings - Fork 786
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
Embassy HAL implementation for Espressif chips #745
Comments
Great to see the interested of running embassy on espressif! 🚀
👍 ! The 'core' of the executor is arch-independent, but the the different arch-dependent executor parts can be found here: https://github.com/embassy-rs/embassy/tree/master/embassy/src/executor/arch The cortex_m one might be the most relevant to look at.
In addition to the embedded-hal(-async) traits, embassy has the concept of an opt-in 'timer driver' system timer that is implemented for most HALs, which makes async timers just work. For instance: https://github.com/embassy-rs/embassy/blob/master/embassy/src/time/driver.rs and an implementation: There is also the There is also some hardware specific stuff in the macros that's needed for users to use the |
Thanks for the pointers! For HAL peripheral implementations I also saw the |
It's to allow creating drivers with (It has nothing to do with async, it's a design decision the embassy HALs make, you can do different design decisions if you like) |
Hi everyone, I made it by stitching together the assembler code responsible for setting up the interrupt table from [esp-hal] (https://github.com/esp-rs/esp-hal) , as well as using some of the existing traits / implementations from embedded-hal to write to the UART0 peripheral. Some of what I have working is:
Interrupts are handled differently on the ESP32C3 board, I'm not sure if the same interrupt controller is used for other ESP boards, either way, another area that would need porting is interrupts, this would require
Finally, one last thing to do would be to have compatibility with |
This is awesome! Thanks @osobiehl, I'll take a in-depth look soon!
Yes the c3 uses a custom interrupt controller, and the next few chips will too. Longer-term I believe we will integrate the standard PLIC. Perhaps we can find an abstraction that supports PLIC & custom interrupt controllers (I know there are other RISCV chips out there with them) without special behaviour inside embassy. |
I've just opened #804 based on your work @osobiehl, thank you for laying the groundwork! I've also been working on the |
I've opened a PR in Edit: this has now been merged. |
In case anybody wants to follow progress, I've created some tracking issues in
|
How close is this to useable ? Especially on the Xtensa ESP32 base device (not S/C etc) |
@markfarnan as things stand currently:
|
A quick update 6~ weeks on: We have two async drivers in esp-hal: and we also have two forms of async networking through esp-wifi
|
@Dirbaio embassy switched from using Some further context from this discussion:
In other words, even though embassy doesn't require CAS, rustc doesn't emit even the types themselves.
Could #1125 be reverted to restore embassy support to esp32c3? Side note: Could someone more knowledgeable on the subject open an issue in rustc to get the codegen working for this and link to the issue? |
I don't think anything needs to be changed in embassy. We have atomic emulation in esp-hal for the esp32c3 and esp32c2 enabled by default. You just need to add the following rustflags to your project from the riscv-atomic-emulation-trap handler: https://github.com/esp-rs/riscv-atomic-emulation-trap#usage. Atomic load/stores on RISCV are implemented as a normal load/store (essentially zero cost) and I believe CAS will actually be handled by atomic-polyfill where possible because it is set to polyfill for any riscv target: https://github.com/embassy-rs/atomic-polyfill/blob/80cee72cf0e583e6fccefa8ee463d66ad9aa05d8/build.rs#L31. To ensure that is the case, you could remove the CAS related cfg's from the rustflags list above. |
doesn't this require trap handlers get taken on any load or store on an atomic? I would assume that is bad for performance. If we don't need CAS, but we do need atomic loads/stores, is using the trap handler really the right approach? Disclaimer: I have no experience with atomics at the assembly level or codegen. I'm asking about this because I am trying to understand and learn, and am trying to understand what the performance tradeoffs here are. |
#1125 removed It is (IMO) a rust bug that load/store atomics aren't exposed in That's what should be fixed, instead of adding workarounds to Embassy. |
Awesome, thanks for the added context :) |
I'm a little confused by current status.
I'm looking at maybe switching from CircuitPython to Embassy for broader hardware support. In order for the port to make sense, I'd need BLE, i2c, i2s, spi/qspi, and gpio (preferably with interrupts) already working across nrf52840, esp32-s3, and esp32-c6 (as implemented in the Adafruit Feather boards, for the nrf and the s3). If there's anything I can do to help out, I'm all ears, but I'll be the first to admit limited expertise with low-level hardware work. |
All the eha traits are now implemented (I've updated the check list). The remaining async drivers can be tracked here: esp-rs/esp-hal#361. From your list async i2c,spi,gpio and BLE are already available. Async I2S is being worked on. |
Does this make Embassy now useable, (for the peripherals which are done),
or are there other blocking issues ?
…On Wed, Sep 20, 2023 at 2:24 PM Scott Mabin ***@***.***> wrote:
All the eha traits are now implemented (I've updated the check list). The
remaining async drivers can be tracked here: esp-rs/esp-hal#361
<esp-rs/esp-hal#361>. From your list async
i2c,spi,gpio and BLE are already available. Async I2S is being worked on.
—
Reply to this email directly, view it on GitHub
<#745 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFRFHIAL2NZV7JNEGOVGBIDX3LN6PANCNFSM5U3UEYFA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Yes, its been more than usable since February this year :) |
Thanks for the update, MabezDev. I noticed after the update, interrupts still remain unchecked, and your message didn't mention them. Just for clarity, do you know if interrupts are still a work in progress? |
An interrupt executor != interrupts (See the note about them here: https://embassy.dev/book/dev/runtime.html). Interrupts are essentially a requirements for async, and have been supported in esp-hal since esp-rs/esp-hal#118 & esp-rs/esp-hal#103. Thanks to @bugadani we do actually have an interrupt executor inside esp-hal, but currently it's only for our Xtensa chips at the moment, which is why I haven't checked it off. |
Is there a guide to using Embassy with ESP32 ? (It's not listed on in the
Embassy main guide, less I'm blind)
…On Wed, Sep 20, 2023 at 5:45 PM Scott Mabin ***@***.***> wrote:
An interrupt executor != interrupts (See the note about them here:
https://embassy.dev/book/dev/runtime.html). Interrupts are essentially a
requirements for async, and have been supported in esp-hal since
esp-rs/esp-hal#118 <esp-rs/esp-hal#118> &
esp-rs/esp-hal#103 <esp-rs/esp-hal#103>.
Thanks to @bugadani <https://github.com/bugadani> we do actually have an
interrupt executor inside esp-hal, but currently it's only for our Xtensa
chips at the moment, which is why I haven't checked it off.
—
Reply to this email directly, view it on GitHub
<#745 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFRFHIGLP4BTL4Y4OB7G6K3X3MFSPANCNFSM5U3UEYFA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Check https://github.com/esp-rs/awesome-esp-rust for general esp32 rust stuff, and if you want a more complex firmware that uses it with embassy, you can reference https://github.com/SlimeVR/SlimeVR-Rust/tree/main/firmware. The best source of information though is the example code in |
I think we can consider this done, we have excellent embassy support in esp-hal including but not limited to:
Thanks to everyone involved in making this possible! ❤️ |
We're looking to implement the required traits/executors for Espressif chips, do you have any pointers on what we'll need to implement in our HAL's?
So far it looks like we'll need:
embassy-time::Driver
implementation for each chipThe text was updated successfully, but these errors were encountered: