2022-10-15 03:39 AM
Hello guys.
Im a little confused about dma functionality.
My question is that if dma controller can start a peripheral or it just can move data from the peripheral to memory.
For example when using adc with dma:
Is it dma that start the conversion and moving data from adc to memory or when we start the conversion by software (or timer trigger for examole) its the EOC flag that start the dma transfer procedure?
In case of spi and dma if we dont want any cpu usage how would it work? In adc there is a connection between timer trigger out and adc that starts the adc by hardware but in spi i didnt see any.
Am i able to use a dma stream that is connected to timer update channel request to transfer data without cpu starting spi transmit?
Solved! Go to Solution.
2022-10-15 04:53 AM
> My question is that if dma controller can start a peripheral or it just can move data from the peripheral to memory.
DMA is a machine which upon arrival of a trigger transfers one piece of data from one address to another. That's all.
The problem with your question is, what is "start a peripheral". For example, without DMA, you would start a SPI master Tx by the processor writing some to SPI_DR (at the same time, in SPI master, it also means starting Rx, as SPI is normally full-duplex). So, if a DMA transfer ends with writing data to SPI_DR, it starts the Tx in exactly very same way - and it does not matter, what was the trigger of that DMA transfer. Normally, that trigger comes from the TXE bit in SPI_SR - but you can as well use a timer to generate that trigger (depending on the particular STM32 model you are using, you might need to use a different DMA channel/stream for that).
However, with power comes responsibility - the DMA has no idea what is the current state of SPI, it simply just shovels data whenever and wherever it is told to. So, if your timer trigger for example occurs more often than is the time SPI needs to transmit a frame, DMA does not care, it simply shovels data into "occupied" SPI_DR which then gets simply ignored.
JW
2022-10-15 04:53 AM
> My question is that if dma controller can start a peripheral or it just can move data from the peripheral to memory.
DMA is a machine which upon arrival of a trigger transfers one piece of data from one address to another. That's all.
The problem with your question is, what is "start a peripheral". For example, without DMA, you would start a SPI master Tx by the processor writing some to SPI_DR (at the same time, in SPI master, it also means starting Rx, as SPI is normally full-duplex). So, if a DMA transfer ends with writing data to SPI_DR, it starts the Tx in exactly very same way - and it does not matter, what was the trigger of that DMA transfer. Normally, that trigger comes from the TXE bit in SPI_SR - but you can as well use a timer to generate that trigger (depending on the particular STM32 model you are using, you might need to use a different DMA channel/stream for that).
However, with power comes responsibility - the DMA has no idea what is the current state of SPI, it simply just shovels data whenever and wherever it is told to. So, if your timer trigger for example occurs more often than is the time SPI needs to transmit a frame, DMA does not care, it simply shovels data into "occupied" SPI_DR which then gets simply ignored.
JW