Skip to main content
Senior
June 12, 2025
Solved

STM32H7RS SPI DMA memory to/from peripheral

  • June 12, 2025
  • 3 replies
  • 906 views

Hi,

I am trying to establish a successful transfer using SPI in master full duplex DMA mode using a NUCLEO-H7S3L8 board (STM32H7RSxx family)..

The runs and SPI data can be seen from the MOSI pins, but with one problem: data is not successfully sent.

In the following photo:

simozz_0-1749735236467.jpeg

504B @50MHz are being transmitted (CH1 trace - yellow one - is SCK, CH2 trace is CS):

total time of transmission is:

20us * 3.1 = 62us

vs

(504*8/50e6) = 80.64us

which is the time required for such a full transmission, meaning that approx. 116 B (according to these numbers) are missing on transmission.

However, when I read the GPDMA_CxBR1.BNDT[15:0] (previously programmed to 504) after GPDMA TC Irq, its value is 0, meaning that all the 504 should have been transmitted... But that's not true according to oscilloscope analysis.

So ... what is the missing piece? Maybe an LLI setup?

Thanks,

s.

 

Best answer by simo zz

The problem is related with data widths and FIFO settings. The TRF says the following regarding SPI and DMA data packing:

Data packing with DMA
If the transfers are managed by DMA (TXDMAEN and RXDMAEN set in the SPI_CFG1 register) the packing mode is enabled/disabled automatically depending on the PSIZE value configured for SPI TX and the SPI RX DMA channel.

The packing mode is enabled if the DMA channel PSIZE value is a multiple of the data size.

Then the DMA automatically manages the sequences of write and read operations to/from the SPI data registers, based on FIFO occupancy flags, and depending on the FIFO threshold and data size configurations.

The DMA completes the transfer automatically according to the TSIZE field setting, whatever the data packing mode used, and even if the number of data to transfer is not a multiple of the DMA data size (16 bits or 32 bits) while the frame size is smaller.

Alternatively, the last data frames can be written by software, in the single/unpacked mode. Configuring any DMA data access to less than the configured data size is forbidden. One complete data frame must be always accessed at minimum.

Also, for SPI RXPLVL[1:0]

00: no next frame is available at RxFIFO
01: 1 frame is available
10: 2 frames are available*
11: 3 frames are available*
Note: (*): Possible value when data size is set up to 8 bits only.

When SPI DSIZE and DMA access width are set to both 8b, the DMA cannot read the the whole RxFIFO packing level, so missing at least always one B, resulting in:

t = (512*3/4*8)/50e6 = 61.44 us

which is approximately what is seen on oscilloscope using the above settings.

Setting SPI DSIZE = 16bits, FTHLV to 02_DATA, DMA Peripheral access to WORD and Mem access to 1B and SPI TSIZE according to DSIZE, results in correct whole 512 B transfer, SPI EOT IRQ also notified:

shared image (1).jpg

3 replies

TDK
Super User
June 12, 2025

Probably the SPI/DMA is doing what it's been told to do. Can you show the contents of the SPI and DMA registers just before transmission starts (LL_SPI_StartMasterTransfer)?

> (504*8/50e6) = 8.064us

I believe it's actually 80.64 us.

"If you feel a post has answered your question, please click ""Accept as Solution""."
simo zzAuthor
Senior
June 13, 2025

@TDK wrote:

I believe it's actually 80.64 us.


Yes, this was obviously a typo. Fixed. Thanks.

The following is just before starting the transfer:

simozz_3-1749801706898.png

There is a strange p_txsrcaddr=<optimized out> that it might could be part of the issue....

s.

PS: the issue happens also with lower GPDMA_CxBR1.BNDT[15:0] values (e.g. 256 instead of 504).

 

 

 

TDK
Super User
June 13, 2025

Looks correct as far as I can see.

How do you know not all data is getting sent? Just based off of the width of the transfer? Is the measured bus speed 50 MHz? Does it work with 2 bytes? 1 byte? Lower clock speed?

When is U2aLlStopTrfSpiDma called? Need to wait for transmission to end, not just DMA completion.

"If you feel a post has answered your question, please click ""Accept as Solution""."
TDK
Super User
June 16, 2025

I think it's just general code bugs. We're only getting snippets here. Try to create a minimal but complete working example and attach that as a zipped project.

 

"If you feel a post has answered your question, please click ""Accept as Solution""."
simo zzAuthor
Senior
June 16, 2025

Yes, I agree it's the better way to proceed.

simo zzAuthor
Senior
June 17, 2025

Deleted

simo zzAuthorBest answer
Senior
June 18, 2025

The problem is related with data widths and FIFO settings. The TRF says the following regarding SPI and DMA data packing:

Data packing with DMA
If the transfers are managed by DMA (TXDMAEN and RXDMAEN set in the SPI_CFG1 register) the packing mode is enabled/disabled automatically depending on the PSIZE value configured for SPI TX and the SPI RX DMA channel.

The packing mode is enabled if the DMA channel PSIZE value is a multiple of the data size.

Then the DMA automatically manages the sequences of write and read operations to/from the SPI data registers, based on FIFO occupancy flags, and depending on the FIFO threshold and data size configurations.

The DMA completes the transfer automatically according to the TSIZE field setting, whatever the data packing mode used, and even if the number of data to transfer is not a multiple of the DMA data size (16 bits or 32 bits) while the frame size is smaller.

Alternatively, the last data frames can be written by software, in the single/unpacked mode. Configuring any DMA data access to less than the configured data size is forbidden. One complete data frame must be always accessed at minimum.

Also, for SPI RXPLVL[1:0]

00: no next frame is available at RxFIFO
01: 1 frame is available
10: 2 frames are available*
11: 3 frames are available*
Note: (*): Possible value when data size is set up to 8 bits only.

When SPI DSIZE and DMA access width are set to both 8b, the DMA cannot read the the whole RxFIFO packing level, so missing at least always one B, resulting in:

t = (512*3/4*8)/50e6 = 61.44 us

which is approximately what is seen on oscilloscope using the above settings.

Setting SPI DSIZE = 16bits, FTHLV to 02_DATA, DMA Peripheral access to WORD and Mem access to 1B and SPI TSIZE according to DSIZE, results in correct whole 512 B transfer, SPI EOT IRQ also notified:

shared image (1).jpg