Error Detection for SPI DMA Master->Slave
Hello,
I have an STM32F373 and setup a master uC and slave uC to communicate over SPI with DMA enabled. I send a fixed packet size of 10bytes and have set the DMA size to 20bytes in case I need a double buffer for my solution. I enabled a SS/CS output pin on the master which goes active low when sending data to the slave. I enabled an EXTI input pin on the slave to detect the master setting the SS/CS pin low or high, with the interrupt enabled for rising and falling edge in case I need those for my solution.
Currently, I don't use the EXTI interrupts since I use the DMA half-transfer interrupt to detect when a full 10 byte packet has been received. For now, I plan on clearing the SPI DMA in this interrupt so the second half of the DMA buffer will never really be used unless I implement a double buffer.
I see a flaw in my design; What if the slave's SPI DMA potentially fills with a few bytes due to noise? Let's say the SPI gets 1 byte of noise, the DMA half-transfer interrupt would then be triggered at 9bytes of the packet received which is a problem. The SPI DMA may be out-of-sync for any following packet, always triggering the Half-Transfer or Transfer-Complete interrupts at 9bytes of packet received. I need to reset the DMA pointer somehow.
I was thinking of enabling the SPI when the SS pin goes active low, resetting the DMA buffer pointer, and then disabling the SPI when the SS pin goes high. This may not work since the slave may start receiving SPI data from the master before it gets a change to enable SPI in the EXTi interrupt.
I thought of adding some type of watch-dog timer to reset the SPI DMA rx pointer after 1ms or so, but realize I may be creating another problem.
Any suggestions on how to best handle this? Is there a good way to handle all error conditions and retries? ( I can add a request-select pin going from slave to master if needed )
Thank you!
