Reading/programming the STM32F10xxx embedded Flash memory PM0042 17 页这样写 This protection is activated by setting the RDP option byte. Once the protection byte has been programmed to a value: ● Main Flash memory read access is not allowed except for the user code (when booting from main Flash memory itself with the debug mode not active). ● Pages 0-3 (for low- and medium-density devices), or pages 0-1 (for high-density devices) are automatically write-protected. The rest of the memory can be programmed by the code executed from the main Flash memory (for IAP, constant storage, etc.), but it is protected against write/erase (but not against mass erase) in debug mode or when booting from the embedded SRAM. ● All features linked to loading code into and executing code from the embedded SRAM are still active (JTAG/SWD and boot from embedded SRAM) and this can be used to Reading/programming the STM32F10xxx embedded Flash memory PM0042 disable the read protection. When the read protection option byte is altered to a memory-unprotect value, a mass erase is performed.
/******************************************************************************* * Function Name : FLASH_ReadOutProtection * Description : Enables or disables the read out protection. * If the user has already programmed the other option bytes before * calling this function, he must re-program them since this * function erases all option bytes. * Input : - Newstate: new state of the ReadOut Protection. * This parameter can be: ENABLE or DISABLE. * Output : None * Return : FLASH Status: The returned value can be: FLASH_BUSY, * FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or * FLASH_TIMEOUT. *******************************************************************************/ FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState) { FLASH_Status status = FLASH_COMPLETE;
/* Check the parameters */ assert_param(IS_FUNCTIONAL_STATE(NewState));
status = FLASH_WaitForLastOperation(EraseTimeout);
if(status == FLASH_COMPLETE) { /* Authorizes the small information block programming */ FLASH->OPTKEYR = FLASH_KEY1; FLASH->OPTKEYR = FLASH_KEY2;
/* Wait for last operation to be completed */ status = FLASH_WaitForLastOperation(EraseTimeout);
if(status != FLASH_BUSY) { /* if the program operation is completed, disable the OPTPG Bit */ FLASH->CR &= CR_OPTPG_Reset; } } else { if(status != FLASH_BUSY) { /* Disable the OPTER Bit */ FLASH->CR &= CR_OPTER_Reset; } } } /* Return the protection operation Status */ return status; }