STM32H7 SPI DMA only works when breakpoint is set in debugger
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.