cancel
Showing results for 
Search instead for 
Did you mean: 

Hi am using the STM32G474RE nucleo board to try Flash_Dualboot example but crashing at HAL_FLASH_OB_Launch()

ASank
Associate II

Hi, I have been trying the Flash dual boot example from version1.3.0. I am following the steps as given in the readme.txt, flashed the bank2 FW from location 0x08040000 and used the debugger to flash the bank1FW. I triggered a bank swap by pressing the User button. The option byte got changed, but the program crashed at

HAL_FLASH_OB_Launch() function and when I restarted it started only again from bank1. This is the code that is there in the example code I am using. It did not go into error code, directly crashed and did not respond.

   if (HAL_FLASH_OB_Launch() != HAL_OK)

   {

    /*

    Error occurred while reloading option bytes configuration.

    User can add here some code to deal with this error.

    To know the code error, user can call function 'HAL_FLASH_GetError()'

    */

    /* Infinite loop */

    while (1)

    {

     /* Make LED2 blink (100ms on, 2s off) to indicate error */

     BSP_LED_On(LED2);

     HAL_Delay(100);

     BSP_LED_Off(LED2);

     HAL_Delay(2000);

    }

   }

I am unable to figure out why a straightforward example code downloaded is not working correctly. Is there anything wrong in the way the API is used? Please suggest

Thanks,

Aviinaash S

5 REPLIES 5
Imen.D
ST Employee

Hello @ASank​ and welcome to the STM32 Community =)

From my side, the Flash_Dualboot example works perfectly using IAR toolchain and bootloader version 13.4.

Which IDE are you using ? Which G4 device Rev you have ?

Make sure that you are using the bootloader version v13.4.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
ASank
Associate II

Hi Imen,

I am currently using CubeIDE 1.5.1. Where do I check for the device rev?

I did check the bootloader version based on another message in the group, it was showing D3.

I assume must be 13.3. So the HAL_FLASH_OB_Launch() API wont work in bootloader 13.3?

Thanks,

Aviinaash S

Imen.D
ST Employee

>> I assume must be 13.3. So the HAL_FLASH_OB_Launch() API wont work in bootloader 13.3?

No, but with BL v13.3 there is a jumping problem between banks.

Maybe the issue is due to the stack pointer size defined in the STM32G474RExx_FLASH.ld file.

So, please try to update this line:

_estack = ORIGIN(RAM) + 0x18000 ;

and change it to:

_estack = ORIGIN(RAM) + 0x1000 ;

Then, please confirm to me if this workaround solve the issue in your side?

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
ASank
Associate II

I tried changing the stack pointer size as you mentioned. But same issue.

   /* Start the Option Bytes programming process */

   if (HAL_FLASH_OB_Launch() != HAL_OK)

   {

    /*

    Error occurred while reloading option bytes configuration.

    User can add here some code to deal with this error.

    To know the code error, user can call function 'HAL_FLASH_GetError()'

    */

    /* Infinite loop */

    while (1)

    {

     /* Make LED2 blink (100ms on, 2s off) to indicate error */

     BSP_LED_On(LED2);

     HAL_Delay(100);

     BSP_LED_Off(LED2);

     HAL_Delay(2000);

    }

   }

   /* Prevent Access to option bytes sector */

   HAL_FLASH_OB_Lock();

I tried putting a break point in HAL_FLASH_OB_Lock(); but it was never hit. According to the example it is supposed to jump to bank2 and bank2 code has LED2 always ON, but LED2 is no longer flashing and is OFF. I restarted the board again and nothing happens. I have to debug the board with correct code to start again.

Thanks,

Aviinaash S

Imen.D
ST Employee

Hi @ASank​ ,

As stating on the AN2606: the dual boot is not working on the bootloader V13.3.

0693W000008zMh6QAE.jpgImen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen