|
36 | 36 | #include "cdc_enumerate.h"
|
37 | 37 |
|
38 | 38 | const char RomBOOT_Version[] = SAM_BA_VERSION;
|
39 |
| -const char RomBOOT_ExtendedCapabilities[] = "[Arduino:X]"; |
| 39 | +const char RomBOOT_ExtendedCapabilities[] = "[Arduino:XY]"; |
40 | 40 |
|
41 | 41 | /* Provides one common interface to handle both USART and USB-CDC */
|
42 | 42 | typedef struct
|
@@ -338,6 +338,61 @@ void sam_ba_monitor_loop(void)
|
338 | 338 | // Notify command completed
|
339 | 339 | ptr_monitor_if->putdata("X\n\r", 3);
|
340 | 340 | }
|
| 341 | + else if (command == 'Y') |
| 342 | + { |
| 343 | + // This command writes the content of a buffer in SRAM into flash memory. |
| 344 | + |
| 345 | + // Syntax: Y[ADDR],0# |
| 346 | + // Set the starting address of the SRAM buffer. |
| 347 | + |
| 348 | + // Syntax: Y[ROM_ADDR],[SIZE]# |
| 349 | + // Write the first SIZE bytes from the SRAM buffer (previously set) into |
| 350 | + // flash memory starting from address ROM_ADDR |
| 351 | + |
| 352 | + static uint32_t *src_buff_addr = NULL; |
| 353 | + |
| 354 | + if (current_number == 0) { |
| 355 | + // Set buffer address |
| 356 | + src_buff_addr = ptr_data; |
| 357 | + |
| 358 | + } else { |
| 359 | + // Write to flash |
| 360 | + uint32_t size = current_number/4; |
| 361 | + uint32_t *src_addr = src_buff_addr; |
| 362 | + uint32_t *dst_addr = ptr_data; |
| 363 | + |
| 364 | + // Set automatic page write |
| 365 | + NVMCTRL->CTRLB.bit.MANW = 0; |
| 366 | + |
| 367 | + // Do writes in pages |
| 368 | + while (size) { |
| 369 | + // Execute "PBC" Page Buffer Clear |
| 370 | + NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_PBC; |
| 371 | + while (NVMCTRL->INTFLAG.bit.READY == 0) |
| 372 | + ; |
| 373 | + |
| 374 | + // Fill page buffer |
| 375 | + uint32_t i; |
| 376 | + for (i=0; i<(PAGE_SIZE/4) && i<size; i++) { |
| 377 | + dst_addr[i] = src_addr[i]; |
| 378 | + } |
| 379 | + |
| 380 | + // Execute "WP" Write Page |
| 381 | + //NVMCTRL->ADDR.reg = ((uint32_t)dst_addr) / 2; |
| 382 | + NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_WP; |
| 383 | + while (NVMCTRL->INTFLAG.bit.READY == 0) |
| 384 | + ; |
| 385 | + |
| 386 | + // Advance to next page |
| 387 | + dst_addr += i; |
| 388 | + src_addr += i; |
| 389 | + size -= i; |
| 390 | + } |
| 391 | + } |
| 392 | + |
| 393 | + // Notify command completed |
| 394 | + ptr_monitor_if->putdata("Y\n\r", 3); |
| 395 | + } |
341 | 396 |
|
342 | 397 | command = 'z';
|
343 | 398 | current_number = 0;
|
|
0 commit comments