Skip to main content
DDU
Associate II
August 14, 2018
Question

Enable SRAM parity check

  • August 14, 2018
  • 6 replies
  • 1433 views

How can I enable the parity check in the SRAM 2 of the STM32L4?

Is there a HAL function?

    This topic has been closed for replies.

    6 replies

    Tesla DeLorean
    Guru
    August 14, 2018

    You have to configure a bit in the Options Bytes, try looking at related examples for reading/writing those and extend to your requirements

    STM32Cube_FW_L4_V1.12.0\Projects\STM32L476G-EVAL\Applications\IAP\IAP_Main\Src\flash_if.c

    STM32Cube_FW_L4_V1.12.0\Projects\32L476GDISCOVERY\Examples\FLASH\FLASH_DualBoot\Src

    STM32Cube_FW_L4_V1.12.0\Projects\32L476GDISCOVERY\Examples\FLASH\FLASH_WriteProtection\Src

    STM32Cube_FW_L4_V1.12.0\Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_flash_ex.c

    /**

     * @brief Program the FLASH User Option Byte.

     *

     * @note  To configure the user option bytes, the option lock bit OPTLOCK must

     *        be cleared with the call of the HAL_FLASH_OB_Unlock() function.

     * @note  To validate the user option bytes, the option bytes must be reloaded

     *        through the call of the HAL_FLASH_OB_Launch() function.

     *

     * @param UserType: The FLASH User Option Bytes to be modified

     * @param UserConfig: The FLASH User Option Bytes values:

     *        BOR_LEV(Bit8-10), nRST_STOP(Bit12), nRST_STDBY(Bit13), IWDG_SW(Bit16),

     *        IWDG_STOP(Bit17), IWDG_STDBY(Bit18), WWDG_SW(Bit19), BFB2(Bit20),

     *        DUALBANK(Bit21), nBOOT1(Bit23), SRAM2_PE(Bit24) and SRAM2_RST(Bit25).

     *

     * @retval HAL status

     */

    static HAL_StatusTypeDef FLASH_OB_UserConfig(uint32_t UserType, uint32_t UserConfig)

    {

    ..

       if((UserType & OB_USER_SRAM2_PE) != 0U)

       {

         /* SRAM2_PE option byte should be modified */

         assert_param(IS_OB_USER_SRAM2_PARITY(UserConfig & FLASH_OPTR_SRAM2_PE));

         /* Set value and mask for SRAM2_PE option byte */

         optr_reg_val |= (UserConfig & FLASH_OPTR_SRAM2_PE);

         optr_reg_mask |= FLASH_OPTR_SRAM2_PE;

       }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    DDU
    DDUAuthor
    Associate II
    August 16, 2018

    FLASH_OB_UserConfig() is a static function. I use HAL_FLASHEx_OBProgram() which calls FLASH_OB_UserConfig():

      HAL_FLASHEx_OBGetConfig(&optionBytesInit);

      optionBytesInit.USERType |= OB_USER_SRAM2_PE;

      optionBytesInit.USERConfig &= ~FLASH_OPTR_SRAM2_PE_Msk;

      HAL_FLASH_OB_Unlock();

      HAL_FLASHEx_OBProgram(&optionBytesInit);

      HAL_FLASH_OB_Lock();

      HAL_FLASH_OB_Launch();

    But HAL_FLASH_OB_Unlock() generates a hard fault.

    waclawek.jan
    Super User
    August 16, 2018

    Do you have some of the lock or other options set through device programming?

    JW

    DDU
    DDUAuthor
    Associate II
    August 16, 2018

    I don't set anything actively during programming, but we use IAR (V8.20) and HAL (V1.8.3).

    The value of the option register (FLASH->OPTR) is 0xFFEFF8AA.

    DDU
    DDUAuthor
    Associate II
    November 2, 2018

    Do someone from ST could check if the SRAM2 parity enable bit can be reset to 0 (0 = parity check enabled!) in the STM32L4A6ZG?

    The code in not working:

      FLASH_OBProgramInitTypeDef optionBytesInit = {0U};

      HAL_FLASHEx_OBGetConfig(&optionBytesInit);

      optionBytesInit.USERType |= OB_USER_SRAM2_PE;

      optionBytesInit.USERConfig &= ~FLASH_OPTR_SRAM2_PE;

      HAL_FLASH_OB_Unlock();

      HAL_FLASH_Unlock();

      HAL_FLASHEx_OBProgram(&optionBytesInit);

      if (HAL_FLASH_OB_Launch() != HAL_OK)

      {

        while(1);

      }

      HAL_FLASH_OB_Lock();

      HAL_FLASH_Lock();

    The SRAM2_PE is always 1 (instead of 0).

    And a bus fault arise afterwards.

    Tesla DeLorean
    Guru
    November 2, 2018

    >>Do someone from ST could check if the SRAM2 parity enable bit...

    This is predominantly a user forum, you should work with the ST FAE supporting your account, or those at your distributor. Or file an Online Support request.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..