2025-06-22 10:05 PM - last edited on 2025-06-23 4:29 AM by Andrew Neil
Hi,
I want to get data from an ADC connected externally through SPI DMA whenever data ready pin is set.
I want to do it without any interrupt handler, since our firmware have already loaded with other stuffs.
I have tried the synchronisation of SPI DMA with GPIO EXTI trigger. It works when I configure SPI DMA in circular mode only.
Because synchronisation doesn't triggers the SPI DMA it just syncs the process. I can't find any options to trigger the SPI DMA with timer or any event.
How to trigger SPI DMA through GPIO EXTI event? Is that possible in STM32G4 series?.
Thank you!
Solved! Go to Solution.
2025-06-23 1:14 AM
@BrindhaP wrote:How to use DMA request generator to generate DMA RX/TX ?
Eh, Reference Manual specify that in 13.4.5. But generaly it is not good idea to sending data to SPI this way. Why ? DMA request generator dont care about SPI buffer status and writes data to it even if there is no room which may lead to data loss.
If i understand your problem correct, then you should set SPI TX to generate DMA requests and synchronize them by synchronization feature.
2025-06-22 11:37 PM
There are multiple ways:
Better one: use DMAMUX and its synchronisation feature. Look at figure 33 in Reference Manual. Use EXTI line from your GPIO to "trigger" (synchronise) SPI TX DMA requests.
Alternative one: Route your signal to timer input. Set timer to trigger by external event and to one-shot mode. Use timer DMA request to trigger transfer data to SPI. Timer is in this case used only to "route" signal from GPIO as DMA request.
Of course in both cases use DMA for SPI reading (read is triggered by write...)
https://www.st.com/resource/en/reference_manual/rm0440-stm32g4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf
2025-06-22 11:42 PM
@BrindhaP wrote:
Because synchronisation doesn't triggers the SPI DMA it just syncs the process. I can't find any options to trigger the SPI DMA with timer or any event.
You probably misunderstand synchronisation.
Usualy you enable SPI TX DMA request, they are blocked by synchronisation feature in DMAMUX. When synchronisation event comes, then waiting requests pass on to DMA. In other words, DMA request are generated by SPI, DMAMUX only hold them until synchronisation event comes.
BTW: If needed (which is not the case), request also can be generated by DMAMUX - "request generator" feature.
2025-06-23 12:33 AM
Thank you for the reply.
How to use DMA request generator to generate DMA RX/TX ?
2025-06-23 1:14 AM
@BrindhaP wrote:How to use DMA request generator to generate DMA RX/TX ?
Eh, Reference Manual specify that in 13.4.5. But generaly it is not good idea to sending data to SPI this way. Why ? DMA request generator dont care about SPI buffer status and writes data to it even if there is no room which may lead to data loss.
If i understand your problem correct, then you should set SPI TX to generate DMA requests and synchronize them by synchronization feature.
2025-06-24 1:50 AM
Ya I am doing the same. I am using SPI Tx to generate DMA request. There is a config in synchronisation setting like request number. Will one request will allow the DMA to send all the data in the buffer to SPI. or I need to generate multiple requests matching the number of bytes in the buffer to be sent to SPI?.
2025-06-24 2:25 AM
@BrindhaP wrote:Will one request will allow the DMA to send all the data in the buffer to SPI.
Yes.
SPI generate request permanently (whenever space becomes available in the buffer). DMAMUX in "synchronisation mode" wait until synchronisation event comes and then will pass on selected number of requests (for example 4). And then no further requests will pass, until new synchronisation event comes.
2025-06-24 2:35 AM
Suppose If I want to send 20 number of bytes in the tx array I have to make request 20 or it will send all the data in buffer in one request itself and waits for next synchronisation event
2025-06-24 3:24 AM
@BrindhaP wrote:Suppose If I want to send 20 number of bytes in the tx array I have to make request 20 or it will send all the data in buffer in one request itself and waits for next synchronisation event
You should just to set number of requests to 20 and after each single synchronisation event DMAMUX let pass 20 requests from SPI to DMA and therefore DMA transfer 20 bytes to SPI buffer. Fully autonomously.
2025-06-24 3:48 AM - edited 2025-06-24 3:49 AM
OK. Thank you so much