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.
Diff: src/RamDisk.cpp
- Revision:
- 2:eafc1c6787c7
- Parent:
- 1:cccfc461c61f
diff -r cccfc461c61f -r eafc1c6787c7 src/RamDisk.cpp --- 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"); -} -