AnsweredAssumed Answered

Unable to write to internal flash - STM32F4Discovery

Question asked by walmsley.dan on Nov 11, 2015
Latest reply on Nov 12, 2015 by Dheeraj
I have the following code:


 FLASH_EraseInitTypeDef EraseInitStruct;

    __HAL_FLASH_INSTRUCTION_CACHE_RESET ();
    
__HAL_FLASH_INSTRUCTION_CACHE_ENABLE ();

    
HAL_FLASH_Unlock ();
    /* Get the 1st sector to erase */
    // FirstSector = GetSector (Start_Addr);

    /* Get the number of sector to erase from 1st sector*/
    // NbOfSectors = GetSector (End_Addr) - FirstSector + 1;


    uint32_t SectorError;
    /* Fill EraseInit structure*/
    EraseInitStruct.TypeErase = TYPEERASE_SECTORS;

    EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3;

    EraseInitStruct.Sector = FLASH_SECTOR_1;

    EraseInitStruct.NbSectors = 1;

    
__HAL_FLASH_CLEAR_FLAG (FLASH_FLAG_EOP | FLASH_FLAG_OPERR |
                            FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR);

    if (
HAL_FLASHEx_Erase (&EraseInitStruct, &SectorError) != HAL_OK)
    {
        return false;
    }

    
FLASH_WaitForLastOperation (10000);

    uint32_t* ptr = (uint32_t*)0x8004000;

    uint32_t value = *ptr;

    if (value == 0xFFFFFFFF)
    {
        return true;
    }
    else
    {
        return false;
    }


I expect this to  make the value at address 0x08004000 read 0xFFFFFFFF but it doesn't.

    Any ideas why not? I'm running this and stepping through to verify.

Any help is much appreciated.

D

Outcomes