- Process read/write commands on the Flash memory.
Algorithm:
Synchronize the software UART.
Send the application '$' prompt
Infinite loop:
Wait for: c + al + ah + n + '\n'
IF c=='f' THEN read n bytes from Flash address al:ah
IF c=='F' THEN write n at Flash address al:ah
- Test application
./main.py --help
./main.py read 0 1024
./main.py write 0x800 0x55 # BE CAREFULL OF NOT OVERWRITING THE APPLICATION OR THE BOOTLOADER!
Note: if you have Diabolo installed, writing into the Flash memory below Diabolo will corrupt the application CRC and Diabolo will not start the application anymore after RESET. Oonly a few 0xFF bytes above Diabolo can be modified without changing the CRC. If the application does not start, you can still dump the Flash content with: diabolo.py --read-flash --hexdump
FIXME: the Diabolo host application should help repairing the CRC.
- config.h
#ifndef CONFIG_H
#define CONFIG_H
#include BOARD_H
#define UART HW_SWUARTA( txd, DIABOLO_PIN_TX, \
rxd, DIABOLO_PIN_RX, \
startirq, (DIABOLO_PIN_RX,port,pcic,irq), \
counter, counter1, \
compare, compare0, \
clkdiv, 1, \
autosync, 51, \
fastreg, (shared,gpior0) )
#endif
- main.c
#include "config.h"
uint8_t uart_getbyte ( )
{
while ( !
hw(stat,UART).rxc )
}
void uart_putbyte ( uint8_t byte )
{
while ( !
hw(stat,UART).txc )
}
static void process ( uint8_t byte )
{
static uint8_t bcount = 0 ;
static union {
uint8_t buf[4] ;
struct {
uint8_t cmd ;
uint16_t addr ;
uint8_t n ;
} ;
} buf ;
if ( bcount == 0 ) {
buf.cmd = byte ;
bcount++ ;
} else if ( bcount < 4 )
buf.buf[bcount++] = byte ;
else {
bcount = 0 ;
if ( byte == '\n'
if ( buf.cmd == 'F' ) {
hw( read_bytes, flash0, page, zpage,
sizeof(page) );
page[ zbyte ] = buf.n ;
hw( load_buffer, flash0, page );
hw( erase_page, flash0, zpage );
hw( write_page, flash0, zpage );
uart_putbyte( '$');
return ;
}
else if ( buf.cmd == 'f' ) {
while ( buf.n-- ) {
uint8_t
byte =
hw( read, flash0, buf.addr++ );
uart_putbyte( byte );
}
uart_putbyte( '$');
return ;
}
}
uart_putbyte( '!');
return ;
}
}
int
main ( )
{
sleep, enabled,
sleep_mode, idle );
hw( enable, interrupts );
while ( !
hw(stat,UART).sync )
uart_putbyte( '$');
for(;;) {
if (
hw(stat,UART).rxc ) {
process( uart_getbyte() );
}
}
}