ISP example program.
Dependencies: SLCD mbed USBLocalFileSystem
FRDM-KL46Z | LPC810 | |
---|---|---|
UART RXD | PTE23 | p2(P0_4) |
UART TXD | PTE22 | p8(P0_0) |
nRESET | D6 | p1(P0_5) |
nISP | D8 | p5(P0_1) |
GND | GND | p7 |
3.3V | P3V3 | p6 |
Copy binary image to the disk called LPC81ISP.
Push sw1 or sw3, start write to LPC810 flash.
main.cpp
- Committer:
- va009039
- Date:
- 2014-02-16
- Revision:
- 1:cccfc461c61f
- Parent:
- 0:ad2b1fc04955
- Child:
- 2:eafc1c6787c7
File content as of revision 1:cccfc461c61f:
#ifdef TARGET_KL46Z #include "RamDisk.h" #include "Storage.h" #include "BaseLpcIsp.h" #include "SLCD.h" DigitalOut led_sw(PTD5); DigitalOut led_tx(PTE29); #define LED_ON 0 #define LED_OFF 1 InterruptIn sw1(SW1); InterruptIn sw3(SW3); RawSerial pc(USBTX,USBRX); SLCD slcd; class lpc81isp : public BaseLpcIsp { public: lpc81isp(PinName txd, PinName rxd, PinName reset, PinName isp):BaseLpcIsp(txd, rxd, reset, isp){} virtual void infoLED(int select, int value) { switch(select) { case LED_TX: led_tx = value ? LED_ON : LED_OFF; break; } } virtual void infoSLCD(const char* s) { slcd.puts(s); } } lpc(PTE22, PTE23, PTB0, PTB1); // TX,RX,nRESET,nISP __IO bool write_start = false; void swIRQ() { led_sw = LED_ON; wait_ms(100); led_sw = LED_OFF; write_start = true; } int main() { pc.baud(9600); pc.printf("%s", __FILE__); led_sw = LED_OFF; led_tx = LED_OFF; sw1.rise(swIRQ); sw3.rise(swIRQ); RamDisk* ramdisk = new RamDisk; USBStorage2* usb = new USBStorage2(ramdisk); LocalStorage* local = NULL; slcd.puts("REDY"); write_start = false; while(1) { if (write_start) { if (local) { delete local; } local = new LocalStorage(ramdisk); mystring filename; if (LocalStorage::find_bin(filename)) { pc.printf("bin filename=[%s]\n", filename.c_str()); lpc.baud(9600); lpc.Reset(true); // ISP mode lpc.Sync(); lpc.FlashWrite(filename.c_str()); lpc.Reset(false); // Reset } write_start = false; } if (usb->readable()) { lpc.putc(usb->getc()); } if (lpc.readable()) { usb->putc(lpc.getc()); } if (pc.readable()) { switch(pc.getc()) { case 'd': ramdisk->dump(0); break; case 'D': ramdisk->dump(1); break; case 'w': write_start = true; break; } } } } #endif