cancel
Showing results for 
Search instead for 
Did you mean: 

Option Byte Loading (OBL_LAUNCH) fails

elKarro
Associate III
Posted on April 22, 2017 at 13:10

Hi, I'm having an issue on STM32L151RC with HAL_FLASH_OB_Launch(), simplifying:

if (HAL_FLASH_OB_Unlock() == HAL_OK)

{

    HAL_FLASH_OB_Launch();

    while (1);

}

MCU seems to fall in an undefined state.

Certainly GPIO peripherals reset, beacause a pin configured as output, after launch, turns into hi-z input state (its default at reset), but CPU doesn't, because the 1st ever executed instruction at reset, in startup_stm32l151xc.s, is this:

Reset_Handler:

    bl  test_reset

and test_reset() is never reached.

void test_reset(void)

{

//    led_r_Pin        PORTB.6

//    led_g_Pin        PORTB.7

//    led_b_Pin        PORTB.8

    __HAL_RCC_GPIOB_CLK_ENABLE();

    (*GPIOB).MODER = ((*GPIOB).MODER & ~0b00000000000000111111000000000000UL) | 0b00000000000000010101000000000000UL;

    (*GPIOB).ODR   = 0b00000000000000000000000000000000UL;

    if (HAL_IS_BIT_SET((*RCC).CSR, RCC_CSR_OBLRSTF))

    {

    //    OBL reset occurred, toggle blue led forever

        while (1)

            tgl_led_b();    //    toggle port B pin 8

    }

    else

    {

    //    non-OBL reset occurred, toggle red led for a while, then exit

        DWORD timeout = 0xFFFFF;

        do {

            tgl_led_r();    //    toggle port B pin 6

        } while (timeout--);

    //    exit

    }

    __HAL_RCC_GPIOB_CLK_DISABLE();

}

Any idea?

Thanks

#oblrstf #option-bytes #hal_flash_ob_launch #obl_launch #obl-launch #options-bytes-loading-reset-flag #obl-reset
MCU speaks VHDL and CPU speaks assembly. Neither of them speaks HAL.
1 REPLY 1
elKarro
Associate III
Posted on April 22, 2017 at 15:36

Calling HAL_RCC_DeInit() before HAL_FLASH_OB_Launch() seems to be a valid workaround.

MCU speaks VHDL and CPU speaks assembly. Neither of them speaks HAL.