cancel
Showing results for 
Search instead for 
Did you mean: 

problem with use HAL_FLASH_Program

askari.nima
Associate II
Posted on March 05, 2015 at 09:08

when i use this function

uint8_t    Save_data(void)

{

    uint8_t    idx;

    uint8_t    addr;

    FLASH_EraseInitTypeDef    erase;

    uint32_t    pg_error;

    HAL_FLASH_Unlock();

    erase.NbPages = 1;

    erase.PageAddress = ADDR_FLASH_PAGE_127;

    erase.TypeErase = FLASH_TYPEERASE_PAGES;

    if(HAL_FLASHEx_Erase(&erase,&pg_error)!= HAL_OK)

    {

        HAL_FLASH_Lock();

        return 0;    

    }

    

    addr=0;

    for(idx=0; idx <9 ; idx++)

    {

        if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,(uint32_t)(ADDR_FLASH_PAGE_127+addr),(uint64_t)param[idx])!= HAL_OK)

        {

            HAL_FLASH_Lock();

            return 0;

        }

        addr++;

    }

    HAL_FLASH_Lock();

    return 1;

}

my system going to HardFault_Handler

and only write first byte of data to flash .

please help me
1 REPLY 1
Flavio Alves
Associate II
Posted on December 28, 2017 at 14:44

Hello,

I also had this problem. This post is old, but can be an issue still for other (like me).

In my case, I deleted flash area where my code was located. When it executed again, it got lost and thus, the hard fault.

It is important to check exactly the sectors that we need to erase.