AnsweredAssumed Answered

Option Byte Loading (OBL_LAUNCH) fails

Question asked by Carretti_Mambrini.An on Apr 22, 2017
Latest reply on Apr 22, 2017 by Carretti_Mambrini.An

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

Outcomes