Skip to content
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

Initial embassy support #225

Merged
merged 17 commits into from
Nov 9, 2022
Merged

Initial embassy support #225

merged 17 commits into from
Nov 9, 2022

Conversation

MabezDev
Copy link
Member

@MabezDev MabezDev commented Oct 24, 2022

The following features are now available in esp-hal-common:

  • async, enables eh1, eha, and embassy-sync
  • embassy, enables embassy-time and the base time driver implementation
  • embassy-time-systick & embassy-time-timg features add embassy driver support for either the systick or timg peripheral
    • Depending on the chip these features are also available on the chip specific hal

This PR also enables atomic emulation for the esp32s2 by default, the examples have been updated. I've also implemented Deref for the Timer wrapping structs to allow calling the underlying functions without boilerplate.

Blocked on

  • Xtensa targets won't build because we need 1.65 release for GAT support in embedded-hal-async

Unresolved issues

Closes #231
Closes #232

@MabezDev MabezDev marked this pull request as draft October 24, 2022 22:19
@bjoernQ
Copy link
Contributor

bjoernQ commented Oct 25, 2022

Awesome! Just out of curiosity: do you know of a roadmap when those git dependencies will get published on crates.io?

@MabezDev MabezDev force-pushed the feature/embassy-initial branch from 726c6b9 to 1b09b1c Compare October 25, 2022 10:25
@jessebraham
Copy link
Member

embassy-time and embassy-sync have both been published on crates.io.

@jessebraham jessebraham force-pushed the feature/embassy-initial branch from 59d7306 to 17aa6a6 Compare November 1, 2022 13:27
@jessebraham
Copy link
Member

I've rebased this on main to pull in my previous CI changes, so that I can take care of the Ci changes needed here.

@MabezDev MabezDev force-pushed the feature/embassy-initial branch 7 times, most recently from ca925e4 to 9a0d099 Compare November 7, 2022 14:08
@MabezDev MabezDev marked this pull request as ready for review November 7, 2022 14:08
@MabezDev
Copy link
Member Author

MabezDev commented Nov 7, 2022

This is now ready for review! Still looking into the S2 issue, but I don't think it's related to the implementation here. It's either a bug in the atomic emulation crate or a codegen issue.

Copy link
Member

@jessebraham jessebraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a handful of comments, but overall it's looking quite good to me. Thanks again for your work on this!

I'm not super excited about the changes required for the ESP32-S2, though that's not your fault at all. I hope we can find a more elegant solution in the future.

esp-hal-common/src/embassy.rs Outdated Show resolved Hide resolved
#[cfg_attr(
all(
feature = "embassy-time-timg",
any(feature = "esp32", feature = "esp32s3", feature = "esp32s2")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this isn't supported for all chips? We should state that somewhere if there is, I think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the timg on the c3 (and I think c2) only has one configurable alarm, so the systick should be used instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that's fine for now then. I do think we either need to document this or define a new configuration symbol in our build script just because it's not immediately clear what's going on by looking at the code. But this can be done later, won't block the PR on it.

esp-hal-common/src/embassy.rs Outdated Show resolved Hide resolved
esp-hal-common/src/embassy/time_driver_systimer.rs Outdated Show resolved Hide resolved
esp-hal-common/src/embassy/time_driver_timg.rs Outdated Show resolved Hide resolved
esp32-hal/examples/embassy_hello_world.rs Outdated Show resolved Hide resolved
@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 8, 2022

Great job! Jesse already did a careful code-review so not too much from my side

  • yes, the boilerplate we now need for the ESP32-S2 examples are annoying - hopefully and most likely we can come up with something more elegant in the future
  • also, in future we need to think about how to get this together with esp-wifi since it's currently very opinionated regarding the use of the timers
  • for the embassy-example we should list all the needed features so users get the right error message (e.g. required-features = ["embassy", "embassy-time-systick"])

Seems like the build failures are just network issues?

@MabezDev MabezDev force-pushed the feature/embassy-initial branch from c2f14d8 to 77c847c Compare November 8, 2022 11:21
@MabezDev
Copy link
Member Author

MabezDev commented Nov 8, 2022

for the embassy-example we should list all the needed features so users get the right error message (e.g. required-features = ["embassy", "embassy-time-systick"])

I don't think we can do this because the time driver is a choice for some chips, like the s2 & s3. Maybe it's possible to improve the error message if a time driver is not selected.

@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 8, 2022

for the embassy-example we should list all the needed features so users get the right error message (e.g. required-features = ["embassy", "embassy-time-systick"])

I don't think we can do this because the time driver is a choice for some chips, like the s2 & s3. Maybe it's possible to improve the error message if a time driver is not selected.

Ah I thought we could make a choice for the user 😄 in general it would be great if every user can get a sample to run at the second attempt (i.e. after learning some feature needs to be specified)

@MabezDev
Copy link
Member Author

MabezDev commented Nov 8, 2022

Ah I thought we could make a choice for the user smile in general it would be great if every user can get a sample to run at the second attempt (i.e. after learning some feature needs to be specified)

I suppose we could but it then makes testing CI harder.

also, in future we need to think about how to get this together with esp-wifi since it's currently very opinionated regarding the use of the timers

I think I will do a follow up PR soon which should address this, but for now I want to get the baseline embassy support in so we can start messing around with some drivers :)

@MabezDev MabezDev force-pushed the feature/embassy-initial branch from 77c847c to 4ea4316 Compare November 8, 2022 14:32
@MabezDev MabezDev requested a review from jessebraham November 9, 2022 13:54
- read_raw on timg renamed to now()
- timg initialized and stored in static for use in the embassy driver
- timg sets alarm value
- untested whether alarms actually trigger
- Adds the timg timer block as a time driver for embassy
- Not enabled on the C3 as it only has one timer block, better to use
  systimer
- s2 example added but can't build due to atomic requirements in
  futures-core
@MabezDev MabezDev force-pushed the feature/embassy-initial branch from 4ea4316 to 39d78c3 Compare November 9, 2022 15:39
Copy link
Member

@jessebraham jessebraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and verified for all chips, so I think we're good to go! Thanks again for your work on this, very excited to move forward with async support!

:shipit:

@jessebraham jessebraham merged commit 9064177 into main Nov 9, 2022
i404788 pushed a commit to i404788/esp-hal that referenced this pull request Nov 9, 2022
* wip: timg embassy driver

- read_raw on timg renamed to now()
- timg initialized and stored in static for use in the embassy driver
- timg sets alarm value
- untested whether alarms actually trigger

* TIMG timer driver for esp32, esp32s3

- Adds the timg timer block as a time driver for embassy
- Not enabled on the C3 as it only has one timer block, better to use
  systimer
- s2 example added but can't build due to atomic requirements in
  futures-core

* Add S2 atomic support with emulation, fixup embassy support for the S2

* Move executor & static-cell to dev deps. Make eha optional

* Add c2 support, run fmt

* Update to crates.io embassy releases

* Update eha

* update timg time driver to new trait

* Remove exception feature of esp-backtrace and use the user handler for backtracing

* Add async testing workflow

* Update systick example

* Fix S2 examples

* Update xtensa-toolchain

* set rustflags for s2 target

* Disable systick for esp32s2 until we can fix the noted issues

* review improvements

- Fix intr prio array being off by one
- emabssy time prio interrupt set to max prio
- use cfg instead of feature for systick detection

* Update example time delays
@MabezDev MabezDev deleted the feature/embassy-initial branch November 9, 2022 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Embassy time driver for TIMG Embassy systick time driver
3 participants