HAL_SPI_TransmitReceive_DMA doesn't transfer properly under Arduino Core (STM32H750XBH6)
Posted: Thu Feb 06, 2025 3:39 am
Same code works directly using CubeIDE.
Chip: STM32H750XBH6
DMA Config
Mode: Circular
Data Width: Byte/Byte
No Sync/Event used
SPI Config:
Mode: Slave with hardware SS Input
Frame Format: Motorola
Data Size: 8Bits
Other configs are default.
Here I encountered a strange problem.
pRX[0]~pRX[7] keeps empty and can be modified (DMA doesn't transfer data).
After I change the definition of pTX and pRX to the following code, data appears in pRX[0] ~ pRX[7] (DMA transfers data) and the data is exactly what I send.
I try to figure out if it is the problem of memory alignment, but finally I confirmed it's not memory alignment related.
Because I try to force the variable at the same memory address in CubeIDE as the address in Arduino, everything works fine.
I've tested that when X is between 8 to 12, DMA won't transfer. And when X is equal to or larger than 13, data present in pRX.
During the process of reproducing this.
Sometimes it can work after I exchange the definition of pTX and pRX.
And somethings data in pRX only has the front 4 bytes.
Well, my brain keeps exploding for several days
I'd appreciate it very much if someone could save me from this hell.
Chip: STM32H750XBH6
DMA Config
Mode: Circular
Data Width: Byte/Byte
No Sync/Event used
SPI Config:
Mode: Slave with hardware SS Input
Frame Format: Motorola
Data Size: 8Bits
Other configs are default.
Here I encountered a strange problem.
Code: Select all
//This is the definition of the DMA Buffers
uint8_t pTX[8];
uint8_t pRX[8];
Code: Select all
//in "setup" function, I use this function to start SPI with DMA
HAL_SPI_TransmitReceive_DMA(&hspi2, (uint8_t *)pTX, (uint8_t *)pRX, 8);
After I change the definition of pTX and pRX to the following code, data appears in pRX[0] ~ pRX[7] (DMA transfers data) and the data is exactly what I send.
Code: Select all
uint8_t pTX[16];
uint8_t pRX[16];
Because I try to force the variable at the same memory address in CubeIDE as the address in Arduino, everything works fine.
I've tested that when X is between 8 to 12, DMA won't transfer. And when X is equal to or larger than 13, data present in pRX.
Code: Select all
uint8_t pTX[X];
uint8_t pRX[X];
Sometimes it can work after I exchange the definition of pTX and pRX.
Code: Select all
uint8_t pRX[8]; //was pTX
uint8_t pTX[8]; //was pRX
Well, my brain keeps exploding for several days

I'd appreciate it very much if someone could save me from this hell.
