spiStop() breaks SPI reception on STM32F042
Posted: Fri Apr 17, 2020 7:16 pm
Hi,
I am using an STM32F042 and I want to use the I2C and SPI drivers together. Due to the DMA stream overlap, I need to use the start/stop functionality in both drivers. Still, there seems to be some conflict and I get broken data reception and transmission on SPI. I cannot exactly tell what is wrong (no scope at the moment) but I receive wrong data, and my peripherals behave incorrectly.
If I disable my I2C thread, including all data exchange, the problems reduce to SPI reception errors. When I remove the spiStop() command, everything is fine. Is something wrong with spiStop()?
Here is my spiHelper that exchanges data with the peripherals. It is inspired by the demo applications. I am also using a semaphore that prevents I2C and SPI from acting at the same time.
Thanks in advance!
I am using an STM32F042 and I want to use the I2C and SPI drivers together. Due to the DMA stream overlap, I need to use the start/stop functionality in both drivers. Still, there seems to be some conflict and I get broken data reception and transmission on SPI. I cannot exactly tell what is wrong (no scope at the moment) but I receive wrong data, and my peripherals behave incorrectly.
If I disable my I2C thread, including all data exchange, the problems reduce to SPI reception errors. When I remove the spiStop() command, everything is fine. Is something wrong with spiStop()?
Here is my spiHelper that exchanges data with the peripherals. It is inspired by the demo applications. I am also using a semaphore that prevents I2C and SPI from acting at the same time.
Thanks in advance!
Code: Select all
void spiExchangeHelper(SPIDriver *spi, const SPIConfig *conf, uint32_t length, uint8_t *txbuf, uint8_t *rxbuf)
{
chBSemWait(&dma_lock);
spiStart(spi, conf);
/* Bus acquisition and SPI reprogramming.*/
spiAcquireBus(spi);
/* Slave selection and data transmission.*/
spiSelect(spi);
if (rxbuf != NULL && txbuf != NULL) // exchange data
spiExchange(spi, length, txbuf, rxbuf);
else if (txbuf != NULL && rxbuf == NULL) // only send
spiSend(spi, length, txbuf);
else if (rxbuf != NULL && txbuf == NULL) // only receive
spiReceive(spi, length, rxbuf);
spiUnselect(spi);
/* Releasing the bus.*/
spiReleaseBus(spi);
//spiStop(spi);
chBSemSignal(&dma_lock);
}