Erasing page on stm32 fails with FLASH_ERROR_WRP

stm32 hal flash example
stm32 hal flash read/write example
stm32 save data to flash

I am trying to erase one page in flash on an STM32F103RB like so:

FLASHStatus = FLASH_ErasePage(Page);

However, FLASH_ErasePage fails producing FLASH_ERROR_WRP

Manually enabling/disabling write protection in the stm32-linker tool doesn't fix the problem.

Basically FLASH_ErasePage fails with WRP error without trying to do anything if there's previous WRP error in the status register.

What comes to your FLASH_ClearFlag call, at least FLASH_FLAG_BSY will cause assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG)); to fail (though I'm not really sure what happens in this case).

#define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFC0FD) == 0x00000000) && ((FLAG) != 0x00000000))

STM32F407 Flash Erase - Keil forum - Software Tools, However, FLASH_ErasePage fails producing FLASH_ERROR_WRP. Manually enabling/disabling write protection in the stm32-linker tool doesn't fix the  flash_erase cannot erase a page from the STM32L4 SOC flash. I've seen it, after investigating why MCUboot would never perform swapping and always resulted in panic. I concluded that the erase time of a 2K page is not enough. STM32L496xx datasheet states in 6.3.10 Flash memory characteristics, that the maximum

What is your page address ? Which address are you trying to access ? For instance, this example is tested on STM32F100C8 in terms of not only erasing but also writing data correctly.

Can not erase flash memory page using HAL Drivers, My problem occurs immediately after erasing a bock of the flash. FLASH_Sector_11)) // sectors 10 & 11 only { status = FLASH_ERROR_WRP; // set fault  Hi everyone, I am trying to work with JLink on an STM32F401CC. It is on an ST Eval Bord STEVAL-FCU001V1. It looks as if the STM32 cannot be flashed. You will find the JLinkExe Log below. Any hint you can give me is much appreciated! thanks & best…

If using the HAL driver, your code might look like this (cut'n paste from an real project)

static HAL_StatusTypeDef Erase_Main_Program ()
    FLASH_EraseInitTypeDef ins;
    uint32_t sectorerror;

    ins.Banks = FLASH_BANK_1; /* Do not care, used for mass-erase */
#warning We currently erase from sector 2 (only keep 64KB of flash for boot))
    ins.Sector = FLASH_SECTOR_4;
    ins.NbSectors = 4;
    ins.VoltageRange = FLASH_VOLTAGE_RANGE_3; /* voltage-range defines how big blocks can be erased at the same time */
    return HAL_FLASHEx_Erase (&ins, &sectorerror);

The internal function in the HAL driver that actually does the work

void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange)
  uint32_t tmp_psize = 0U;

  /* Check the parameters */

  if(VoltageRange == FLASH_VOLTAGE_RANGE_1)
     tmp_psize = FLASH_PSIZE_BYTE;
  else if(VoltageRange == FLASH_VOLTAGE_RANGE_2)
    tmp_psize = FLASH_PSIZE_HALF_WORD;
  else if(VoltageRange == FLASH_VOLTAGE_RANGE_3)
    tmp_psize = FLASH_PSIZE_WORD;
    tmp_psize = FLASH_PSIZE_DOUBLE_WORD;

  /* If the previous operation is completed, proceed to erase the sector */
  FLASH->CR |= tmp_psize;

Second thing to check. Is interrupts enabled, and is there any hardware access between the unlock call and the erase call?

I hope this helps

Possible bug when writing to flash using the EEPROM library (F7 , ;// error, BALAGAN!!! } } The program crashes at this line. if (​HAL_FLASHEx_Erase  Can´t erase data from flash memory (STM32) Ask Question Asked 4 years, STM32 Flash erase sector 0. 0. STM32 Virtual EEPROM Page Swap not working correctly. 0.

HAL Flash sector erase doesn't work consistently · Issue #6380 , hasenbanck opened this issue on Aug 8, 2018 · 9 comments I will receive a FLASH_ERROR_WRP error (FLASH Write protected error). I don't think it's a problem in the generic definition for the F7, since the page size and also the memory fpistm added this to To do in STM32 core based on ST HAL on Sep 19​, 2018. It seems to --probe correctly, erase correctly, the stlink led flashes, but it does not flash the actual firmware, i tried to flash the same firmware with the same setup on an stm32f103c8t6 and it worked. I'm using a cheap chinese stlink clone. Output with --debug:

Flash Memory Library, normads opened this issue on Mar 16, 2018 · 16 comments checking whether the sector is erased and erasing again in a loop usually works after 1 forum (​ just in case ? The constraint is: when you want to erase, you have to erase the whole sector. As you have seen, on STM32F7, there are 8 sectors, with different sizes (4 sectors of 32 Kbytes, 1 sector of 128 Kbytes, and 3 sectors of 256 Kbytes).

Page ERASING STM32 échoue avec FLASH_ERROR_WRP, This function will program one words into the on-chip flash. Each word in a page of Flash can only be programmed one time between an erase of that page; Erasing blocks you are currently executing from will likely crash the system. Both Erase and Write are self timing, functions return when complete or on failure, check the status returned. The CPU will block if you execute code from the same flash bank you are erasing or writing. This will also limit realtime responsiveness of interrupts, etc.