-
Notifications
You must be signed in to change notification settings - Fork 261
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
esp32c3 how to change SPI bus clock speed #204
Comments
Thanks for bringing this up! I think having this feature would be quite useful Option 1 seems to be the right thing but it also needs the Option 2 is a problem since the driver doesn't hold |
OK. I am not sure if I can implement it but I will give it a try. |
Sounds great! In case you get stuck or have questions - we are happy to help |
Fix by #235 |
Some time ago I wrote an SD Card driver for the Longan Nano to provide filesystem access through the fatfs crate. I am now porting it to the esp32c3.
I am running into an issue when I want to change the clock speed of the SPI bus. For the initialization of the card, the SPI bus clock rate must be set between 100 kHz and 400 kHz. Then the SCLK frequency should be changed to 20-25 MHz to maximize the read/write performance.
My driver
Card
struct receives ownership of the SPI peripheral, the pins, the SPIMode variant,&Clocks
and&mut SystemClockControl
from the user through this call:and then creates the
esp32c3_hal::spi::Spi
struct with a bus frequency of 400 KHz by callingSpi::new_no_cs()
. So far so good.Now, to increase the bus speed to 20 MHz I tried to
Spi::free()
the Spi and recreate a new one by callingSpi::new_internal()
BUT the driver struct I no longer has the&mut PeripheralClockControl
that is required for that call. How can I solve this issue?I see 2 options:
esp32c3_hal::spi::Spi
to change the bus clock speed. That is what the gd32vf103xx_hal does.I think it would need to call thespi::Instance::setup()
method inhal-common
.Spi::free()
could also return&mut PeripheralClockControl
so that it can be re-injected in a following call toSpi::new_internal()
. This approach has the disadvantage that I have to keep the&Clocks
around in theCard
struct, which contaminates the crate with lifetimes everywhere.The text was updated successfully, but these errors were encountered: