HAL_DDR_Init returns an error intermittently.
I am currently working with an STM32MP131 in a bare-metal environment and utilizing external DDR3. For this, I am using the HAL library, and in most cases, it works as expected. However, I occasionally encounter an issue where the HAL_DDR_Init function returns an error intermittently.
Below is a portion of the code where the error occurs:
HAL_StatusTypeDef HAL_DDR_Init(DDR_InitTypeDef *iddr)
{
...
...
...
if ((static_ddr_config.c_reg.MSTR & DDRCTRL_MSTR_DDR3) != 0U)
{
iret = HAL_DDR_MspInit(STM32MP_DDR3);
}
else if ((static_ddr_config.c_reg.MSTR & DDRCTRL_MSTR_LPDDR2) != 0U)
{
if (bus_width == 32U)
{
iret = HAL_DDR_MspInit(STM32MP_LPDDR2_32);
}
else
{
iret = HAL_DDR_MspInit(STM32MP_LPDDR2_16);
}
}
else if ((static_ddr_config.c_reg.MSTR & DDRCTRL_MSTR_LPDDR3) != 0U)
{
if (bus_width == 32U)
{
iret = HAL_DDR_MspInit(STM32MP_LPDDR3_32);
}
else
{
iret = HAL_DDR_MspInit(STM32MP_LPDDR3_16);
}
}
else
{
/* Unsupported DDR type */
return HAL_ERROR;
}
...
...
In normal operation, the condition if ((static_ddr_config.c_reg.MSTR & DDRCTRL_MSTR_DDR3) != 0U) should evaluate to TRUE, and HAL_DDR_MspInit should be executed. The MSTR register is defined as 0x0040401 in stm32mp13xx-ddr3-4Gb.
The issue is that, intermittently, none of the if conditions are met, and the function returns HAL_ERROR. Since the MSTR register holds a predefined, non-variable value, I am unsure how this situation could occur.
I would greatly appreciate your insights and assistance on this matter.
Thank you in advance.
