What is the correct way to recover from an SPI error or a timeout?
Lets say i call HAL_SPI_TransmitReceive_DMA() and then I get an error or I decide to timeout while waiting for SPI data. What is the correct way to recover from an SPI error or a timeout?
I use this code and it seems to work:
// De-init SPI2
HAL_SPI_DeInit(&hspi2);
// Reset SPI2
__HAL_RCC_SPI2_FORCE_RESET();
__NOP();
__NOP();
__HAL_RCC_SPI2_RELEASE_RESET();
__NOP();
__NOP();
// Reset DMA1
__HAL_RCC_DMA1_FORCE_RESET();
__NOP();
__NOP();
__HAL_RCC_DMA1_RELEASE_RESET();
__NOP();
__NOP();
// Re-init DMA and SPI
MX_DMA_Init();
MX_SPI2_Init();