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

Add support for the ESP32-C6 #392

Merged
merged 64 commits into from
Feb 27, 2023
Merged

Conversation

jessebraham
Copy link
Member

@jessebraham jessebraham commented Feb 10, 2023

This is still a work in progress, however we're nearing completion so I think it's ready enough to start getting some eyes on it.

Unfortunately there were some hiccups with the git history, so things are a bit messy there; I've tried to fix things as much as possible but there are still some oddities.

At this point I have tested all examples, and all are functional except for the following:

  • clock_monitor
  • i2s_sound
  • twai

The twai example is failing in the same way as the ESP32 and ESP32-S2, so we can likely hold off on completing this until #341 is resolved.

The esp_hal_common::rtc_cntl and esp_hal_common::rtc_cntl::rtc modules are still being worked on by @JurajSadel and will hopefully be completed soon; this will allow us to complete the clock_monitor example.

In addition to the above, I seem to be experiencing linker errors when trying to build any of the embassy_*, pcnt_encoder, or ram examples when using the direct-boot feature; they build fine without it. Not sure what's going on here.

Thank you to all who have contributed to this work, looking forward to getting it merged :)

Closes #219


TODO

  • Publish the esp32c6 package and remove the git dependency
  • Use published releases of esp-println and esp-backtrace
  • Get the clock_monitor and i2s_sound examples working
    • The clock_monitor example will be fixed in a separate PR
  • Resolve 'direct-boot' linker errors

@MabezDev
Copy link
Member

FYI I tried looking at the direct boot errors but didn't actually run into any? Do you know how to reproduce? We should also make sure we apply the fix from #386 to the direct boot linker scripts too

@bjoernQ
Copy link
Contributor

bjoernQ commented Feb 21, 2023

FYI I tried looking at the direct boot errors but didn't actually run into any? Do you know how to reproduce? We should also make sure we apply the fix from #386 to the direct boot linker scripts too

I can at least reproduce linker errors for the pcnt_encoder and the ram example when using the direct-boot feature

@jessebraham
Copy link
Member Author

jessebraham commented Feb 21, 2023

@MabezDev I think there's something funny going on with my dev environment, let me try again.

@jessebraham jessebraham marked this pull request as ready for review February 23, 2023 17:43
README.md Outdated Show resolved Hide resolved
@bjoernQ
Copy link
Contributor

bjoernQ commented Feb 24, 2023

I tried all the examples we have for ESP32-C6 (only boot-loader mode). Not too bad but seems there are a few issues (some with the examples themselves and some with the driver, mostly clock related)

These are my results

