Write protection on STM32F779ii

0

I'm trying to erase flash for STM32F779II.

The start up file starts with that section:

{
  FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1664K
  DTCMRAM (xrw)   : ORIGIN = 0x20000000, LENGTH = 128K
  SRAM1 (xrw)     : ORIGIN = 0x20020000, LENGTH = 368K
  SRAM2 (xrw)     : ORIGIN = 0x2007C000, LENGTH = 16K
  MEMORY_B1 (rx)  : ORIGIN = 0x60000000, LENGTH = 0K
}

So I'm leaving that three sections.

I'm trying to clear sector number 22. but I get Write Protection Error.

Here is how I'm earsing it.

Sectors is an array with one element, which is 22 sector number which has address 0x081C0000

secbool flash_erase_sectors(const uint8_t *sectors, int len,
                            void (*progress)(int pos, int len)) {
  ensure(flash_unlock_write(), NULL);
  HAL_FLASH_OB_Unlock();


  FLASH_EraseInitTypeDef EraseInitStruct;
  EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
  EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
  EraseInitStruct.NbSectors = 1;
  if (progress) {
    progress(0, len);
  }
  for (int i = 0; i < len; i++) {
    EraseInitStruct.Sector = sectors[i];
    uint32_t SectorError;
    if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
      ensure(flash_lock_write(), NULL);
      return secfalse;
    }
    // check whether the sector was really deleted (contains only 0xFF)
    const uint32_t addr_start = FLASH_SECTOR_TABLE[sectors[i]],
                   addr_end = FLASH_SECTOR_TABLE[sectors[i] + 1];
    for (uint32_t addr = addr_start; addr < addr_end; addr += 4) {
      if (*((const uint32_t *)addr) != 0xFFFFFFFF) {
        ensure(flash_lock_write(), NULL);
        return secfalse;
      }
    }
    if (progress) {
      progress(i + 1, len);
    }
  }
  ensure(flash_lock_write(), NULL);
  return sectrue;
}
c
stm32
stm32f7
asked on Stack Overflow Sep 4, 2019 by Ahmed Saleh

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0