AnsweredAssumed Answered

Writing to internal Flash

Question asked by gurnett.michael on Apr 9, 2013
Latest reply on Apr 9, 2013 by Clive One
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

-Michael

Outcomes