Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void UnlockFlash()
- {
- FLASH->KEYR = 0x45670123;
- FLASH->KEYR = 0xCDEF89AB;
- }
- void LockFlash()
- {
- SET_BIT(FLASH->CR, FLASH_CR_LOCK);
- }
- void UserFlash_Erase()
- {
- //Unlock FLASH register
- UnlockFlash();
- //Check that no Flash memory operation is ongoing by checking the BSY bit in the FLASH_SR register
- while (READ_BIT(FLASH->SR, FLASH_SR_BSY));
- //Set the SER bit
- SET_BIT(FLASH->CR, FLASH_CR_SER);
- //Select the sector out of the 12 sectors
- MODIFY_REG(FLASH->CR, FLASH_CR_SNB, USER_FLASH_SECTOR_INDEX << FLASH_CR_SNB_Pos);
- //Set the STRT bit in the FLASH_CR register
- SET_BIT(FLASH->CR, FLASH_CR_STRT);
- //Wait for the BSY bit to be cleared
- while(READ_BIT(FLASH->SR, FLASH_SR_BSY));
- //Lock FLASH register
- LockFlash();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement