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.

Revision:
2:eafc1c6787c7
Parent:
1:cccfc461c61f
--- a/src/RamDisk.cpp	Sun Feb 16 12:56:12 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,120 +0,0 @@
-#include "RamDisk.h"
-
-#if (DEBUG2 > 3)
-#define RAMDISK_DBG(...) do{fprintf(stderr,"[%s@%d] ",__PRETTY_FUNCTION__,__LINE__);fprintf(stderr,__VA_ARGS__);fprintf(stderr,"\r\n");} while(0);
-#else
-#define RAMDISK_DBG(...)
-#endif
-
-RamDisk::RamDisk()
-{
-    format();
-    _sectors = 128; // 128*512 64Kbytes
-}
-
-/* virtual */ int RamDisk::storage_initialize()
-{
-    return 0;
-}
-
-/* virtual */ uint32_t RamDisk::storage_sectors()
-{
-    return _sectors;
-}
-
-/* virtual */ uint32_t RamDisk::storage_size()
-{
-    return _sectors * 512;
-}
-
-/* virtual */ int RamDisk::storage_status()
-{
-    return 0;
-}
-
-/* virtual */ int RamDisk::storage_read(uint8_t * data, uint32_t block)
-{
-    RAMDISK_DBG("R block=%d", block);
-    memset(data, 0x00, 512);
-    if (_sector_image.count(block) > 0) {
-        uint8_t* buf = _sector_image[block];
-        int size = buf[0]|(buf[1]<<8);
-        memcpy(data, buf + 2, size);
-    }
-    return 0;
-}
-
-bool is_romdata(uint8_t* data)
-{
-    return data < (uint8_t*)0x1ffff000;
-}
-
-static int block_size(const uint8_t* data)
-{
-    for(int i = 512-1; i >= 0; i--) {
-        if (data[i] != 0x00) {
-            return i+1;
-        }
-    }
-    return 0;
-}
-
-/* virtual */ int RamDisk::storage_write(const uint8_t * data, uint32_t block)
-{
-    int size = block_size(data);
-    if (_sector_image.count(block) > 0) {
-        uint8_t* buf = _sector_image[block];
-        if (!is_romdata(buf)) {
-            free(buf);
-        }
-        buf = (uint8_t*)malloc(size + 2);
-        if (buf == NULL) {
-            RAMDISK_DBG("DISK FULL");
-            exit(1);
-            return 1;
-        }
-        _sector_image[block] = buf;
-        buf[0] = size;
-        buf[1] = size>>8;
-        memcpy(buf + 2, data, size);
-        RAMDISK_DBG("W block=%d size=%d", (int)block, size);
-    } else if (size > 0) {
-        uint8_t* buf = (uint8_t*)malloc(size + 2);
-        if (buf == NULL) {
-            RAMDISK_DBG("DISK FULL");
-            exit(1);
-            return 1;
-        }
-        _sector_image[block] = (uint8_t*)buf;
-        buf[0] = size;
-        buf[1] = size>>8;
-        
-        memcpy(buf + 2, data, size);
-        RAMDISK_DBG("W block=%d size=%d NEW %d", (int)block, size, _sector_image.size());
-    } else {
-        RAMDISK_DBG("W block=%d BLANK", (int)block);
-    }
-    return 0;
-}
-
-void RamDisk::dump(int mode)
-{
-    printf("static const uint8_t block_image[] = { // %d blocks\n", _sector_image.size());
-    for(int i = 0; i < _sector_image.size(); i++) {
-        int block = _sector_image.getKey(i);
-        uint8_t* buf = _sector_image[block];
-        int size = buf[0]|(buf[1]<<8);
-        printf("0x%02x,0x%02x,0x%02x, // block=%d, size=%d\n", 
-                                block, buf[0], buf[1], block, size);
-        if (mode == 1) {
-            for(int j = 0; j < size; j++) {
-                printf("0x%02x,", buf[j+2]);
-                if ((j % 16) == 15 || j == size-1) {
-                    printf("\n");
-                }
-            }
-        }
-    }
-    printf("0xff};\n");
-}
-