diff --git a/atusb/fw/flash.c b/atusb/fw/flash.c index cd29b5b..3b12a56 100644 --- a/atusb/fw/flash.c +++ b/atusb/fw/flash.c @@ -14,6 +14,7 @@ #include #include +#include #include "dfu.h" #include "board.h" @@ -30,7 +31,7 @@ void flash_start(void) int flash_can_write(uint16_t size) { - return 1; + return payload+size <= BOOT_ADDR; } @@ -67,5 +68,13 @@ void flash_write(const uint8_t *buf, uint16_t size) uint16_t flash_read(uint8_t *buf, uint16_t size) { - return 0; + uint16_t got = 0; + + while (size && payload != (uint32_t) FLASHEND+1) { + *buf++ = pgm_read_byte(payload); + payload++; + size--; + got++; + } + return got; }