semihost server example program
Dependencies: SWD mbed USBLocalFileSystem BaseDAP USBDAP
LPCXpresso LPC11U68 | LPCXpresso LPC1549 | FRDM-KL46Z | EA LPC4088 QSB app-board | LPC1768 app-board | LPC810 | LPC1114FN28 | |
---|---|---|---|---|---|---|---|
server | server | server | server | server | client | client | |
SWDIO | D12 | D12 | D12 | p25 | p21 | p4(P0_2) | p12 |
SWCLK | D10 | D10 | D10 | p26 | p22 | p3(P0_3) | p3 |
nRESET *option | D6 | D6 | D6 | p34 | p30 | p1(P0_5) | p23 |
GND | GND | GND | GND | p1 | p1 | p7 | p22 |
3.3V | P3V3 | P3V3 | P3V3 | p44 | p40 | p6 | p21 |
flash write | SW2(P0_1) | SW3(P1_9) | SW1 | p14 joystick center | p14 joystick center |
client example:
Import programlpc810-semihost_helloworld
semihost client example program
Diff: Flash.cpp
- Revision:
- 3:d7a7cde0bfb8
- Parent:
- 2:32e9437348ad
- Child:
- 4:5e4107edcbdb
--- a/Flash.cpp Thu Sep 05 09:34:12 2013 +0000 +++ b/Flash.cpp Sun Sep 08 14:13:15 2013 +0000 @@ -1,8 +1,13 @@ -// Flash.cpp 2013/9/5 +// Flash.cpp 2013/9/6 #include "Flash.h" #include "Target2.h" #include "mydebug.h" +#define SYSMEMREMAP 0x40048000 +#define MAINCLKSEL 0x40048070 +#define MAINCLKUEN 0x40048074 +#define SYSAHBCLKDIV 0x40048078 + Flash::Flash(Target2* target, Serial* usbpc) :_target(target),_pc(usbpc) { _setup(); @@ -14,6 +19,29 @@ _target->wait_status(TARGET_HALTED); } +bool Flash::init() +{ + _pc->printf("Initializing."); + if (_target->idcode == 0x0bb11477) { // LPC1114FN28 + _target->writeMemory(MAINCLKSEL, 0); // Select Internal RC Oscillator + _target->writeMemory(MAINCLKUEN, 1); // Update Main Clock Source + _target->writeMemory(MAINCLKUEN, 0); // Toggle Update Register + _target->writeMemory(MAINCLKUEN, 1); + uint32_t data = _target->readMemory(MAINCLKUEN); // Wait until updated + if (!(data & 1)) { + _pc->printf("\nerror MAINCLKUEN=%08x\n", data); + return false; + } + _target->writeMemory(SYSAHBCLKDIV, 1);// Set Main Clock divider to 1 + _target->writeMemory(SYSMEMREMAP, 2); // User Flash Mode + } else { + _pc->printf("\nerror idcode=%08x\n", _target->idcode); + return false; + } + _pc->printf("passed.\n"); + return true; +} + bool Flash::write(const char* filename) { FILE* fp = fopen(filename, "rb"); @@ -25,11 +53,7 @@ uint8_t buf[256]; bool passed = false; for(int addr = 0; addr < 0x8000; addr += sizeof(buf)) { - if (feof(fp)) { - passed = true; - break; - } - fread(buf, sizeof(buf), 1, fp); + int ret = fread(buf, 1, sizeof(buf), fp); if (!_patch(buf, sizeof(buf), addr)) { break; } @@ -52,6 +76,10 @@ } } _pc->printf("."); + if (ret < sizeof(buf)) { + passed = true; + break; + } } fclose(fp); if (passed) {