cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to erase Flash sector - STM32F4Discovery

dan239955_stm1_st
Associate II
Posted on November 11, 2015 at 17:41

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

2 REPLIES 2
Posted on November 11, 2015 at 18:40

Any of the functions throwing errors, or timing out?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 12, 2015 at 00:57

What debugger are you using?

Can you instrument the code and output status/progress via a serial port?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..