AnsweredAssumed Answered

[Solved] How to properly stop/cancel a (SPI) DMA transfer when CRC is enabled?

Question asked by CaCO3.CaCO3 on Oct 7, 2015
Latest reply on Oct 12, 2015 by CaCO3.CaCO3
I have a SPI slave (RX only) and need to use it with CRC check enabled (STM32F4, 8bit CRC generator of SPI unit).
To process the high amount of data, I use a P2M DMA.
What is the correct way to stop/cancel a DMA transfer, before it is completed?

Currently, I do it in this way:
void init(void){
   HAL_SPI_Receive_DMA(&hspi1, SPI_RX_Buffer, 10); //start DMA
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi){
  HAL_SPI_Receive_DMA(&hspi1, SPI_RX_Buffer, 10); //restart DMA
void BUTTON_PRESS(void){
  HAL_DMA_Abort(&hdma_spi1_rx); // Aborting a (possibly incomplete) DMA transfer
  HAL_SPI_Receive_DMA(&hspi1, SPI_RX_Buffer, 15); //restart DMA with different length

This works fine, but only, if the CRC check is disabled!

If I enable the CRC check:
  hspi1.Init.CRCPolynomial = 0x10;
it hangs in the function
Specifically on the line
which is a macro for
hdma->Instance->CR &=  ~DMA_SxCR_EN

So my question in summary:
How do I properly stop/cancel a SPI RX DMA transfer, when the CRC generator is enabled?