cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F3 Option Byte problems

Lutz.Tilo
Associate II
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
2 REPLIES 2
Amel NASRI
ST Employee
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 Accept as Solution on the reply which solved your issue or answered your question.

Lutz.Tilo
Associate II
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.