2025-07-23 3:48 PM
Hi all,
I am working on a project involving reading from the external AD7768. I've tested to get data out of it using and EXTI and Interrupt based SPI receives, but that was too slow to capture the message, so I'm trying to get it to work with DMA.The problem is, I can't get DMA to work at all!
The current set up is SPI1 as full duplex master and SPI2 as full duplex slave, both CPOL and CPHA = 0. These are the physical connections on the board.
SPI1_SCK (PA5) <-> SPI2_SCK (PB10)
SPI1_MOSI (PD7) <-> SPI2_MOSI (PC3)
GPIO_Output (PE2) <-> GPIO_EXTI12 (PB12)
Just to get anything working, I'm running the following code with EXTI12 disabled.
uint8_t tx[2] = {0x11, 0x22};
uint8_t rx[2] = {0};
HAL_SPI_TransmitReceive_DMA(&hspi2, tx, rx, 2);
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_SET);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_RESET);
if(HAL_SPI_TransmitReceive_DMA(&hspi1,tx,rx, 2) != HAL_OK){
uint32_t err = HAL_SPI_GetError(&hspi1);
printf("%d \r\n", err);
}
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_SET);
printf("%02x, %02x \r\n", rx[0], rx[1]);
...
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef * hspi){
printf("done\r\n");
}
void HAL_SPI_RxHalfCpltCallback(SPI_HandleTypeDef *hspi) {
printf("half\r\n");
}
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef * hspi)
{
printf("done transmitting \r\n");
}
There is no activity on the SPI bus at all, tested using a logic analyzer. I've tested the SPI1 transmit using non-dma functions and have confirmed that it's making a valid signal (still, none of the DMA callback function triggered).
I have both D-Cache and I-Cache disabled, since I know that DMA can cause cache coherence issues on this board. I'm really not sure where to look here, any tips would be appreciated. I've attached the IOC for this project if you'd like to take a look.
P.S. If anyone here has experience reading from high speed serial devices like the AD7768, I'd love to hear how it would be best to read from it? I think that having the GPIO trigger an armed DMA read would be able to catch the message (there's a little over 190 ns between the rising edge of the data ready signal of the ADC and the first valid edge of the DCLK) but I'm not sure
Solved! Go to Solution.
2025-07-23 5:02 PM
Are the buffers in a region that the DMA can access? Where are they at?
DMA is not working on STM32H7 devices - STMicroelectronics Community
The relevant callbacks for HAL_SPI_TransmitReceive_DMA are HAL_SPI_TxRxHalfCpltCallback and HAL_SPI_TxRxCpltCallback.
2025-07-23 3:53 PM
Oh, and I forgot to mention, everything is done on the CM7 core.
2025-07-23 5:02 PM
Are the buffers in a region that the DMA can access? Where are they at?
DMA is not working on STM32H7 devices - STMicroelectronics Community
The relevant callbacks for HAL_SPI_TransmitReceive_DMA are HAL_SPI_TxRxHalfCpltCallback and HAL_SPI_TxRxCpltCallback.
2025-07-23 5:55 PM
Shucks, I remember reading that article, I must have forgotten about it while debugging. I hadn't touched the ld at all, so I think it's all in the default block at 0x20000000, which looking over the data sheet is specifically not accessible by DMA, I'll try specifying and moving everything to D1 domain tomorrow when I'm back at my desk.
Thank you for the pointers on the callbacks as well, I tested a version of the code which called HAL_SPI_Receive_DMA instead, I'll make sure to update that as well.
2025-07-24 7:40 AM
That more or less did the trick! In addition to moving everything to D1 RAM it also seems like I had to call SCB_CleanDCache_by_Addr() on the rx buffer, although I am not sure why since I'm certain that the D-Cache is disabled. Anywhos, thank you so much for the pointers, such a simple thing to look for.