Skip to main content
Lutz.Tilo
Associate
May 12, 2015
Question

STM32F3 Option Byte problems

  • May 12, 2015
  • 2 replies
  • 880 views
Posted on May 12, 2015 at 08:35

Hello

I'm using an STM32F302CB. I use this code to protect the first pages of code which contains a bootloader:

[code]

uint32_t write_protected = FLASH_OB_GetWRP();

uint32_t protect_mask = OB_WRP_AllPages - BOOTLOADER_WP;

/*

Bootloader

pages are not write protected.

*/

if

(write_protected != protect_mask)

{

/*

* Unlock sequence

*/

FLASH_Unlock();

FLASH_OB_Unlock();

/*

* Enable WRP protection fails because factory default of the option flash is 00FF00FF00FFF.

* The function does a check for FFFF and an erase will set it to FFFF too.

* Therefore we do an erase of the option bytes before trying to protect the memory.

* This behavior is OK because no other settings of the option bytes excepts RDP is used.

*/

/*

* Clear flash flags

*/

FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);

if

(FLASH_OB_Erase() != FLASH_COMPLETE)

{

/*

* The best error handler we can do here is a reset

*/

NVIC_SystemReset();

}

/*

* Do some NOPs to take care of flash latency

*/

uint16_t loops = 40u;

while

(loops--)

{

__NOP();

}

/*

* Clear flash flags

*/

FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);

if

(FLASH_OB_EnableWRP(BOOTLOADER_WP) != FLASH_COMPLETE)

{

/*

* The best error handler we can do here is a reset

*/

NVIC_SystemReset();

}

/*

* Do some NOPs to take care of flash latency

*/

loops = 40u;

while

(loops--)

{

__NOP();

}

/*

* Write Protection OK, lock Flash and do

relaunch

of settings to ensure new settings are used.

*/

FLASH_OB_Lock();

FLASH_Lock();

FLASH_OB_Launch();

}

[/code]

IDE is IAR 7.4. Protecting the Flash pages is working. The Problem is I have some devices which have some Kind of locked Option Bytes. I tried JLinkSTM32.exe  which is included in IAR to reset Option Bytes. I tried it manually via jlink. Nothing is working. I'm not able to Change Option Bytes anymore.

RDP is _not_ set to 0xCC. It is set to 0xAA.

Any idea what might be wrong? I have this issue with several Controllers. At the moment I have to unsolder the not working MCUs and replace them with working Versions.

Thanks,

Tilo
    This topic has been closed for replies.

    2 replies

    Amel NASRI
    ST Technical Moderator
    May 21, 2015
    Posted on May 21, 2015 at 18:31

    Hi Tilo,

    Did you tried to unlock the protection on your devices using the ST-Link Utility?

    -Mayla-

    To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
    Lutz.Tilo
    Lutz.TiloAuthor
    Associate
    June 9, 2015
    Posted on June 09, 2015 at 07:56

    Hi

    I have not used the ST utility yet because I only have the Segger J-Link JTAG.

    I will try to get the debugger.