|
Hi,
I am using sam3s4 for one of my design, I need to write some data into the flash for the data backup in case of power lost. Whenever I try to write or read the flash, my code will stop working. With the debugger, I can see it always goes to a infiniti loop, HardFault_Handler. I use the atmel library to write my code, the plateform is iar for arm v5.50 + j-link v8.0.
I really appreciate for your advice.
uint8_t WriteFlash(void) { uint32_t i; uint8_t error=0; uint32_t lastPageAddress; volatile uint32_t *pLastPageData; /* Performs on last page (to avoid overriding existing program).*/ lastPageAddress = IFLASH_ADDR + IFLASH_SIZE - IFLASH_PAGE_SIZE; pLastPageData = (volatile uint32_t *) lastPageAddress; /* Unlock page */ error = FLASHD_Unlock(lastPageAddress, lastPageAddress + IFLASH_PAGE_SIZE, 0, 0);
/* Write page */ error = FLASHD_Write(lastPageAddress, NVram, IFLASH_PAGE_SIZE);
/* Check page contents */ for (i=0; i < (IFLASH_PAGE_SIZE / 4); i++) { if (NVram[i] != pLastPageData[i]) return (1) ; } /* Lock page */ error = FLASHD_Lock( lastPageAddress, lastPageAddress + IFLASH_PAGE_SIZE, 0, 0 ) ;
/* Set GPNVM bit 0 (security bit) */ error = FLASHD_SetGPNVM( 0 ) ; return error; }
|