Skip to main content
askari.nima
Associate III
March 5, 2015
Question

problem with use HAL_FLASH_Program

  • March 5, 2015
  • 1 reply
  • 509 views
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
    This topic has been closed for replies.

    1 reply

    Flavio Alves
    Associate II
    December 28, 2017
    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.