AT91SAM7S256 flash programming problem

Hi @all,

i’am trying to store some data in the internal flash memory (see code below). Unfortunately the ARM runs into a prefetch abort error after the write operation. After reset i check the programmed flash page and the content is correctly written. MCK is 48MHz and as the uarts are working correctly i’am sure to have it set up correctly.

		wrptr=(unsigned long *)(CONFIGADDR);		// #define CONFIGADDR 	(uint32_t)0x03C000
	
	// dump contents of memory section
	for(l=0;l<512;l+=4)
	{
		sprintf(buf,"%d: %08X  : %8X\r\n",l, (unsigned long)(wrptr),*(wrptr));
		write_str_USART1(buf);	
		
		wrptr++;
	}
	// write flash page
	wrptr=(unsigned long *)(CONFIGADDR);
	for(l=0;l<256;l+=4)
	{
		*(wrptr++) = 0x12345681;
	}
	AT91C_BASE_MC->MC_FMR = (((75)<<16) & AT91C_MC_FMCN) | AT91C_MC_FWS_1FWS;
	// wait for flash done/ready
	while(!(AT91C_BASE_MC->MC_FSR & AT91C_MC_FRDY));
	AT91C_BASE_MC->MC_FCR = (0x5A<<24) | (((CONFIGADDR/AT91C_IFLASH_PAGE_SIZE)<<8)&AT91C_MC_PAGEN) | AT91C_MC_FCMD_START_PROG;
	// ==== PREFETCH ABORT ERROR, following code never reached  ============================
	// wait for flash done/ready
	while(!(AT91C_BASE_MC->MC_FSR & AT91C_MC_FRDY));

Right now i’m a little bit clueless so any suggestions are welcome.

This code cannot be run from flash memory.

It is not possible for the processor to fetch instructions from

flash while the flashunit is writing your data to flash. So the prefetch error follows …

The solution is to place the flash writing code in RAM, there has been several threads on this board on how that is done.

Regards

Magnus

Thanks a lot, that was the missing clue. Everything is running fine now.