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

Unify examples and update hal #296

Merged
merged 1 commit into from
Nov 1, 2023
Merged

Conversation

MabezDev
Copy link
Member

@MabezDev MabezDev commented Oct 19, 2023

This PR merges the chip-specific examples into one folder, inside the esp-wifi project. To simplify building, alias' have been added to esp-wifi/.cargo/config.toml per chip to automatically select the right target and enable the chip feature. I've also used git esp-hal to benefit from the recent unification efforts there.

Before this PR:

$ cd examples-$CHIP
$ cargo run --example X --features $CHIP,etc

After this PR:

cd esp-wifi
cargo $CHIP --example X --features etc

For example, cargo esp32c3 --example dhcp --features wifi.

I think this syntax is close to what it was before, and much easier to remember than each specific target name if you just want to run a quick example. It's also important to note, this change doesn't affect downstream users of esp-wifi, just folks running the examples in this repo.

TODO

  • Update CI
  • Find a nicer solution for the timer initialization other than cfg(riscv) etc
  • Update examples.md
  • Use Xtensa executor within esp-hal instead of generic single core embassy-executor
  • Use a default time driver for async so it doesn't have to be specified

Unanswered questions

  • What to do about examples that can't run on certain chips?
    • Initially I wondered if we could utilize required-features in cargo but I don't think that will work
    • We could just use compiler_error! to error out on certain example/target combos

@bugadani

This comment was marked as outdated.

@bjoernQ
Copy link
Contributor

bjoernQ commented Oct 20, 2023

Good idea to use [alias]

I guess using compile_error! if an example isn't suitable for a specific target should be good enough

@MabezDev
Copy link
Member Author

cc: @jessebraham I'd like to get your input as to whether this is a good idea or an insane one :D

esp-wifi/Cargo.toml Outdated Show resolved Hide resolved
@jessebraham
Copy link
Member

jessebraham commented Oct 20, 2023

I think this looks pretty reasonable! Interesting use of aliases, never thought of doing this before. Possibly a little insane, but when has that ever stopped us before 😁

Find a nicer solution for the timer initialization other than cfg(riscv) etc

Is there any reason not to just use embassy-time-timg0 for every chip in the examples? I recall speaking with @bjoernQ about making esp-wifi more generic about which timers/alarms it accepts, if this is the only limitation maybe something we can look into? I can't recall how feasible this is, if at all.

Other random though, does the rust-toolchain.toml file in the root not cause issues with the RISC-V chips? Should this just be removed?

@MabezDev
Copy link
Member Author

Is there any reason not to just use embassy-time-timg0 for every chip in the examples? I recall speaking with @bjoernQ about making esp-wifi more generic about which timers/alarms it accepts, if this is the only limitation maybe something we can look into? I can't recall how feasible this is, if at all.

Good point, we should look at doing that.

Other random though, does the rust-toolchain.toml file in the root not cause issues with the RISC-V chips? Should this just be removed?

I don't think so, esp toolchain has RISCV compiled too, so in theory, it shouldn't make a difference.

@jessebraham
Copy link
Member

I don't think so, esp toolchain has RISCV compiled too, so in theory, it shouldn't make a difference.

Ahh right I always forget about this detail. Disregard 😁

@bjoernQ
Copy link
Contributor

bjoernQ commented Oct 23, 2023

Is there any reason not to just use embassy-time-timg0 for every chip in the examples? I recall speaking with @bjoernQ about making esp-wifi more generic about which timers/alarms it accepts, if this is the only limitation maybe something we can look into? I can't recall how feasible this is, if at all.

We could add a feature to choose the timer used by esp-wifi internally - might be a useful. Probably not really something that fits into this PR though

@MabezDev MabezDev force-pushed the simplify-examples branch 14 times, most recently from 0f71d5f to fd174bc Compare October 26, 2023 13:32
@bugadani bugadani mentioned this pull request Oct 31, 2023
@bugadani bugadani mentioned this pull request Oct 31, 2023
@MabezDev MabezDev changed the title Unify examples Unify examples and update hal Oct 31, 2023
@MabezDev MabezDev marked this pull request as ready for review October 31, 2023 17:48
@MabezDev
Copy link
Member Author

This is now ready for a review, the last cfg issue IMO isn't that big of a deal and something we can sort in another PR.

@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 1, 2023

Unfortunately, all BLE examples (ble, embassy_ble, coex) crash on ESP32-C3 while they work on main

Exception 'Store/AMO access fault' mepc=0x4005882e, mtval=0x3fc00100
0x4005882e - r_sch_plan_offset_req_hook
    at ??:??
0x3fc00100 - _sidata
    at ??:??
...

They do work fine on ESP32-S3 (their BLE implementations are very similar)

@bugadani
Copy link
Contributor

bugadani commented Nov 1, 2023

Unfortunately, all BLE examples (ble, embassy_ble, coex) crash on ESP32-C3 while they work on main

Exception 'Store/AMO access fault' mepc=0x4005882e, mtval=0x3fc00100
0x4005882e - r_sch_plan_offset_req_hook
    at ??:??
0x3fc00100 - _sidata
    at ??:??
...

They do work fine on ESP32-S3 (their BLE implementations are very similar)

Is it possible that this comes from the HAL update for some reason and not the rest of this monster?

@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 1, 2023

Unfortunately, all BLE examples (ble, embassy_ble, coex) crash on ESP32-C3 while they work on main

Exception 'Store/AMO access fault' mepc=0x4005882e, mtval=0x3fc00100
0x4005882e - r_sch_plan_offset_req_hook
    at ??:??
0x3fc00100 - _sidata
    at ??:??
...

They do work fine on ESP32-S3 (their BLE implementations are very similar)

Is it possible that this comes from the HAL update for some reason and not the rest of this monster?

I'm almost sure it's the HAL update - will be fun to identify the exact commit since the range is huge

@MabezDev MabezDev force-pushed the simplify-examples branch 2 times, most recently from 22a4540 to cf922a0 Compare November 1, 2023 11:06
@MabezDev
Copy link
Member Author

MabezDev commented Nov 1, 2023

The esp32c6 also works, so I guess it's not RISCV-specific.

@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 1, 2023

❯ git bisect bad
d81994552226ca8e69e9d774aef50aa1c0550a31 is the first bad commit
commit d81994552226ca8e69e9d774aef50aa1c0550a31
Author: jneem <[email protected]>
Date:   Fri Sep 29 10:09:50 2023 -0500

    Sleep support for esp32c3 (#795)

    * Make the example work

    * Make GPIO wakeups work

    * Add example

    * revert hello_rgb change

    * Clean up the first hacky version

    * Fix example warnings

    * Add changelog entry

    * Fix example comment

    * Stop skipping rustfmt

 CHANGELOG.md                                     |   1 +
 esp-hal-common/src/gpio.rs                       |  51 +-
 esp-hal-common/src/rtc_cntl/mod.rs               |  12 +-
 esp-hal-common/src/rtc_cntl/rtc/esp32c3_sleep.rs | 893 +++++++++++++++++++++++
 esp-hal-common/src/rtc_cntl/sleep.rs             |  18 +-
 esp-hal-common/src/soc/esp32c3/gpio.rs           |  11 +
 esp32c3-hal/examples/sleep_timer.rs              |  41 ++
 esp32c3-hal/examples/sleep_timer_rtcio.rs        |  58 ++
 8 files changed, 1077 insertions(+), 8 deletions(-)
 create mode 100644 esp-hal-common/src/rtc_cntl/rtc/esp32c3_sleep.rs
 create mode 100644 esp32c3-hal/examples/sleep_timer.rs
 create mode 100644 esp32c3-hal/examples/sleep_timer_rtcio.rs

@MabezDev
Copy link
Member Author

MabezDev commented Nov 1, 2023

❯ git bisect bad
d81994552226ca8e69e9d774aef50aa1c0550a31 is the first bad commit
commit d81994552226ca8e69e9d774aef50aa1c0550a31
Author: jneem <[email protected]>
Date:   Fri Sep 29 10:09:50 2023 -0500

    Sleep support for esp32c3 (#795)

    * Make the example work

    * Make GPIO wakeups work

    * Add example

    * revert hello_rgb change

    * Clean up the first hacky version

    * Fix example warnings

    * Add changelog entry

    * Fix example comment

    * Stop skipping rustfmt

 CHANGELOG.md                                     |   1 +
 esp-hal-common/src/gpio.rs                       |  51 +-
 esp-hal-common/src/rtc_cntl/mod.rs               |  12 +-
 esp-hal-common/src/rtc_cntl/rtc/esp32c3_sleep.rs | 893 +++++++++++++++++++++++
 esp-hal-common/src/rtc_cntl/sleep.rs             |  18 +-
 esp-hal-common/src/soc/esp32c3/gpio.rs           |  11 +
 esp32c3-hal/examples/sleep_timer.rs              |  41 ++
 esp32c3-hal/examples/sleep_timer_rtcio.rs        |  58 ++
 8 files changed, 1077 insertions(+), 8 deletions(-)
 create mode 100644 esp-hal-common/src/rtc_cntl/rtc/esp32c3_sleep.rs
 create mode 100644 esp32c3-hal/examples/sleep_timer.rs
 create mode 100644 esp32c3-hal/examples/sleep_timer_rtcio.rs

I guess its https://github.com/esp-rs/esp-hal/pull/795/files#diff-13b76e7f6d000776921729c895984b5ce03e1657df0c93a36411d63fce98cd45R216, but we need to figure out which "base setting" has messed things up... fun 🙃

@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 1, 2023

Yes, it's exactly that .... commenting that makes it work again

@MabezDev MabezDev force-pushed the simplify-examples branch 2 times, most recently from dbe4b15 to 51c8abc Compare November 1, 2023 11:57
@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 1, 2023

Yes, it's exactly that .... commenting that makes it work again

I think I know how to make it work ... will create a PR in esp-hal when I verified it

@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 1, 2023

Fix in esp-hal: esp-rs/esp-hal#891

@jessebraham
Copy link
Member

If we can find a couple other small, compatible changes to make in esp-hal, I wouldn't mind doing a patch release of esp-hal-common to make these changes available.

This PR merges the chip specific examples into one folder, inside the
esp-wifi project.

To simplify building, alias' have been added to
`esp-wifi/.cargo/config.toml` per chip to automatically select the right
target and enable the chip feature.

Add build script detection for invalid features

Fix CI, use build instead of check to detect linker errors

enable async feature of hal, this breaks because of interrupt definition for systimer

upgrade hal rev

upgrade hal rev c6

undo binding modifications

fix esp now

fix esp coex

use released hals, update async examples

sync example names

sync example names

Update examples.md

Document alias

update build alias
@MabezDev
Copy link
Member Author

MabezDev commented Nov 1, 2023

I'm keen to get this merged, so I've gone ahead and patched the c3 hal for now. We can replace it with a new release later.

Copy link
Contributor

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

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

Thanks! This should make maintaining the examples much easier

@MabezDev MabezDev merged commit 7632e74 into esp-rs:main Nov 1, 2023
7 checks passed
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.

4 participants