Can't set Option Byte with the attached function for the Micro STM32L151CBT6A Only when the controller is new from factory. If we erase and reset the option bytes the STM32 afterwards new flashing it works.
void init_OptionByte (void)
{
FLASH->SR |= FLASH_SR_WRPERR ; // l�sche bestehende Fehler
FLASH->SR |= FLASH_SR_PGAERR ; // l�sche bestehende Fehler
FLASH->SR |= FLASH_SR_SIZERR ; // l�sche bestehende Fehler
FLASH->SR |= FLASH_SR_OPTVERR; // l�sche bestehende Fehler
#if TT_DEBUG == TT_ON /* Debug Betrieb */
NOP;
#else /* Release */
// Es soll:
if(( FLASH_OB_GetRDP() == RESET ) // Lese-Schutz bestehen
|| ( FLASH_OB_GetWRP() != 0x00000000 ) // kein Schreibschutz bestehen
|| ( FLASH_OB_GetUser() != 0x07 ) // nRST_STDBY,nRST_STOP,IWDG_SW
|| ( FLASH_OB_GetBOR() != OB_BOR_OFF )) // Brown-Out-Level 2
{
// falls nicht, folgende Aktionen
FLASH_Unlock(); // unlock flash memory for erase/write actions
FLASH_OB_Unlock(); // unlocks the option bytes block access
FLASH_OB_RDPConfig (OB_RDP_Level_1); // memory read protection on. Achtung Level 2 ist irreversibel und klemmt den EMU ab!!
FLASH_OB_WRPConfig (OB_WRP_AllPages, DISABLE); // memory write protection off (like default)
FLASH_OB_UserConfig(OB_IWDG_SW, OB_STOP_NoRST, OB_STDBY_NoRST); // Sw watch dog, no reset when entering stop mode, no reset when entering standby (like default)
FLASH_OB_BORConfig (OB_BOR_OFF); // brown out detection off
FLASH_OB_Launch(); // lauch the option byte loading. L�st RESET aus
FLASH_OB_Lock(); // unlocks the option bytes block access
FLASH_Lock(); // lock flash memory after erase/write actions
}
else
{
NOP;
}
#endif
}