ISP example program.

Dependencies:   SLCD mbed USBLocalFileSystem

/media/uploads/va009039/lpc81isp-360x240.jpg

FRDM-KL46ZLPC810
UART RXDPTE23p2(P0_4)
UART TXDPTE22p8(P0_0)
nRESETD6p1(P0_5)
nISPD8p5(P0_1)
GNDGNDp7
3.3VP3V3p6

Copy binary image to the disk called LPC81ISP.
Push sw1 or sw3, start write to LPC810 flash.

Committer:
va009039
Date:
Sun May 04 00:36:04 2014 +0000
Revision:
2:eafc1c6787c7
Parent:
1:cccfc461c61f
update USBLocalFileSystem library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 1:cccfc461c61f 1 #ifdef TARGET_KL46Z
va009039 2:eafc1c6787c7 2 #include "USBLocalFileSystem.h"
va009039 0:ad2b1fc04955 3 #include "BaseLpcIsp.h"
va009039 0:ad2b1fc04955 4 #include "SLCD.h"
va009039 0:ad2b1fc04955 5
va009039 0:ad2b1fc04955 6 DigitalOut led_sw(PTD5);
va009039 0:ad2b1fc04955 7 DigitalOut led_tx(PTE29);
va009039 0:ad2b1fc04955 8 #define LED_ON 0
va009039 0:ad2b1fc04955 9 #define LED_OFF 1
va009039 0:ad2b1fc04955 10
va009039 0:ad2b1fc04955 11 InterruptIn sw1(SW1);
va009039 0:ad2b1fc04955 12 InterruptIn sw3(SW3);
va009039 0:ad2b1fc04955 13 RawSerial pc(USBTX,USBRX);
va009039 0:ad2b1fc04955 14 SLCD slcd;
va009039 0:ad2b1fc04955 15
va009039 0:ad2b1fc04955 16 class lpc81isp : public BaseLpcIsp {
va009039 0:ad2b1fc04955 17 public:
va009039 0:ad2b1fc04955 18 lpc81isp(PinName txd, PinName rxd, PinName reset, PinName isp):BaseLpcIsp(txd, rxd, reset, isp){}
va009039 0:ad2b1fc04955 19 virtual void infoLED(int select, int value) {
va009039 0:ad2b1fc04955 20 switch(select) {
va009039 0:ad2b1fc04955 21 case LED_TX: led_tx = value ? LED_ON : LED_OFF; break;
va009039 0:ad2b1fc04955 22 }
va009039 0:ad2b1fc04955 23 }
va009039 0:ad2b1fc04955 24 virtual void infoSLCD(const char* s) { slcd.puts(s); }
va009039 2:eafc1c6787c7 25 } lpc(PTE22, PTE23, D6, D8); // TX,RX,nRESET,nISP
va009039 0:ad2b1fc04955 26
va009039 0:ad2b1fc04955 27 __IO bool write_start = false;
va009039 0:ad2b1fc04955 28 void swIRQ() {
va009039 0:ad2b1fc04955 29 led_sw = LED_ON;
va009039 0:ad2b1fc04955 30 wait_ms(100);
va009039 0:ad2b1fc04955 31 led_sw = LED_OFF;
va009039 0:ad2b1fc04955 32 write_start = true;
va009039 0:ad2b1fc04955 33 }
va009039 0:ad2b1fc04955 34
va009039 0:ad2b1fc04955 35 int main() {
va009039 0:ad2b1fc04955 36 pc.baud(9600);
va009039 0:ad2b1fc04955 37 pc.printf("%s", __FILE__);
va009039 0:ad2b1fc04955 38 led_sw = LED_OFF;
va009039 0:ad2b1fc04955 39 led_tx = LED_OFF;
va009039 0:ad2b1fc04955 40
va009039 0:ad2b1fc04955 41 sw1.rise(swIRQ);
va009039 0:ad2b1fc04955 42 sw3.rise(swIRQ);
va009039 0:ad2b1fc04955 43
va009039 2:eafc1c6787c7 44 USBLocalFileSystem* usb_local = new USBLocalFileSystem(); // RamDisk(64KB)
va009039 0:ad2b1fc04955 45 slcd.puts("REDY");
va009039 0:ad2b1fc04955 46 write_start = false;
va009039 0:ad2b1fc04955 47 while(1) {
va009039 0:ad2b1fc04955 48 if (write_start) {
va009039 2:eafc1c6787c7 49 usb_local->remount();
va009039 0:ad2b1fc04955 50 mystring filename;
va009039 0:ad2b1fc04955 51 if (LocalStorage::find_bin(filename)) {
va009039 0:ad2b1fc04955 52 pc.printf("bin filename=[%s]\n", filename.c_str());
va009039 0:ad2b1fc04955 53 lpc.baud(9600);
va009039 0:ad2b1fc04955 54 lpc.Reset(true); // ISP mode
va009039 0:ad2b1fc04955 55 lpc.Sync();
va009039 0:ad2b1fc04955 56 lpc.FlashWrite(filename.c_str());
va009039 0:ad2b1fc04955 57 lpc.Reset(false); // Reset
va009039 0:ad2b1fc04955 58 }
va009039 0:ad2b1fc04955 59 write_start = false;
va009039 0:ad2b1fc04955 60 }
va009039 2:eafc1c6787c7 61 if (usb_local->readable()) {
va009039 2:eafc1c6787c7 62 lpc.putc(usb_local->getc());
va009039 1:cccfc461c61f 63 }
va009039 1:cccfc461c61f 64 if (lpc.readable()) {
va009039 2:eafc1c6787c7 65 usb_local->putc(lpc.getc());
va009039 1:cccfc461c61f 66 }
va009039 0:ad2b1fc04955 67 if (pc.readable()) {
va009039 0:ad2b1fc04955 68 switch(pc.getc()) {
va009039 2:eafc1c6787c7 69 case 'w':
va009039 2:eafc1c6787c7 70 case 'W':
va009039 2:eafc1c6787c7 71 write_start = true;
va009039 2:eafc1c6787c7 72 break;
va009039 2:eafc1c6787c7 73 default:
va009039 2:eafc1c6787c7 74 break;
va009039 0:ad2b1fc04955 75 }
va009039 0:ad2b1fc04955 76 }
va009039 0:ad2b1fc04955 77 }
va009039 0:ad2b1fc04955 78 }
va009039 2:eafc1c6787c7 79 #endif // TARGET_KL46Z
va009039 2:eafc1c6787c7 80