2013-04-09 09:26 AM
I'm trying to write to the internal flash of a STM32F103ZE. I've been using the following code
FLASH_Unlock(); uint32_t Start=0x8008000; uint32_t End =0x800C000; NbrOfPage = (End - Start) / FLASH_PAGE_SIZE; /* Clear All pending flags */ FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR); /* Erase the FLASH pages */ for(EraseCounter=0; EraseCounter<NbrOfPage && (FLASHStatus == FLASH_COMPLETE); EraseCounter++) { FLASHStatus = FLASH_ErasePage(Start + (FLASH_PAGE_SIZE * EraseCounter)); } uint32_t Address = Start; while((Address < End) && (FLASHStatus == FLASH_COMPLETE)) { FLASHStatus = FLASH_ProgramWord(Address, Data); Address = Address + 4; } FLASH_Lock(); However, this results in a visit to the hardfault_handler. Are there some other steps required to get this working? I'm using crossworks. Thanks -Michael2013-04-09 11:12 AM
Doesn't look too objectionable. Make sure you don't erase memory you are currently executing from.
Diagnose the cause of the Hard Fault, understand the registers and processor state when it faulted. If you understand where, and why, it faulted you'd be in a better position to solve the problem.