44 #define dbg_putchr(...) putchr(__VA_ARGS__)
45 #define dbg_putstr(...) putstr(__VA_ARGS__)
46 #define dbg_put_hex(...) put_hex(__VA_ARGS__)
47 #define dbg_put_hex16(...) put_hex16(__VA_ARGS__)
48 #define dbg_put_hex32(...) put_hex32(__VA_ARGS__)
50 #define dbg_putchr(...)
51 #define dbg_putstr(...)
52 #define dbg_put_hex(...)
53 #define dbg_put_hex16(...)
54 #define dbg_put_hex32(...)
60 while(*UART1_URXCON == 0);
68 uint32_t to_u32(
volatile uint32_t *c);
82 volatile uint32_t buf[4];
83 volatile uint32_t len=0;
84 volatile uint32_t state = SCAN_X;
85 volatile uint32_t addr,data;
88 uart_init(INC, MOD, SAMP);
93 dbg_putstr(
"Detecting internal nvm\n\r");
95 err = nvm_detect(gNvmInternalInterface_c, &type);
97 dbg_putstr(
"nvm_detect returned: 0x");
99 dbg_putstr(
" type is: 0x");
104 err = nvm_erase(gNvmInternalInterface_c, type, 0x7fffffff);
106 dbg_putstr(
"nvm_erase returned: 0x");
110 dbg_putstr(
" type is: 0x");
133 ((uint8_t *)buf)[0] =
'O'; ((uint8_t *)buf)[1] =
'K'; ((uint8_t *)buf)[2] =
'O'; ((uint8_t *)buf)[3] =
'K';
135 ((uint8_t *)buf)[0] =
'S'; ((uint8_t *)buf)[1] =
'E'; ((uint8_t *)buf)[2] =
'C'; ((uint8_t *)buf)[3] =
'U';
137 ((uint8_t *)buf)[0] =
'N'; ((uint8_t *)buf)[1] =
'O'; ((uint8_t *)buf)[2] =
'N'; ((uint8_t *)buf)[3] =
'O';
140 dbg_putstr(
" type is: 0x");
146 ((uint8_t *)buf)[0] =
'N';
147 ((uint8_t *)buf)[1] =
'O';
148 ((uint8_t *)buf)[2] =
'N';
149 ((uint8_t *)buf)[3] =
'O';
152 err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)buf, 0, 4);
154 dbg_putstr(
"nvm_write returned: 0x");
159 err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)&len, 4, 4);
162 for(i=0; i<len; i++) {
164 err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)&c, 8+i, 1);
167 putstr(
"flasher done\n\r");
169 state = SCAN_X; addr=0;
171 if(state == SCAN_X) {
174 if(c!=
'x'){
continue; }
179 if(state == READ_CHARS) {
181 ((uint8_t *)buf)[i++] = c;
184 if((c ==
',') || (c == 0)) { state =
PROCESS; }
193 putstr(
"writing addr ");
198 err = nvm_write(gNvmInternalInterface_c, 1, (uint8_t *)&data, addr, 4);
206 while(1) {
continue;};
212 while(*UART1_URXCON !=0) {
220 uint8_t from_hex(uint8_t ch)
222 if(ch==
' ' || ch==
'\r' || ch==
'\n')
233 return ch -
'a' + 10;
238 uint32_t to_u32(
volatile uint32_t *c)
240 volatile uint32_t ret=0;
241 volatile uint32_t i,val;
245 while(((uint8_t *)c)[i] !=
',') {
247 val = from_hex(((uint8_t *)c)[i++]);