cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F091 option bytes programming problem

Gabriele Rizzi
Associate
Posted on February 26, 2017 at 12:32

Hi everybody,

I am facing a rather strange problem when trying to program the two user option bytes (0x1ffff804, 0x1ffff806).

The code I am using is rather straightforward:

    

volatile

FLASH_Status

test3;

   

volatile

uint8_t

test, test2;

    test = 0x12;

    test2=0;

    FLASH_Unlock();

    FLASH_OB_Unlock();

    test3 = FLASH_OB_ProgramData( 0x1FFFF804, test);

    FLASH_OB_Launch();

    FLASH_OB_Lock();

    FLASH_Lock();

    test2 = FLASH_OB_GetUser();

    

The code il flashed on a Nucleo64 board. Apparently the CPU hangs completely when executing FLASH_OB_Launch().

If I step the code through the instructions, it looks as if FLASH_OB_Launch() is generating a complete erase of the chip. In fact, I cannot simply reset and re-start execution, I need to re-load the program with the debugger.

If I remove FLASH_OB_Launch() the code executes with no problems, test3 reports FLASH_COMPLETE but the options bytes are not programmed.

I can read and program the option bytes without any problem using ST-link.

Elsewhere in the code I am erasing and programming the flash memory again with no problems, but the options bytes just do not program!

Can anybody please give me a hint?

Regards,

Gabriele

2 REPLIES 2
Renato
Associate II
Posted on March 12, 2017 at 15:56

Hello Gabriele

I've had more or less the same problem: CPU crashes (I lose connection with the debugger) when I execute FLASH_OB_Launch(). But I figured out that it is not needed to program the two free bytes at 0x1FFFF804 and 0x1FFFF806.

Whatsoever, I had to first call FLASH_OB_Erase() before FLASH_OB_ProgramData() to get it work.

Hope it helps,

regards

Posted on March 12, 2017 at 23:19

Hi Renato,

apparently -I read it in the documentation- FLASH_OB_Launch() forces a reset of the CPU to get the data programmed. This could be the reason why the debugger loses the connection and the CPU hangs.

Anyhow, as I could also not live with a CPU reset in that situation, I simply overcame the problem by just using a page of the flash memory, which I now use as a “quasi-ram�.

The positive side-effect is that I can now make use of many more “flash� bytes than just two!

Best regards,

Gabriele