adc.rs 🆗
advanced_serial.rs - baud rate is half (57600)
aes.rs 🆗
blinky.rs 🆗
blinky_erased_pins.rs - example code uses gpio 0 as a button but it's gpio 9
embassy_hello_world.rs 🆗
embassy_spi.rs - SCLK is 50kHz (i.e. it's half)
embassy_wait.rs - example code uses gpio 0 as a button but it's gpio 9
gpio_interrupt.rs 🆗
hello_rgb.rs 🆗
hello_world.rs 🆗
i2c_bmp180_calibration_data.rs 🆗
i2c_display.rs 🆗
i2s_read.rs - example descriptions mentions MCLK but it's not used, seems ok 🆗
i2s_sound.rs - tested with PCM5102, sounds okay in release mode 🆗
ledc.rs 🆗
mcpwm.rs 🆗
pcnt_encoder.rs - limits don't work?
pulse_control.rs 🆗
ram.rs 🆗
read_efuse.rs 🆗
rtc_watchdog.rs - seems it waits longer than 5 secs - so clocks seem to be off
serial_interrupts.rs - AT command detection not working
sha.rs 🆗
spi_eh1_device_loopback.rs - SCLK is 500kHz, should be 1000kHz
spi_eh1_loopback.rs - SCLK is 500kHz, should be 1000kHz
spi_loopback.rs - SCLK is 50kHz (i.e. it's half)
spi_loopback_dma.rs - SCLK is 50kHz (i.e. it's half)
systimer.rs 🆗
timer_interrupt.rs 🆗
usb_serial_jtag.rs - unable to get this to work - but might a problem with my OS since I can't even connect to the serial port
watchdog.rs 🆗

@jessebraham
Copy link
Member Author

jessebraham commented Feb 24, 2023

Building on top of @bjoernQ's testing, with my latest commits here is the current status of testing:

Example idf-bootloader direct-boot
adc
advanced_serial
aes
blinky
blinky_erased_pins
embassy_hello_world
embassy_spi
embassy_wait
gpio_interrupt
hello_rgb
hello_world
i2c_bmp180_calibration_data
i2c_display
i2s_read
i2s_sound
ledc
mcpwm
pcnt_encoder
pulse_control
ram
read_efuse
rtc_watchdog
serial_interrupts
sha
spi_eh1_device_loopback
spi_eh1_loopback
spi_loopback
spi_loopback_dma
systimer
timer_interrupt
usb_serial_jtag
watchdog

✅ = working as expected
⏰ = (suspected) clock issues
❔ = sort of working, but something is off
❌ = not working

I will update this table as I continue to test. Hopefully these remaining examples aren't too difficult to crack.


I've tested most of the examples using direct-boot now, plus a large number using idf-bootloader (the default).

For whatever reason I seem to be getting panics when using direct-boot seemingly with anything using DMA. Going to be something to investigate next week.

I've fixed the UART clocks, so we should be good to go there. Working on the SPI clocks, will get that wrapped up either this afternoon or next week depending on how it goes.

The blinky_erased_pins example works however it seems that only one in N button presses are actually detected; this is consistent between image formats. Probably not worth blocking on but there's something weird going on there.

The ledc example seems to mostly work but the frequency is not quite correct. This, however, seems to be the case for other chips as well, so likely does not matter.

Copy link
Member

@MabezDev MabezDev left a comment

Choose a reason for hiding this comment

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

Little bit late, sorry! I found a few things I think we should address before merging :)

Self {
phantom: PhantomData::default(),
}
}

#[cfg(esp32c6)]
fn enable_clock() {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we be using our already established PeripheralClockControl struct instead of this one off function?

Copy link
Contributor

Choose a reason for hiding this comment

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

We are missing some peripherals for that PeripheralClockControl enable thing. For example, sha, adc, usb-serial-jtag don't take a mutable reference to PeripheralClockControl - we can address all of them in a separate PR.

README.md Outdated Show resolved Hide resolved
esp-hal-common/src/interrupt/riscv.rs Outdated Show resolved Hide resolved
esp-hal-common/src/rtc_cntl/mod.rs Outdated Show resolved Hide resolved
esp-hal-common/src/rtc_cntl/mod.rs Show resolved Hide resolved
esp-hal-common/src/rtc_cntl/rtc/esp32c6.rs Show resolved Hide resolved
esp-hal-common/src/rtc_cntl/rtc/esp32c6.rs Outdated Show resolved Hide resolved
esp-hal-common/src/system.rs Outdated Show resolved Hide resolved
esp-hal-common/src/system.rs Outdated Show resolved Hide resolved
esp-hal-common/src/uart.rs Show resolved Hide resolved
@bjoernQ
Copy link
Contributor

bjoernQ commented Feb 27, 2023

The blinky_erased_pins example works however it seems that only one in N button presses are actually detected; this is consistent between image formats. Probably not worth blocking on but there's something weird going on there.

That's exactly how the example works - it just reads the state of the button after the delay. So while it is not a good example of how to write real-world code it works as expected then.

@bjoernQ
Copy link
Contributor

bjoernQ commented Feb 27, 2023

Seems I found the problem with serial_interrupts .... will prepare a PR for it

Update: it's here jessebraham#5

@bjoernQ
Copy link
Contributor

bjoernQ commented Feb 27, 2023

I fixed the DMA issues in direct-boot mode here: jessebraham#7

bjoernQ and others added 6 commits February 27, 2023 06:47
* fix SPI clocks

* run cargo fmt

* Add comment about used default clk src

* Fix rtc_watchdog example in BL mode

* run cargo fmt

* Update rtc_watchdog example that it works in DB mode
@jessebraham
Copy link
Member Author

I think at this point all examples are functioning as expected, both using the idf-bootloader format as well as direct-boot.

This PR is still far from perfect, but I think the remaining problems are isolated enough that we can create issues for them and address them individually; I'm not sure how much more we stand to gain by nitpicking this PR.

@bjoernQ and @MabezDev, let me know how you're feeling about the state of this PR, please.

@JurajSadel, @bjoernQ, and @MabezDev, thanks for all the work on this over the last couple months! It's been quite the learning experience for us and hopefully this will be easier in the future as a result.

@bjoernQ
Copy link
Contributor

bjoernQ commented Feb 27, 2023

I agree this is okay to get merged and the remaining issues should be addressed after the merge

@MabezDev
Copy link
Member

I think this is in a good enough spot for merging! The few odd bits can be solved later :).

@jessebraham jessebraham merged commit d293d9f into esp-rs:main Feb 27, 2023
@jessebraham jessebraham deleted the feature/esp32c6 branch February 27, 2023 17:30
MabezDev added a commit to MabezDev/esp-hal that referenced this pull request Mar 31, 2023
* Create the `esp32c6-hal` package

* Teach `esp-hal-common` about the ESP32-C6

* Get a number of peripheral drivers building for the ESP32-C6

bckup

initial clocks_ii

* Create the `esp32c6-hal` package

C6: update

* Simplify and fix the linker script

update

* C6: add I2S

* Create the `esp32c6-hal` package

* Teach `esp-hal-common` about the ESP32-C6

* Get a number of peripheral drivers building for the ESP32-C6

bckup

initial clocks_ii

* Create the `esp32c6-hal` package

* C6: update

* Simplify and fix the linker script

* update

* C6: add I2S

* update

* C6 Interrupts

* C6: Update build.rs, linker scripts and initial examples

* C6: RMT

* Fix interrupt handling

* Fix `ClockControl::configure`

* C6: revert to I2S0 instead of just I2S

* C6: rebase and update

* RTC not buildable

* Implement RWDT and SWD disable

* C6: working LEDC

* C6: working RMT

* C6: add aes

* C6: add mcpwm

* C6: add rtc_cntln - not finished

* C6: update and formatting

* C6: add pcnt

* C6: add examples and format

* Remove inline assembly, fix interrupts and linker scripts

* Remove unused features, update cargo config for atomic emu, misc cleanup

* Get ADC building and example "working" (as much as it ever does)

* Remove a bunch of unused constants which were copied from ESP-IDF

* The `mcpwm` example now works correctly

* Get `TWAI` peripheral driver building for C6

* Clean up the `rtc_cntl` module and get all the other HALs building again

* Add the C6 to our CI workflow

* Fix various things that have been missed when rebasing

Still missing a few examples (`clock_monitor`, `embassy_spi`, `ram`)

* C6: Small updates in wdt (esp-rs#1)

* C6: Update WDT

* C6: Update examples with WDT update

* Update `esp-println` dependency to fix build errors

* Fix formatting issues causing pre-commit hook to fail

* Get some more examples working

* Working `ram` example

* Sync with changes in `main` after rebasing

* Working `embassy_spi` example

* Use a git dependency for the PAC until we publish a release

* Fix I2S for ESP32-C6

* Fix esp32c6 direct boot (esp-rs#4)

* Add direct boot support for C6

* Fix direct boot for c6

- Actually copy into rtc ram
- remove dummy section that is no longer needed (was just a waste of
  flash space)
- Move RTC stuff before the no load sections

* Update RWDT and refactor RTC (esp-rs#3)

* C6: Update RWDT and add example, refactor RTC and add not-really-good example

* Update based on review comments, resolve bunch of warnings and run cargo fmt

* Update C6 esp-pacs rev commit

* Fix clocks_ll/esp32c6.rs

* Fix riscv interrupts

* Remove clock_monitor example for now

* RAM example works in direct-boot mode

* Add a TODO for &mut TIMG0 and cargo fmt

* Fix linker script after a bad rebase

* Update CI and Cargo.toml embassy required features

* use riscv32imac-unknown-none-elf target for C6 in CI

* change default target to riscv32imac-unknown-none-elf

* add riscv32imac-unknown-none-elf target to MSRV job

* another cleanup

---------

Co-authored-by: bjoernQ <[email protected]>
Co-authored-by: Jesse Braham <[email protected]>

* Make required changes to include new `RADIO` peripheral

* Use published versions of PAC and `esp-println`

* Use the correct target extensions (`imac`)

* Fix the super watchdog timer, plus a few more examples

* Fix UART clock configuration

* Make sure to sync UART registers when configuring AT cmd detection

* Disable APM in direct-boot mode

* Address a number of review comments

* Fix `SPI` clocks and `rtc_watchdog` example  (esp-rs#6)

* fix SPI clocks

* run cargo fmt

* Add comment about used default clk src

* Fix rtc_watchdog example in BL mode

* run cargo fmt

* Update rtc_watchdog example that it works in DB mode

* README and example fixes/cleanup

* Add I2C peripheral enable and reset

* Fix `ApbSarAdc` configuration in `system.rs`

---------

Co-authored-by: bjoernQ <[email protected]>
Co-authored-by: Juraj Sadel <[email protected]>
Co-authored-by: Juraj Sadel <[email protected]>
Co-authored-by: Scott Mabin <[email protected]>
i404788 pushed a commit to i404788/esp-hal that referenced this pull request Jul 22, 2023
* Create the `esp32c6-hal` package

* Teach `esp-hal-common` about the ESP32-C6

* Get a number of peripheral drivers building for the ESP32-C6

bckup

initial clocks_ii

* Create the `esp32c6-hal` package

C6: update

* Simplify and fix the linker script

update

* C6: add I2S

* Create the `esp32c6-hal` package

* Teach `esp-hal-common` about the ESP32-C6

* Get a number of peripheral drivers building for the ESP32-C6

bckup

initial clocks_ii

* Create the `esp32c6-hal` package

* C6: update

* Simplify and fix the linker script

* update

* C6: add I2S

* update

* C6 Interrupts

* C6: Update build.rs, linker scripts and initial examples

* C6: RMT

* Fix interrupt handling

* Fix `ClockControl::configure`

* C6: revert to I2S0 instead of just I2S

* C6: rebase and update

* RTC not buildable

* Implement RWDT and SWD disable

* C6: working LEDC

* C6: working RMT

* C6: add aes

* C6: add mcpwm

* C6: add rtc_cntln - not finished

* C6: update and formatting

* C6: add pcnt

* C6: add examples and format

* Remove inline assembly, fix interrupts and linker scripts

* Remove unused features, update cargo config for atomic emu, misc cleanup

* Get ADC building and example "working" (as much as it ever does)

* Remove a bunch of unused constants which were copied from ESP-IDF

* The `mcpwm` example now works correctly

* Get `TWAI` peripheral driver building for C6

* Clean up the `rtc_cntl` module and get all the other HALs building again

* Add the C6 to our CI workflow

* Fix various things that have been missed when rebasing

Still missing a few examples (`clock_monitor`, `embassy_spi`, `ram`)

* C6: Small updates in wdt (#1)

* C6: Update WDT

* C6: Update examples with WDT update

* Update `esp-println` dependency to fix build errors

* Fix formatting issues causing pre-commit hook to fail

* Get some more examples working

* Working `ram` example

* Sync with changes in `main` after rebasing

* Working `embassy_spi` example

* Use a git dependency for the PAC until we publish a release

* Fix I2S for ESP32-C6

* Fix esp32c6 direct boot (esp-rs#4)

* Add direct boot support for C6

* Fix direct boot for c6

- Actually copy into rtc ram
- remove dummy section that is no longer needed (was just a waste of
  flash space)
- Move RTC stuff before the no load sections

* Update RWDT and refactor RTC (esp-rs#3)

* C6: Update RWDT and add example, refactor RTC and add not-really-good example

* Update based on review comments, resolve bunch of warnings and run cargo fmt

* Update C6 esp-pacs rev commit

* Fix clocks_ll/esp32c6.rs

* Fix riscv interrupts

* Remove clock_monitor example for now

* RAM example works in direct-boot mode

* Add a TODO for &mut TIMG0 and cargo fmt

* Fix linker script after a bad rebase

* Update CI and Cargo.toml embassy required features

* use riscv32imac-unknown-none-elf target for C6 in CI

* change default target to riscv32imac-unknown-none-elf

* add riscv32imac-unknown-none-elf target to MSRV job

* another cleanup

---------

Co-authored-by: bjoernQ <[email protected]>
Co-authored-by: Jesse Braham <[email protected]>

* Make required changes to include new `RADIO` peripheral

* Use published versions of PAC and `esp-println`

* Use the correct target extensions (`imac`)

* Fix the super watchdog timer, plus a few more examples

* Fix UART clock configuration

* Make sure to sync UART registers when configuring AT cmd detection

* Disable APM in direct-boot mode

* Address a number of review comments

* Fix `SPI` clocks and `rtc_watchdog` example  (esp-rs#6)

* fix SPI clocks

* run cargo fmt

* Add comment about used default clk src

* Fix rtc_watchdog example in BL mode

* run cargo fmt

* Update rtc_watchdog example that it works in DB mode

* README and example fixes/cleanup

* Add I2C peripheral enable and reset

* Fix `ApbSarAdc` configuration in `system.rs`

---------

Co-authored-by: bjoernQ <[email protected]>
Co-authored-by: Juraj Sadel <[email protected]>
Co-authored-by: Juraj Sadel <[email protected]>
Co-authored-by: Scott Mabin <[email protected]>
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.

Add support for the ESP32-C6
4 participants