AnsweredAssumed Answered

STM32F3 Option Byte problems

Question asked by Tilo on May 12, 2015
Latest reply on Jun 9, 2015 by Tilo
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

Outcomes