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 USBMSD_LPC.cpp Source File

USBMSD_LPC.cpp

00001 // USBMSD_LPC.cpp 2013/9/28
00002 #include "mbed.h"
00003 #include "USBMSD_LPC.h"
00004 #define MY_DEBUG
00005 #include "mydebug.h"
00006 
00007 #ifdef TARGET_LPC1768
00008 #define LED_ON  1
00009 #define LED_OFF 0
00010 #endif
00011 #ifdef TARGET_KL25Z
00012 #define LED_ON  0
00013 #define LED_OFF 1
00014 #endif
00015 DigitalOut led3(LED3);
00016 
00017 USBMSD_LPC::USBMSD_LPC(SWD* swd, Serial* usbpc) : _pc(usbpc)
00018 {
00019     _target = new Target2(swd);
00020     _flash = NULL;
00021     led3 = LED_OFF;
00022 }
00023 
00024 /* virtual */ void USBMSD_LPC::Drop(const uint8_t* data, int len, int offset, int total)
00025 {
00026     if (_flash == NULL) {
00027         _target->setup();
00028         _flash = new Flash(_target, _pc);
00029     }    
00030     DBG("%d/%d", offset, total);
00031     if (offset == 0) {
00032         _flash->init();
00033         _flash->eraseAll();
00034         led3 = LED_ON;
00035     }
00036     _flash->write(offset, data, len);
00037     led3 = !led3;
00038     if (offset+len >= total) {
00039         led3 = LED_OFF;
00040         delete _flash;
00041         _flash = NULL;
00042         _target->SoftwareReset();
00043         _target->setup();
00044     }
00045 }