Skip to main content
Jalon Wong
Associate
November 19, 2019
Question

Interrupt safety issue in HAL_I2C_Mem_Read_DMA()

  • November 19, 2019
  • 1 reply
  • 696 views

STM32Cube_FW_F0_V1.10.1

Line 2434 in function HAL_I2C_Mem_Read_DMA()

/* Process Unlocked */
 __HAL_UNLOCK(hi2c);
 
 /* Enable DMA Request */
 hi2c->Instance->CR1 |= I2C_CR1_RXDMAEN;
 
 /* Enable ERR and NACK interrupts */
 I2C_Enable_IRQ(hi2c, I2C_XFER_ERROR_IT);

I2C_Enable_IRQ is called after set I2C_CR1_RXDMAEN.This is not safe.

The hi2c->XferISR is cleared in DMA Interrupt function that may occur before I2C_Enable_IRQ is called.

This topic has been closed for replies.

1 reply

gordon239955_st
Associate III
July 30, 2021

I had the same problem on an L081.

My cheap and dirty but effective workaround was to call MX_I2C_Init() immediately before each call to HAL_I2C_Mem_Read_DMA()