STM32F030 Read protection
Looking to see if someone can shed some additional light on programming the memory read protection level 1 or 2 for a STM32F030 device. There are a few examples but they perform other options that are not required for my application. I have unlocked the flash but experiencing questions on whether or not to set the user data 0 & 1 option bytes before setting the read protection in the flashprotect function and what other code is required.
void unlockflash(void)
{ while ((FLASH->SR & FLASH_SR_BSY) != 0) if ((FLASH->CR & FLASH_CR_LOCK) != 0) { FLASH->KEYR = FLASH_FKEY1; FLASH->KEYR = FLASH_FKEY2; } if ((FLASH->CR & FLASH_CR_OPTWRE) == 0) { FLASH->OPTKEYR = FLASH_OPTKEY1; FLASH->OPTKEYR = FLASH_OPTKEY2; } } void flashprotect(void) { OB->RDP |= 0xAA; // program read protect, 0xAA level 0, 0xAB level 1, 0xCC level 2. } /* main: initialize and start the system */ void asmfunc(void); int __attribute__((naked)) main(void) { osKernelInitialize( ); // initialize CMSIS-RTOS SystemCoreClockConfigure( ); // configure System Clock configureGPIO( ); // configure GPIO's unlockflash( ); // unlock flash flashprotect( ); //read/write protect flash asmfunc( ); // jump to assembly code osKernelStart( ); // start thread execution } #stm32-read-protection