Closed qwerty19106 closed 1 year ago
Correct pin mode for SPI and other peripherals is Alternate<N>
. There is 3 mode converts in your workaround code: Input -> Output -> Input -> Alternate
. Last inside SPI initialization code. Should be 1.
I've added possibility to pass pins to peripheral in any mode, but it was not very good idea. Possibly I'll delete it in future.
set/set_speed
is implemented for alternate pins. So your code should looks like:
let sck1 = gpioa.pa5.into_alternate().speed(Speed::VeryHigh);
let miso1 = gpioa.pa6.into_alternate().speed(Speed::VeryHigh);
let mosi1 = gpioa.pa7.into_alternate().speed(Speed::VeryHigh);
let spi1 = dp.SPI1.spi(
(sck1, miso1, mosi1),
hal::spi::MODE_3,
2.MHz(),
&clocks,
);
Anyway it would be good to add description of this potential issue in spi
docs/examples.
I use
stm32f4xx-hal=0.14.0
,cortex-m-rtic = 1.1
, tested onSTM32F411CE
andSTM32F446RE
.Simple SPI initialization spawn this bug at the some SYSCLK and PCLK frequencies. For example,
STM32F411CE
spawn bug atSYSCLK=100.MHz()
, but atSYSCLK=80.MHz()
no errors.Presumably it occurs due to slow GPIO speed. This code fix bit error in my case:
See issue with the same error in other HAL for details.
I want create PR, but I need help. The
set_speed
is method ofPin
, butSpi::new
getPins<SPI>
. I propose addpub trait SetSpeed
to add it intoPins<SPI>
implementation. Are there other ways to fix this?