Revision 162
Fixed bug in bootloader that writes to flash. Can now write to flash
bootloader.c | ||
---|---|---|
15 | 15 |
|
16 | 16 |
#define MAX_WAIT_IN_CYCLES 800000 |
17 | 17 |
#define MAX_TIMEOUT 60000 // Seconds to wait before exiting bootloader mode |
18 |
#define MAIN_ADDR 1024
|
|
18 |
#define MAIN_ADDR 0x400
|
|
19 | 19 |
|
20 | 20 |
//Status LED |
21 | 21 |
#define LED_DDR DDRB |
22 | 22 |
#define LED_PORT PORTB |
23 | 23 |
#define LED PORTB1 |
24 | 24 |
|
25 |
#define PAGE_SIZE 32 |
|
25 |
//#define PAGE_SIZE 32
|
|
26 | 26 |
|
27 | 27 |
//Function prototypes |
28 | 28 |
void flash_led(uint8_t); |
... | ... | |
181 | 181 |
int main(void) |
182 | 182 |
{ |
183 | 183 |
uint8_t mbuf[PROGD_PACKET_SIZE]; |
184 |
uint8_t check_sum = 0; |
|
185 |
uint16_t i; |
|
186 | 184 |
uint16_t caddr = MAIN_ADDR; |
187 | 185 |
|
188 | 186 |
uint8_t resp; |
189 |
uint16_t prog_len; |
|
187 |
uint16_t prog_len = 0;
|
|
190 | 188 |
|
191 | 189 |
init_uart(51); //MAGIC NUMBER?? |
192 | 190 |
init_timer(); |
... | ... | |
215 | 213 |
resp = parse_packet(mbuf); |
216 | 214 |
|
217 | 215 |
if (resp == TT_PROGD) { |
218 |
onboard_program_write(caddr, incoming_page_data);
|
|
216 |
onboard_program_write(caddr, mbuf);
|
|
219 | 217 |
caddr += PROGD_PACKET_SIZE; |
220 | 218 |
} else { |
221 | 219 |
while(1) { |
... | ... | |
237 | 235 |
} |
238 | 236 |
} |
239 | 237 |
|
240 |
#define SPM_PAGESIZE 32 |
|
238 |
//#define SPM_PAGESIZE 32
|
|
241 | 239 |
void onboard_program_write(uint16_t page, uint8_t *buf) |
242 | 240 |
{ |
243 | 241 |
uint16_t i; |
244 | 242 |
|
245 | 243 |
cli(); |
246 | 244 |
|
247 |
eeprom_busy_wait(); |
|
245 |
//eeprom_busy_wait();
|
|
248 | 246 |
|
249 | 247 |
boot_page_erase (page); |
250 | 248 |
boot_spm_busy_wait (); // Wait until the memory is erased. |
... | ... | |
252 | 250 |
for (i=0; i < SPM_PAGESIZE; i+=2){ |
253 | 251 |
// Set up little-endian word. |
254 | 252 |
|
255 |
uint16_t w = *buf++; |
|
256 |
w += (*buf++) << 8; |
|
253 |
//uint16_t w = *buf++;
|
|
254 |
//w += (*buf++) << 8;
|
|
257 | 255 |
|
258 |
boot_page_fill (page + i, w);
|
|
256 |
boot_page_fill (i, buf[i] | (buf[i+1] <<8));
|
|
259 | 257 |
} |
260 | 258 |
|
261 | 259 |
boot_page_write (page); // Store buffer in flash page. |
Also available in: Unified diff