cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt safety issue in HAL_I2C_Mem_Read_DMA()

Jalon Wong
Associate II

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.

1 REPLY 1
gordon239955_st
Associate III

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()