cancel
Showing results for 
Search instead for 
Did you mean: 

Safe to call HAL_SPI_Receive_DMA() in interrupt context?

BMcDo.3
Associate III

HAL_SPI_Receive_DMA() is non-blocking; it just sets up and starts a transfer. Is it safe to call it from an interrupt context?

If it is (at least possibly or sometimes) safe, does it make a difference whether the SPI port is configured as SPI_MODE_MASTER or SPI_MODE_SLAVE? And whether it is bidirectional (SPI_DIRECTION_2LINES) or receive-only (SPI_DIRECTION_2LINES_RXONLY)?

If it is unsafe, why?

1 REPLY 1
w343vaughn
Associate

It should be safe. All that should matter is that you can receive. If you are reading from a sensor, you can send the address (or whatever config info to the sensor), then in the tx complete call back set a DMA rx to read back the data. This is a good option if you are reading a lot of data. 

The only hazard may be the DMA_Rx function being called in more than 1 ISR. Not sure if it will just reset the DMA controller or if it checks that a transaction is not already in progress.