cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0B1 programming Option Bytes stopped after OBL_Launch

FRieb.1
Associate III

The MCU stops when the program reaches this line (FLASH->CR |= FLASH_CR_OBL_LAUNCH;) in the function below.

The option bytes I want to write are at the moment still unchanged to the delivery state. Later they will be changed to RDP Level 1.

void Optionbytes_Config(void)
{
    Flash_Unlock();
    Optionbytes_Unlock();
    FLASH->OPTR = 0xFFFFFEAA;
 
    while((FLASH ->SR & FLASH_SR_BSY1) == FLASH_SR_BSY1);
 
    FLASH->CR |= FLASH_CR_OPTSTRT;
 
    while((FLASH ->SR & FLASH_SR_BSY1) == FLASH_SR_BSY1);
 
    FLASH->CR &= ~FLASH_CR_OPTSTRT;
 
    FLASH->CR |= FLASH_CR_OBL_LAUNCH;
 
    while((FLASH ->SR & FLASH_SR_BSY1) == FLASH_SR_BSY1);
 
    FLASH->CR |= FLASH_CR_LOCK;
    FLASH->CR |= FLASH_CR_OPTLOCK;
}

Thank you for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
FRieb.1
Associate III

I made it. My workaround is that I now set the optionbytes directly at the end of the hex file.

Only the two marked lines need to be inserted.

0693W00000GXHfRQAX.png

View solution in original post

5 REPLIES 5
Andreas Bolsch
Lead II

See RM0444, 5.1.2: "Option byte loader reset

The option byte loader reset is generated when the OBL_LAUNCH bit (bit 27) is set in the

FLASH_CR register. This bit is used to launch the option byte loading by software."

BTW: "FLASH->CR &= ~FLASH_CR_OPTSTRT;" does nothing, OPSTSRT is reset automatically.

FRieb.1
Associate III

Thank you for your reply.

I have removed this line, but it does not change anything.

The point is, setting OBL_LAUNCH causes a RESET.

Of course, removing this line won't change anything.

FRieb.1
Associate III

I made it. My workaround is that I now set the optionbytes directly at the end of the hex file.

Only the two marked lines need to be inserted.

0693W00000GXHfRQAX.png

Martin M.
Associate II

I experienced a similar issue with an STM32F030, which just "hangs" after setting FLASH_CR_OBL_LAUNCH bit in FLASH->CR register.

According to the reference manual (RM0360, 3.5.5, page 61) the STM32F030 should reset after setting FLASH_CR_OBL_LAUNCH, but it just "hangs" and stops executing any further instruction. (A following power cycle will set the option bytes though.)

My workaround is the usage of the independent watchdog (IWDG) which generates a system reset after setting FLASH_CR_OBL_LAUNCH in FLASH->CR register, which luckily also sets the option bytes as expected.

There's another solution shown in this thread, using standby mode and RTC wakeup from standby.

The whole thing might be an undocumented errata (at least of the STM32F0 series)(?)

Just my 2 cents.