cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO Stops Toggling When Timer and SPI DMA Are Active on NUCLEO-H753ZI

YSong.3
Associate II


Hello everyone,

I am working with the NUCLEO-H753ZI and communicating with an IIM42652 accelerometer using SPI with DMA enabled. Below is the relevant part of my code:

 

 

int main(void)
{
  /* MCU Configuration--------------------------------------------------------*/

  HAL_Init();
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_SPI1_Init();
  MX_TIM12_Init();

  /* Start Timer 12 PWM */
  HAL_TIM_PWM_Start_IT(&htim12, TIM_CHANNEL_2);

  // Prepare SPI communication
  txbuffer_dma[0] = REG_WHO_AM_I | 0x80;
  txbuffer_dma[1] = 0x00;
  memset(rxbuffer_dma, 0, sizeof(rxbuffer_dma));

  // Start SPI communication with DMA
  HAL_SPI_TransmitReceive_DMA(&hspi1, txbuffer_dma, rxbuffer_dma, 4);

  /* Main Loop */
  while (1)
  {
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET);
  }
}

 

 

After running this code, I checked the signals using a logic analyzer and observed the following:

  • The CS pin is controlled by Timer 12 PWM output, as we need to read data from the accelerometer at 8 kHz sampling rate.
  • The SPI communication seems to be working correctly because I can successfully read the accelerometer’s WHO_AM_I register.
  • However, I noticed that the GPIO toggling inside the while loop stops working when both Timer 12 and SPI DMA are active.

spi dma.PNG

 

Since DMA is supposed to store the received data directly into memory without CPU intervention, I expected the CPU to be free to execute other tasks (such as GPIO toggling). However, this does not seem to be the case.

 

Has anyone encountered a similar issue or found a solution for this behavior? Any insights would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

When the system is handling interrupts, it is not making progress in the main thread. This is a single thread processor. Interrupts such as transfer complete will interrupt and pause the main thread until they are done.

 

The DMA is handled without the CPU, but the interrupts caused by it are not. You can disable the interrupts if you don't need them.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

When the system is handling interrupts, it is not making progress in the main thread. This is a single thread processor. Interrupts such as transfer complete will interrupt and pause the main thread until they are done.

 

The DMA is handled without the CPU, but the interrupts caused by it are not. You can disable the interrupts if you don't need them.

If you feel a post has answered your question, please click "Accept as Solution".

Thank you for your response. I understand that interrupts pause the main thread while they are being handled.