cancel
Showing results for 
Search instead for 
Did you mean: 

Potentially Dangerous IRQ Disable Before I2C Read in L496 Application Template

Michael K
Senior III

I've been working with the L496 application template v3.0.5. In it, the touchscreen i2c memory read is "guarded" by an __disable_irq() call, and followed by __enable_irq(). For example:

static uint8_t I2Cx_ReadData(uint16_t Addr, uint16_t Reg, uint16_t RegSize)
    {
        HAL_StatusTypeDef status = HAL_OK;
        uint8_t value = 0x0;
 
        __disable_irq();
 
        status = HAL_I2C_Mem_Read(&hi2c2, Addr, Reg, RegSize, &value, 1, TS_I2C_TIMEOUT_MAX);
 
        __enable_irq();
 
        /* Check the communication status */
        if (status != HAL_OK)
        {
            /* Re-Initiaize the BUS */
            I2Cx_Error();
            HAL_Delay(200);
        }
 
        return value;
    }

This effectively disables the ability of the HAL to time out of the i2c function (the HAL tick is incremented in an IRQ, hanging the entire TouchGFX thread where otherwise the method would exit and reinitialize itself.

The irq lines are not present in some other application templates, such as the F769 v2. Is there a particular reason these lines were added?

@Romain DIELEMAN​ @Martin KJELDSEN​ @Alexandre RENOUX​ 

0 REPLIES 0