Simple applet-like flash loader routine

ATMEL in-system programing solution including SAM-BA and SAM-PROG.

Moderators: nferre, fab

bernau84
Posts: 1
Joined: Sun Apr 06, 2014 11:07 am

Simple applet-like flash loader routine

Sun Apr 06, 2014 11:50 am

I have tried simple loader routine instead of complex sam-ba applet adoption to update internal flash. The idea is to write payload and loader into sram (x-modem) together and then directly jump (GO20001000# command) to routine which successively copies the payload data into flash. Unfortunately - such loader seems to doesn't run. I'm sure the loader is position independent cause it doesn't use stack or library function (and i've tried it with jtag as well). Loader should blink with LED in first after start, but it won't happen. GO command is not probably trivial assembler branch instruction, isn't it?

Loader routine:

Code: Select all

void copy_ram_to_flash(void) __attribute__((section("ldr")));  //0x20001000
void copy_ram_to_flash(void){
	
	register unsigned d = LOADER_PG_BGN;	//destination page number
        register unsigned s = LOADER_PAYLOAD;	//source (0x20001500)
	register unsigned i;	//inner loop
	
	REG_PIOA_PER = PIO_PA16;  //indication LED init
	REG_PIOA_OER = PIO_PA16;
	REG_PIOA_OWER = PIO_PA16;
	
	while(d <= LOADER_PG_END){  //copy payload from page to page int[color=#FF0000]o flash
		
		REG_PIOA_CODR = PIO_PA16; //indication pro update process
		for(i = 1000000; i > 0; i--){;}
		REG_PIOA_SODR = PIO_PA16;
		for(i = 1000[/color]000; i > 0; i--){;}
		
		while (0 == (LOADER_EFC_STA & 0x1));  //wait for efc status ready
		
		for(i = 0; i < LOADER_PG_SZ; i += 4)			//fill efc latch buffet
			*(unsigned *)(LOADER_FLASH + i) = *(unsigned *)(s + i);
				
		LOADER_EFC_CMD = 0x5A000003 | (d << 8);	//write & erase efc command
		
		d += 1;
		s += LOADER_PG_SZ;
	}	
	
	while (0 == (LOADER_EFC_STA & 0x1));  //wait for efc status ready
	LOADER_RST_CNT = 0xA500000F;	//reset proc. to bet back to SAM-BA	
}

Return to “AT91-ISP”

Who is online

Users browsing this forum: No registered users and 1 guest