void dfu_protect(dfu_mode_t mode) { if (mode == DFU_MODE) { #ifdef DFU_SELF_PROTECT if ((FLASH_WRPR & 0x03) != 0x00) { flash_unlock(); FLASH_CR = 0; flash_erase_option_bytes(); flash_program_option_bytes(FLASH_OBP_RDP, FLASH_OBP_RDP_KEY); /* CL Device: Protect 2 bits with (2 * 2k pages each)*/ /* MD Device: Protect 2 bits with (4 * 1k pages each)*/ flash_program_option_bytes(FLASH_OBP_WRP10, 0x03FC); } #endif } else if (mode == UPD_MODE) { flash_unlock(); FLASH_CR = 0; flash_erase_option_bytes(); } }
void dfu_protect_enable(void) { #ifdef DFU_SELF_PROTECT if ((FLASH_WRPR & 0x03) != 0x00) { flash_unlock(); FLASH_CR = 0; flash_erase_option_bytes(); flash_program_option_bytes(FLASH_OBP_RDP, FLASH_OBP_RDP_KEY); /* CL Device: Protect 2 bits with (2 * 2k pages each)*/ /* MD Device: Protect 2 bits with (4 * 1k pages each)*/ flash_program_option_bytes(FLASH_OBP_WRP10, 0x03FC); } #endif }