AnsweredAssumed Answered

problem with use HAL_FLASH_Program

Question asked by askari.nima on Mar 5, 2015
Latest reply on Dec 28, 2017 by Flavio Alves
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

Outcomes