cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_DDR_Init returns an error intermittently.

Stnoobs
Associate II
Hello,

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.

 

1 REPLY 1
DBELL.1
ST Employee

Hello @Stnoobs ,

 

The static_ddr_config is a variable with a predifined value as you said which is stored in the SRAM.
And it should be not modified unless another FW is running and modying it.
From my side it is stored at 0x2ffe5048, could you tell me if you have the same?
Do you know the value of static_ddr_config.c_reg.MSTR when the problem occurs?

 

regards,
David B.