1 // minimalistic monitor
2 // to be loaded with the UART boot feature
3 // capable of reading and writing bytes, commanded by UART
9 typedef unsigned char UINT8
;
10 typedef unsigned short UINT16
;
11 typedef unsigned long UINT32
;
13 typedef void(*tpFunc
)(void); // type for exec
14 typedef int(*tpMain
)(void); // type for start vector to main()
20 // our binary has to start with a vector to the entry point
21 tpMain start_vector
[] __attribute__ ((section (".startvector"))) = {main
};
27 while (!(SSR1
& SCI_RDRF
)); // wait for char to be available
34 void uart_write(UINT8 byte
)
36 while (!(SSR1
& SCI_TDRE
)); // wait for transmit buffer empty
48 volatile UINT8
* paddr
= 0;
49 volatile UINT8
* pflash
; // flash base address
57 content
= uart_read();
58 uart_write(cmd
); // acknowledge by returning the command value
59 while (!(SSR1
& SCI_TEND
)); // wait for empty shift register, before changing baudrate
64 addr
= (uart_read() << 24) | (uart_read() << 16) | (uart_read() << 8) | uart_read();
66 pflash
= (UINT8
*)(addr
& 0xFFF80000); // round down to 512k align
67 uart_write(cmd
); // acknowledge by returning the command value
72 uart_write(content
); // the content is the ack
76 content
= uart_read();
78 uart_write(cmd
); // acknowledge by returning the command value
86 uart_write(content
); // the content is the ack
94 content
= uart_read();
97 uart_write(cmd
); // acknowledge by returning the command value
101 content
= uart_read();
102 pflash
[0x5555] = 0xAA; // set flash to command mode
103 pflash
[0x2AAA] = 0x55;
104 pflash
[0x5555] = 0xA0; // byte program command
106 uart_write(cmd
); // acknowledge by returning the command value
113 content
= uart_read();
114 pflash
[0x5555] = 0xAA; // set flash to command mode
115 pflash
[0x2AAA] = 0x55;
116 pflash
[0x5555] = 0xA0; // byte program command
119 uart_write(cmd
); // acknowledge by returning the command value
123 content
= *(UINT16
*)paddr
;
125 uart_write(content
>> 8); // highbyte
126 uart_write(content
& 0xFF); // lowbyte
130 content
= uart_read() << 8 | uart_read();
131 *(UINT16
*)paddr
= content
;
133 uart_write(cmd
); // acknowledge by returning the command value
138 tpFunc pFunc
= (tpFunc
)paddr
;
140 uart_write(cmd
); // acknowledge by returning the command value
147 volatile UINT16
* pPortB
= (UINT16
*)0x05FFFFC2;
148 *pPortB
|= 1 << 6; // bit 6 is red LED on
149 uart_write(~cmd
); // error acknowledge