stm32f1: implement spi_prepare
Implement spi_prepare to fix the undefined behavior on SPI transaction start. Tested with the following command sequence: allocate_oids count=2 config_spi oid=0 bus=0 pin=PA8 mode=3 rate=1000000 shutdown_msg= config_spi oid=1 bus=0 pin=PA8 mode=1 rate=1000000 shutdown_msg= spi_send oid=0 data=30313233343536373839 spi_transfer oid=1 data=3031 Discussion about this here: https://github.com/KevinOConnor/klipper/pull/453#issuecomment-403131149 Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
This commit is contained in:
parent
ebd9035325
commit
2991c7a831
|
@ -303,15 +303,14 @@ spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
|
||||||
void
|
void
|
||||||
spi_prepare(struct spi_config config)
|
spi_prepare(struct spi_config config)
|
||||||
{
|
{
|
||||||
|
*SPI2 = config.config;
|
||||||
|
LL_SPI_Enable(SPI2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
spi_transfer(struct spi_config config, uint8_t receive_data,
|
spi_transfer(struct spi_config config, uint8_t receive_data,
|
||||||
uint8_t len, uint8_t *data)
|
uint8_t len, uint8_t *data)
|
||||||
{
|
{
|
||||||
*SPI2 = config.config;
|
|
||||||
LL_SPI_Enable(SPI2);
|
|
||||||
|
|
||||||
while (len--) {
|
while (len--) {
|
||||||
LL_SPI_TransmitData8(SPI2, *data);
|
LL_SPI_TransmitData8(SPI2, *data);
|
||||||
while (!LL_SPI_IsActiveFlag_TXE(SPI2));
|
while (!LL_SPI_IsActiveFlag_TXE(SPI2));
|
||||||
|
|
Loading…
Reference in New Issue