Skip to content

Add all SPI examples for the ESP32-H2 #549

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

Merged
merged 14 commits into from
May 31, 2023

Conversation

jessebraham
Copy link
Member

Adds all SPI-related examples for the ESP32-H2. This involved updating the GDMA and SPI peripheral drivers.

This was verified on hardware by @SergioGasquez and @JurajSadel, however I committed some git crimes since then so probably wouldn't hurt just to triple-check the examples.

@jessebraham jessebraham requested review from bjoernQ and MabezDev May 17, 2023 15:40
@jessebraham jessebraham mentioned this pull request May 17, 2023
5 tasks
@bjoernQ
Copy link
Contributor

bjoernQ commented May 17, 2023

Maybe it would make sense to change the pins - at least on my boards GPIO7 doesn't seem to be available on the pin headers

@SergioGasquez
Copy link
Member

Maybe it would make sense to change the pins - at least on my boards GPIO7 doesn't seem to be available on the pin headers

Agree, here is the diff my pin changes that I've used for testing: pins.zip

@SergioGasquez
Copy link
Member

Btw, just tested the examples again and all of them seem to be working!

@jessebraham
Copy link
Member Author

Maybe it would make sense to change the pins - at least on my boards GPIO7 doesn't seem to be available on the pin headers

Everybody seems to have different dev kits, I already have to change the pins for a bunch of examples in the repo so I guess I don't really care what they're set to. If you want them changed please tell me which pins to change them to.

@bjoernQ
Copy link
Contributor

bjoernQ commented May 17, 2023

Ah yes GPIO 6 is also not available.

Also the clock seems to be slightly off:

image

The spi_loopback.rs example requests 100u32.kHz()

Also I guess we could add qspi_flash.rs (I have one of those flash chips so I can verify that)

@bjoernQ
Copy link
Contributor

bjoernQ commented May 17, 2023

Yep qspi_flash.rs works - I used these pins

    let sclk = io.pins.gpio1;
    let miso = io.pins.gpio2;
    let mosi = io.pins.gpio3;
    let sio2 = io.pins.gpio4;
    let sio3 = io.pins.gpio5;
    let cs = io.pins.gpio11;

@jessebraham
Copy link
Member Author

Okay thanks, I'll update each example to use those pins and add the missing example.

@SergioGasquez
Copy link
Member

SergioGasquez commented May 19, 2023

I've been investigating the frequency issue, here is what I've found:

