I'm doing a STM32 SPI slave with DMA and hardware NSS. I want to be able to read an arbitrary lenght of data. When the SPI transfer size and the DMA size matches all goes well. Example I have a buffer:
uint8_t data[16] = { 1,2,3,4,5,6,7,8,9,10,11,12,13, 14, 15, 16};
If I keep calling:
HAL_SPI_Transmit_DMA(&hspi2, data, 13);
and try to read exactly 13 bytes for SPI transfer all goes well... I receive 1,2,3,4,5,6,7,8,9,10,11,12,13.
But If I call
HAL_SPI_Transmit_DMA(&hspi2, data, 16);
and read 13 bytes then I get scrooling data (1..13 in first transfer, then 14, 15, 16,1,2,... in the next and so on).
So I tried to restart the DMA after NSS goes up by calling:
HAL_DMA_Abort(&hdma_spi2_tx);
HAL_SPI_DMAStop(&hspi2);
then I get 13,1,2,3,4,5,6,7,8,9,10,11,12 in all transfers. Seems a last byte got stuck in the shift register. Any ideas about how to solve it?