2015-03-05 12:08 AM
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 me2017-12-28 05:44 AM
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.