I was able to solve it by using the XTAL clock (changing to 0 in https://github.com/esp-rs/esp-hal/pull/549/files#diff-13231643cd8aa34e91c614e3f5280962f1e3f2c53a8fa3012786d95865eaf3e6R2149):
image

Looking at esp-idf source, H2 and C6 default clock is the PLL and, the select method is the same for H2 and C6

The thing is, according to the TRM if we want to use the PLL clock, 1 should be correct, although it's 48M in C2 and 80M in C6.

@bjoernQ tested (my C6 devkit is not working for some reason) if the frequency issue was also present in C6, since it should be the same, but C6 works fine.

@jessebraham jessebraham force-pushed the feature/esp32h2-spi branch from 8a07cc6 to f8d4d3b Compare May 23, 2023 14:23
@jessebraham
Copy link
Member Author

I've rebased and updated the SPI clock configuration as per the above comment. @SergioGasquez would you mind please verifying that things are now working correctly?

@SergioGasquez
Copy link
Member

I've rebased and updated the SPI clock configuration as per the above comment. @SergioGasquez would you mind please verifying that things are now working correctly?

Just tried the spi_lookback example with the recent changes and freq seems to be working fine:
image

@jessebraham jessebraham force-pushed the feature/esp32h2-spi branch from f8d4d3b to 7b92921 Compare May 23, 2023 14:45
@bjoernQ
Copy link
Contributor

bjoernQ commented May 23, 2023

but using XTAL_CLK would mean we limit the max SPI speed 🤔

@bjoernQ
Copy link
Contributor

bjoernQ commented May 23, 2023

XTAL_CLOCK works because there is this

let apb_clk_freq: HertzU32 = HertzU32::Hz(clocks.apb_clock.to_Hz());

And we have

           desired_rates: RawClocks {
                cpu_clock: HertzU32::MHz(96),
                apb_clock: HertzU32::MHz(32),
                xtal_clock: HertzU32::MHz(32),
                i2c_clock: HertzU32::MHz(32),
            },

So, the APB_CLOCK of 32MHz matches the XTAL_CLK

@jessebraham jessebraham marked this pull request as draft May 24, 2023 13:59
@jessebraham jessebraham force-pushed the feature/esp32h2-spi branch from ebea2c5 to 2f88b2e Compare May 29, 2023 14:34
@jessebraham
Copy link
Member Author

I've fixed the comment and rebased this branch again.

Given that the SPI data transfer seems to be working (as indicated by the success of the various SPI examples) and that we have a lot of clock-related issues across the board for the H2, I think this is probably okay to merge as-is unless anybody has any major objections.

@bjoernQ
Copy link
Contributor

bjoernQ commented May 30, 2023

Probably doesn't make sense to further block this but we should probably create an issue to remind us to re-think the choose of the clock source here?

@JurajSadel
Copy link
Contributor

I'm doing some testing based on internal discussion, please don't merge this yet

@JurajSadel
Copy link
Contributor

When CI is green this should be ready for final review. I tested all examples with LA but QSPI, @bjoernQ could you please try that?

@JurajSadel JurajSadel marked this pull request as ready for review May 30, 2023 14:35
@bjoernQ
Copy link
Contributor

bjoernQ commented May 31, 2023

qspi_flash example works. Also using pll_48m_clock is the right fix for this 👍 This would also be needed to fix TIMG

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.

LGTM

@JurajSadel JurajSadel force-pushed the feature/esp32h2-spi branch from 909ce12 to bb1c605 Compare May 31, 2023 07:26
@bjoernQ
Copy link
Contributor

bjoernQ commented May 31, 2023

Frequency seems fine

image

Copy link
Member

@SergioGasquez SergioGasquez left a comment

Choose a reason for hiding this comment

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

Changes LGTM, although I couldn't verify the freq as my LA decided not to work

@JurajSadel JurajSadel merged commit d86300f into esp-rs:main May 31, 2023
MabezDev pushed a commit to MabezDev/esp-hal that referenced this pull request Jun 1, 2023
* Update the `GDMA` driver to support the ESP32-H2

* Update the `SPI` driver to support the ESP32-H2

* Add `SPI` examples for ESP32-H2

* Update CHANGELOG

* Remove copy-pasted references to ESP32-C6

* Update GPIO pins used in SPI examples, add `qspi_flash` example

* Update SPI clock configuration to produce correct clock rate

* Correct comment regarding clock source frequency

Co-authored-by: Sergio Gasquez Arcos <sergio.gasquez@gmail.com>

* H2: Add PLL_48M_CLK src to ClockControl and RawClocks

* H2: Use PLL_48M_CLK as SPI clk src

* H2: cleanup commented block in SPI driver

* H2: update docs comment in embassy_spi example

* fmt

* Add a new line in embassy_spi example

---------

Co-authored-by: Sergio Gasquez Arcos <sergio.gasquez@gmail.com>
Co-authored-by: Juraj Sadel <juraj.sadel@espressif.com>
SergioGasquez added a commit to SergioGasquez/esp-hal that referenced this pull request Jun 9, 2023
* Update the `GDMA` driver to support the ESP32-H2

* Update the `SPI` driver to support the ESP32-H2

* Add `SPI` examples for ESP32-H2

* Update CHANGELOG

* Remove copy-pasted references to ESP32-C6

* Update GPIO pins used in SPI examples, add `qspi_flash` example

* Update SPI clock configuration to produce correct clock rate

* Correct comment regarding clock source frequency

Co-authored-by: Sergio Gasquez Arcos <sergio.gasquez@gmail.com>

* H2: Add PLL_48M_CLK src to ClockControl and RawClocks

* H2: Use PLL_48M_CLK as SPI clk src

* H2: cleanup commented block in SPI driver

* H2: update docs comment in embassy_spi example

* fmt

* Add a new line in embassy_spi example

---------

Co-authored-by: Sergio Gasquez Arcos <sergio.gasquez@gmail.com>
Co-authored-by: Juraj Sadel <juraj.sadel@espressif.com>
@jessebraham jessebraham deleted the feature/esp32h2-spi branch August 24, 2023 13:36
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