Skip to main content
ConfusedContrarian
Associate III
August 21, 2021
Question

STM32H7 SPI DMA only works when breakpoint is set in debugger

  • August 21, 2021
  • 2 replies
  • 1231 views

Hi, I have a custom board based on the STM32H745 and I'm trying to understand an issue I'm experiencing with the SPI Interface. I have a BMP280 attached to SPI1 on the M4 coreand I've successfully written a driver for it both using DMAs and Interrupt. However, I have a strange issue with DMA.

I initially configure my sensor using the following code:

void ConfigSensors(void)
{
 // Configure BMP280
 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); // NCS Pin
 uint8_t baro_res = CheckBMP280ChipID();
 if(baro_res == HAL_OK)
 {
 uint8_t reset_chip_ok = ResetBMP280();
 HAL_Delay(1000);
 uint8_t set_config_ok = setConfig(&baro);
 ReadCalibCoefficients(&baro);
 }
}

Function is simple enough. It basically checks the chip ID, resets the sensor, sets the configuration and reads the calibration coefficients.

In my main I have a function that just gets the sensor data and I check it using the debugger.

void BaroTask(void)
{
 if(HAL_GetTick() - baro_timer >= BARO_SAMPLE_TIME)
 {
 
 ReadTemp(&baro);
 ReadPressure(&baro);
 ReadAltitude(&baro);
 
 baro_timer+=BARO_SAMPLE_TIME;
 
 }
 
}

However to get this to work using DMA, I have to set a breakpoint before the CheckBMP280ChipID() function, step through the whole configuration process manually and then click run. Only then am I able to get my sensor readings from the chip.

If I run using interrupt, everything works as expected. If I simply run the code, well baro_res fails and the chip doesn't get setup. However, if I set a breakpoint in the  HAL_SPI_TxRxCpltCallback function, the debugger stops at the breakpoint so I know even then the SPI interface and DMA are working.

I'm guessing it's delay or speed issue?? But I'm not quite sure how to resolve this. Any tips are appreciated.

This topic has been closed for replies.

2 replies

TDK
Super User
August 23, 2021

I don't see you using DMA anywhere in the code you posted.

Be aware you need to manage the cache appropriately on the STM32H7 when using DMA.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Technical Moderator
August 23, 2021

Hello @DB.7abatunde​ ,

Please have a look at this article DMA is not working on STM32H7 devices, which explains the memory layout of the platform and the cache that have an impact on the DMA usage. 

Hope this helps you!

When your question is answered, please close this topic by choosing Select as Best. This will help other users find that answer faster.

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks