/******************************************************************************* * Function Name : FLASH_DisableWriteProtectionPages * Description : Disable the write protection of desired pages * Input : None * Output : None * Return : None *******************************************************************************/ void FLASH_DisableWriteProtectionPages(void) { u32 useroptionbyte = 0, WRPR = 0; u16 var1 = OB_IWDG_SW, var2 = OB_STOP_NoRST, var3 = OB_STDBY_NoRST; FLASH_Status status = FLASH_BUSY; WRPR = FLASH_GetWriteProtectionOptionByte(); /* Test if user memory is write protected */ if ((WRPR & UserMemoryMask) != UserMemoryMask){ useroptionbyte = FLASH_GetUserOptionByte(); UserMemoryMask |= WRPR; status = FLASH_EraseOptionBytes(); if(UserMemoryMask != 0xFFFFFFFF){ status = FLASH_EnableWriteProtection((u32)~UserMemoryMask); } /* Test if user Option Bytes are programmed */ if((useroptionbyte & 0x07) != 0x07){ /* Restore user Option Bytes */ if((useroptionbyte & 0x01) == 0x0){ var1 = OB_IWDG_HW; } if((useroptionbyte & 0x02) == 0x0){ var2 = OB_STOP_RST; } if((useroptionbyte & 0x04) == 0x0){ var3 = OB_STDBY_RST; } FLASH_UserOptionByteConfig(var1, var2, var3); } if (status == FLASH_COMPLETE){ SerialPutString("Write Protection disabled...\r\n"); SerialPutString("...and a System Reset will be generated to re-load the new option bytes\r\n"); /* Enable WWDG clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE); /* Generate a system Reset to re-load the new option bytes: enable WWDG and set counter value to 0x4F, as T6 bit is cleared this will generate a WWDG reset */ WWDG_Enable(0x4F); }else{ SerialPutString("Error: Flash write unprotection failed...\r\n"); } }else{ SerialPutString("Flash memory not write protected\r\n"); } }
/** * @brief Disable the write protection of desired pages * @param None * @retval None */ void FLASH_DisableWriteProtectionPages(void) { uint32_t useroptionbyte = 0, WRPR = 0; uint16_t var1 = OB_IWDG_SW, var2 = OB_STOP_NoRST, var3 = OB_STDBY_NoRST; FLASH_Status status = FLASH_BUSY; WRPR = FLASH_GetWriteProtectionOptionByte(); /* Test if user memory is write protected */ if ((WRPR & UserMemoryMask) != UserMemoryMask) { useroptionbyte = FLASH_GetUserOptionByte(); UserMemoryMask |= WRPR; status = FLASH_EraseOptionBytes(); if (UserMemoryMask != 0xFFFFFFFF) { status = FLASH_EnableWriteProtection((uint32_t)~UserMemoryMask); } /* Test if user Option Bytes are programmed */ if ((useroptionbyte & 0x07) != 0x07) { /* Restore user Option Bytes */ if ((useroptionbyte & 0x01) == 0x0) { var1 = OB_IWDG_HW; } if ((useroptionbyte & 0x02) == 0x0) { var2 = OB_STOP_RST; } if ((useroptionbyte & 0x04) == 0x0) { var3 = OB_STDBY_RST; } FLASH_UserOptionByteConfig(var1, var2, var3); } if (status == FLASH_COMPLETE) { SerialPutString("Write Protection disabled...\r\n"); SerialPutString("...and a System Reset will be generated to re-load the new option bytes\r\n"); /* Generate System Reset to load the new option byte values */ NVIC_SystemReset(); } else { SerialPutString("Error: Flash write unprotection failed...\r\n"); } } else { SerialPutString("Flash memory not write protected\r\n"); } }