Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: help! sam3s4 can not write flash
PostPosted: Tue Aug 30, 2011 9:35 pm 
Offline

Joined: Thu Aug 18, 2011 10:43 pm
Posts: 1
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;
}


Top
 Profile  
 
 Post subject: Re: help! sam3s4 can not write flash
PostPosted: Sun Apr 29, 2012 7:53 am 
Offline

Joined: Mon Aug 08, 2011 5:59 pm
Posts: 19
I know that that I'm answering this message after a long time.
but I had the same error, and I solved it by disabling all interrupts just before writing to flash, and enabling them again when I'm done.
I don't know why it happens, but this trick worked for me.


Top
 Profile  
 
 Post subject: Re: help! sam3s4 can not write flash
PostPosted: Sun Apr 29, 2012 3:06 pm 
Offline

Joined: Tue Jul 13, 2010 12:54 pm
Posts: 32
The function writing to flash should be run from SRAM, or a memory plane different to the one being programmed/written.

The datasheet states "Commands and read operations can be performed in parallel only on different memory planes.
Code can be fetched from one memory plane while a write or an erase operation is performed
on another."


Top
 Profile  
 
 Post subject: Re: help! sam3s4 can not write flash
PostPosted: Sun Apr 29, 2012 3:12 pm 
Offline

Joined: Tue Jul 13, 2010 12:54 pm
Posts: 32
http://www.at91.com/forum/viewtopic.php/f,24/t,20365/

It may be that you already have the write function running out of SRAM, but one or another function like printf for debug jumping back to flash operation before write access is finished


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron