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
Revision 12:2a7ca1f9619b, committed 2014-02-27
- Comitter:
- va009039
- Date:
- Thu Feb 27 14:35:22 2014 +0000
- Parent:
- 11:ad8af1047350
- Child:
- 13:6ff20f3c35dd
- Commit message:
- run on LPC11U35
Changed in this revision
--- a/USBMSD2/USB_CDC.h Sun Feb 23 12:06:02 2014 +0000 +++ b/USBMSD2/USB_CDC.h Thu Feb 27 14:35:22 2014 +0000 @@ -25,7 +25,7 @@ #define CDC_EPINT_IN EP1IN #define CDC_EPBULK_IN EP5IN #define CDC_EPBULK_OUT EP5OUT -#elif defined(TARGET_LPC1347)||defined(TARGET_LPC11U24) +#elif defined(TARGET_LPC1347)||defined(TARGET_LPC11U24)||defined(TARGET_LPC11U35_401) #define CDC_EPINT_IN EP1IN #define CDC_EPBULK_IN EP3IN #define CDC_EPBULK_OUT EP3OUT
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main_LPC11U35.cpp Thu Feb 27 14:35:22 2014 +0000 @@ -0,0 +1,85 @@ +// main_LPC11U35.cpp 2014/2/27 +#if defined(TARGET_LPC11U35_401) +#include "Target2.h" +#include "Flash.h" +#include "RamDisk.h" +#include "SDStorage.h" +#include "Storage.h" +#include "Semihost.h" + +#define USE_SD 1 + +Serial pc(P0_19,P0_18); // tx,rx +SWD swd(P0_8,P0_7,P0_2); // SWDIO,SWCLK,nReset +InterruptIn sw_isp(P0_1); +DigitalOut led_disk(P0_20); +DigitalOut led_flash(P0_21); +#define LED_ON 0 +#define LED_OFF 1 + +void callback_disk() { + led_disk = !led_disk; +} + +void callback_flash() { + led_flash = !led_flash; +} + +__IO bool write_start = false; +void swIRQ() { + wait_ms(500); + write_start = true; +} + +int main() { + pc.baud(9600); + pc.printf("%s\n", __FILE__); + led_disk = LED_OFF; + led_flash = LED_OFF; + + sw_isp.mode(PullUp); + sw_isp.fall(swIRQ); + +#if USE_SD + SDStorage* storage = new SDStorage(P1_15,P0_14,P0_23,P0_17); // mosi,miso,clk,cs + storage->storage_initialize(); +#else + RamDisk* storage = new RamDisk; +#endif + storage->attachEvent(callback_disk); + USBStorage2* usb = new USBStorage2(storage); + LocalStorage* local = NULL; + Target2* lpc = new Target2(&swd); + lpc->setup(); + Semihost semihost(lpc, &pc, usb); + semihost.mount("/local"); + lpc->resume(); // C_DEBUGEN ON + while(1) { + if (write_start) { + if (local) { + delete local; + } + local = new LocalStorage(storage); + mystring filename; + if (LocalStorage::find_bin(filename)) { + pc.printf("*** bin filename=[%s]\n", filename.c_str()); + lpc->setup(); + Flash flash(lpc, &pc); + flash.attachEvent(callback_flash); + if (flash.init()) { + flash.write(filename.c_str()); + flash.verify(filename.c_str()); + } + } else { + pc.printf("*** binary image file not found.\n"); + } + lpc->SoftwareReset(); + lpc->HardwareReset(); + led_flash = LED_OFF; + write_start = false; + } + semihost.poll(); + } +} +#endif // TARGET_LPC11U35_401 +
--- a/tests/mydebug.cpp Sun Feb 23 12:06:02 2014 +0000 +++ b/tests/mydebug.cpp Thu Feb 27 14:35:22 2014 +0000 @@ -18,11 +18,11 @@ void debug_dap_request(uint8_t* buf, int len) { - printf("uint8_t req[] = "); + debug("uint8_t req[] = "); for(int i = 0; i < len; i++) { - printf("%c0x%02x", i == 0 ? '{' : ',', buf[i]); + debug("%c0x%02x", i == 0 ? '{' : ',', buf[i]); } - printf("};\n"); + debug("};\n"); char* cmd; char* param = ""; char tmp[128]; @@ -76,7 +76,7 @@ case 0x0a: cmd = "ResetTarget"; break; case 0x10: cmd = "SWJ_Pins"; - snprintf(tmp, sizeof(tmp), "wait: %d us", buf[3]|buf[4]<<8|buf[5]<<16|buf[6]<<24); + //snprintf(tmp, sizeof(tmp), "wait: %d us", buf[3]|buf[4]<<8|buf[5]<<16|buf[6]<<24); if (buf[2] & 0x01) { strcat(tmp, " SWCLK_TCK "); strcat(tmp, (buf[1] & 0x01) ? "ON" : "OFF"); @@ -105,18 +105,18 @@ break; case 0x11: cmd = "SWJ_Clock"; - snprintf(tmp, sizeof(tmp), "%d Hz", buf[1]|buf[2]<<8|buf[3]<<16|buf[4]<<24); + //snprintf(tmp, sizeof(tmp), "%d Hz", buf[1]|buf[2]<<8|buf[3]<<16|buf[4]<<24); param = tmp; break; case 0x12: cmd = "SWJ_Sequence"; count = buf[1]; - snprintf(tmp, sizeof(tmp), "count: %d", count); + //snprintf(tmp, sizeof(tmp), "count: %d", count); param = tmp; break; case 0x13: cmd = "SWD_Configure"; - snprintf(tmp, sizeof(tmp), "turnaround: %d, data_phase: %d", (buf[1]&0x03)+1, (buf[1]&0x04) ? 1 : 0); + //snprintf(tmp, sizeof(tmp), "turnaround: %d, data_phase: %d", (buf[1]&0x03)+1, (buf[1]&0x04) ? 1 : 0); param = tmp; break; case 0x14: @@ -137,11 +137,11 @@ void debug_dap_response(uint8_t* buf, int len) { - printf("uint8_t res[] = "); + debug("uint8_t res[] = "); for(int i = 0; i < len; i++) { - printf("%c0x%02x", i == 0 ? '{' : ',', buf[i]); + debug("%c0x%02x", i == 0 ? '{' : ',', buf[i]); } - printf("};\n"); + debug("};\n"); } void debug_swd_transfer(uint8_t request, uint32_t wdata, uint32_t rdata, uint8_t ack)