Skip to main content
Associate III
December 9, 2024
Solved

How to cancel HAL_SPI_TransmitReceive_DMA

  • December 9, 2024
  • 2 replies
  • 923 views

How to cancel HAL_SPI_TransmitReceive_DMA

We are developing SPI communication devices using HAL_SPI_TransmitReceive_DMA.
We would like to cancel or stop HAL_SPI_TransmitReceive_DMA even in the middle of transmission by GPIO interrupt, but we do not know how to do it.
Is it possible to cancel in the middle of transmission?
Also, how should I program it?

This topic has been closed for replies.
Best answer by NEdom.1

If you are using SPI to access a large amount of data in SPI flash in a single operation, then you need to stop the DMA operation in some situation. I don't see any stopping DMA mechanism inside HAL_SPI_TransmitReceive_DMA API. I think you might implement your own SPI DMA functions in which you can inject the GPIO interrupt or polling this GPIO to determine whether or not to exit DMA mode. To do this, you need to dig into how the SPI DMA works, which is not in a quick kick.

In the same time you might need a strategy to process the available data transmitted or received.

 

2 replies

NEdom.1
NEdom.1Best answer
Associate III
December 9, 2024

If you are using SPI to access a large amount of data in SPI flash in a single operation, then you need to stop the DMA operation in some situation. I don't see any stopping DMA mechanism inside HAL_SPI_TransmitReceive_DMA API. I think you might implement your own SPI DMA functions in which you can inject the GPIO interrupt or polling this GPIO to determine whether or not to exit DMA mode. To do this, you need to dig into how the SPI DMA works, which is not in a quick kick.

In the same time you might need a strategy to process the available data transmitted or received.

 

Andrew Neil
Super User
December 9, 2024

@NEdom.1 wrote:

you might need a strategy to process the available data transmitted or received.


also to ensure that the Slave is left in a "sensible" state ...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.