sim-card
/
sam7-util
Archived
9
0
Fork 0
Utility for SAM-BA flashing of AT91SAM7
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
sam7-util/loader/loader.c

48 lines
1.1 KiB

/*
* loader/loader.c
*
* Copyright (C) 2006 Erik Gilling, all rights reserved
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2.
*
*/
#include "at91.h"
// SAM-BA apears to write the following data to 0x201400
//
// 0x00: data0
// 0x01: data1
// ...
// PAGE_SIZE-1: last data byte
// PAGE_SIZE : page number to write
#define SAMBA_PAGE_BUFF ((uint32_t *) 0x201400)
int main( void )
{
int i;
uint32_t *page_buff = SAMBA_PAGE_BUFF;
// keep this in units of 32 bit words
int page_num = *(page_buff+PAGE_SIZE/4);
int page_offset = page_num * PAGE_SIZE/4;
// wait for mc to be ready
while( !(mc.fsr & AT91_MC_FMR_FRDY) ) { }
// write samba page buffer to flash buffer
for( i=0 ; i < (PAGE_SIZE/4) ; i++ ) {
AT91_FLASH_ADDR[ page_offset + i ] = page_buff[i];
}
// write page
mc.fcr = AT91_MC_FCR_FCMD_WP | AT91_MC_FCR_PAGEN(page_num) |
AT91_MC_FCR_KEY;
// dont wait for mc to be ready here so that flash ops can stack
return 0;
}