USB composite device example program, drag-and-drop flash writer.

Dependencies:   SWD USBDevice mbed BaseDAP

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Flash.h Source File

Flash.h

00001 // Flash.h 2013/9/16
00002 #pragma once
00003 #include "Target2.h"
00004 
00005 #define IAP_CCLK 12000
00006 
00007 /** Flash writer
00008  */
00009 class Flash {
00010 public:
00011     Flash(Target2* target, Serial* usbpc);
00012     bool init();
00013     bool write(const char* filename);
00014     bool write(int addr, const uint8_t* data, int size);
00015     bool eraseAll();
00016     bool verify(const char* filename);
00017     enum IAP_CMD {
00018         PREPARE_SECTOR = 50,
00019         COPY_RAM_TO_FLASH = 51,
00020         ERASE_SECTOR = 52,
00021         BLANK_CHECK = 53,
00022         READ_PART_ID = 54,
00023         READ_BOOT_CODE_VERSION = 55,
00024         COMPARE = 56,
00025         REINVOKE_ISP = 57,
00026         READ_UID = 58,
00027     };
00028     enum IAP_STATUS {
00029         CMD_SUCCESS = 0,
00030         INVALID_COMMAND =1,
00031         SRC_ADDR_ERROR = 2,
00032         DST_ADDR_ERROR = 3,
00033         SRC_ADDR_NOT_MAPPED = 4,
00034         DST_ADDR_NOT_MAPPED = 5,
00035         COUNT_ERROR = 6,
00036         INVALID_SECTOR = 7,
00037         SECTOR_NOT_BLANK = 8,
00038         SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION = 9,
00039         COMPARE_ERROR = 10,
00040         BUSY = 11,
00041         ADDR_ERROR = 13,
00042     };
00043     IAP_STATUS remoteIAP(IAP_CMD cmd, uint32_t p0=0, uint32_t p1=0, uint32_t p2=0, uint32_t p3=0);
00044 private:
00045     void _setup();
00046     bool _write_to_ram(int addr, int size, const uint8_t* buf);
00047     int _sector(int addr);
00048     bool _patch(uint8_t* buf, int size, int addr);
00049 protected:
00050     Target2* _target;
00051     Serial* _pc;
00052 };