semihost server example program

Dependencies:   SWD mbed USBLocalFileSystem BaseDAP USBDAP

/media/uploads/va009039/kl46z-lpc800-360x480.jpg

LPCXpresso
LPC11U68
LPCXpresso
LPC1549
FRDM-KL46ZEA LPC4088 QSB
app-board
LPC1768
app-board
LPC810LPC1114FN28
serverserverserverserverserverclientclient
SWDIOD12D12D12p25p21p4(P0_2)p12
SWCLKD10D10D10p26p22p3(P0_3)p3
nRESET
*option
D6D6D6p34p30p1(P0_5)p23
GNDGNDGNDGNDp1p1p7p22
3.3VP3V3P3V3P3V3p44p40p6p21
flash writeSW2(P0_1)SW3(P1_9)SW1p14
joystick
center
p14
joystick
center

client example:

Import programlpc810-semihost_helloworld

semihost client example program

Files at this revision

API Documentation at this revision

Comitter:
va009039
Date:
Sat Sep 14 12:55:29 2013 +0000
Parent:
4:5e4107edcbdb
Child:
6:5da6ad51a18f
Commit message:
deleted the code to access the data of unalignment.

Changed in this revision

Flash.cpp Show annotated file Show diff for this revision Revisions of this file
Flash.h Show annotated file Show diff for this revision Revisions of this file
SWD.cpp Show diff for this revision Revisions of this file
SWD.h Show diff for this revision Revisions of this file
SWD.lib Show annotated file Show diff for this revision Revisions of this file
Semihost.h Show annotated file Show diff for this revision Revisions of this file
Target2.cpp Show annotated file Show diff for this revision Revisions of this file
Target2.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
tests/BaseDAP.lib Show annotated file Show diff for this revision Revisions of this file
tests/DAP.cpp Show diff for this revision Revisions of this file
tests/DAP.h Show diff for this revision Revisions of this file
tests/TransferCore.cpp Show diff for this revision Revisions of this file
tests/TransferCore.h Show diff for this revision Revisions of this file
tests/USBDAP.cpp Show diff for this revision Revisions of this file
tests/USBDAP.h Show diff for this revision Revisions of this file
tests/USBDAP.lib Show annotated file Show diff for this revision Revisions of this file
tests/USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
tests/test1_BaseDAP.cpp Show annotated file Show diff for this revision Revisions of this file
tests/test1_DAP.cpp Show diff for this revision Revisions of this file
tests/test1_SWD.cpp Show annotated file Show diff for this revision Revisions of this file
tests/test1_Target2.cpp Show annotated file Show diff for this revision Revisions of this file
tests/test2_BaseDAP.cpp Show annotated file Show diff for this revision Revisions of this file
tests/test2_DAP.cpp Show diff for this revision Revisions of this file
tests/test2_Target2.cpp Show diff for this revision Revisions of this file
tests/test_Flash.cpp Show annotated file Show diff for this revision Revisions of this file
tests/test_Semihost.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Flash.cpp	Wed Sep 11 14:00:40 2013 +0000
+++ b/Flash.cpp	Sat Sep 14 12:55:29 2013 +0000
@@ -121,11 +121,16 @@
     return addr / 4096;
 }
 
+static uint32_t LD32(uint8_t* buf)
+{
+    return buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24;
+}
+
 bool Flash::_patch(uint8_t* buf, int size, int addr)
 {
     const int crp_start = 0x2fc; // Code Read Protection location
     if (crp_start >= addr && crp_start < addr+size) {
-        uint32_t pat = *reinterpret_cast<uint32_t*>(crp_start-addr+buf);
+        uint32_t pat = LD32(crp_start-addr+buf);
         if (pat != 0xffffffff) { // NO_CRP ?
             _pc->printf("\nCAUTION: CRP Pattern is not NO_CRP; %08x\n", pat);
             return false;
--- a/Flash.h	Wed Sep 11 14:00:40 2013 +0000
+++ b/Flash.h	Sat Sep 14 12:55:29 2013 +0000
@@ -1,9 +1,11 @@
-// Flash.h 2013/9/6
+// Flash.h 2013/9/14
 #pragma once
 #include "Target2.h"
 
 #define IAP_CCLK 12000
 
+/** Flash writer
+ */
 class Flash {
 public:
     Flash(Target2* target, Serial* usbpc);
--- a/SWD.cpp	Wed Sep 11 14:00:40 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,229 +0,0 @@
-// SWD.cpp 2013/9/11
-#include "SWD.h"
-#include <algorithm>
-#include "mydebug.h"
-
-SWD::SWD(PinName swdio, PinName swclk, PinName reset)
-    : _swdio(swdio), _swclk(swclk), _nreset(reset)
-{
-    conf.turnaround = 1;
-    conf.data_phase = 0;
-    idle_cycles = 0;
-    retry_count = 100;
-    
-    _cpu_delay_count = 2;
-    TransferAbort = false;
-}
-
-void SWD::Setup()
-{
-    _swclk = 1;
-    _swdio.output();
-    _swdio = 1;
-    _nreset.input();
-    _nreset.mode(PullUp);
-}
-
-void SWD::reset()
-{
-    SWJPins(0x00, 0x80);
-    SWJPins(0x80, 0x80);
-}
-
-void SWD::JTAG2SWD()
-{
-    const uint8_t data1[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff};
-    const uint8_t data2[] = {0x9e,0xe7};
-    const uint8_t data3[] = {0x00};
-    SWJSequence(sizeof(data1)*8, data1);
-    SWJSequence(sizeof(data2)*8, data2);
-    SWJSequence(sizeof(data1)*8, data1);
-    SWJSequence(sizeof(data3)*8, data3);
-}
-
-void SWD::SWJSequence(int count, const uint8_t* data)
-{
-    for(int n = 0; n < count; n++) {
-        uint8_t val = data[n/8];
-        write_bit(val>>(n%8));
-    }
-}
-
-uint8_t SWD::SWJPins(uint32_t value, uint32_t select ,int waittime_us)
-{
-    if (select & 0x01) { // swclk
-        _swclk = (value & 0x01) ? 1 : 0; 
-    }
-    if (select & 0x02) { // swdio
-        _swdio = (value & 0x02) ? 1 : 0;
-    }
-    if (select & 0x80) { // nReset
-        if (value & 0x80) {
-            _nreset.input();
-        } else {    
-            _nreset.output();
-            _nreset = 0;
-        }
-    }
-    if (waittime_us) {
-        waittime_us = std::min(waittime_us, 3000000);
-        Timer t;
-        t.reset();
-        t.start();
-        while(t.read_us() < waittime_us) {
-            if (select & 0x01) { // swclk
-                if (_swclk ^ ((value & 0x01) ? 1 : 0)) {
-                    continue;
-                } 
-            }
-            if (select & 0x02) { // swdio
-                if (_swdio ^ ((value & 0x02) ? 1 : 0)) {
-                    continue;
-                }
-            }
-            if (select & 0x80) { // nReset
-                if (_nreset ^ ((value & 0x80) ? 1 : 0)) {
-                    continue;
-                }
-            }
-            break;
-        }
-    }
-    return (_swclk ? 0x01 : 0x00) | (_swdio ? 0x02 : 0x00) | (_nreset ? 0x80 : 0x00);
-}
-
-void SWD::SWJClock(uint32_t clock_hz)
-{
-    uint32_t scc = SystemCoreClock;
-    _cpu_delay_count = scc / 2 / clock_hz / 3; 
-}
-
-void SWD::TransferConfigure(int _idle_cycles, int _retry_count)
-{
-    idle_cycles = _idle_cycles;
-    retry_count = _retry_count; 
-}
-
-void SWD::Configure(int turnaround, int data_phase)
-{
-    conf.turnaround = turnaround;
-    conf.data_phase = data_phase;
-}
-
-uint8_t SWD::Transfer(uint8_t request, uint32_t *data)
-{
-    for(int retry = retry_count; retry >= 0; retry--) {
-        uint8_t ack = rawTransfer(request, data);
-        if (ack != SWD_WAIT || TransferAbort) {
-            return ack;
-        }
-    }
-    return SWD_WAIT;
-}
-
-#pragma Otime
-
-static uint32_t calc_parity(uint32_t data, int n)
-{
-    uint32_t parity = 0;
-    for(int i = 0; i < n; i++) {
-        parity += data>>i;
-    }
-    return parity & 1;
-}
-
-uint8_t SWD::rawTransfer(uint8_t request, uint32_t *data)
-{
-    write_bit(1);          // start bit
-    write_bit(request, 4); // APnDP,RnW,A2,A3
-    write_bit(calc_parity(request, 4)); // parity bit
-    write_bit(0);       // stop bit
-    write_bit(1);       // park bit
-    
-    _swdio.input();
-    clock_cycle(conf.turnaround);
-    
-    uint8_t ack = read_bit(3);
-    if (ack == SWD_OK) {
-        if (request & SWD_RnW) { // read
-            uint32_t val = read_bit(32);
-            uint32_t parity = read_bit(1);
-            if (parity ^ calc_parity(val, 32)) {
-                ack = SWD_ERROR;
-            }
-            if (data) {
-                *data = val;
-            }
-            clock_cycle(conf.turnaround);
-            _swdio.output();
-        } else {                        // write
-            clock_cycle(conf.turnaround);
-            _swdio.output();
-            uint32_t val = *data;
-            write_bit(val, 32);
-            write_bit(calc_parity(val, 32));
-        }
-        if (idle_cycles) {
-            _swdio = 0;
-            clock_cycle(idle_cycles);
-        }
-        _swdio = 1;
-        return ack;
-    }
-
-    if (ack == SWD_WAIT || ack == SWD_FAULT) {
-        if (conf.data_phase && (request & SWD_RnW)) {
-            clock_cycle(32+1);
-        }
-        clock_cycle(conf.turnaround);
-        _swdio.output();
-        if (conf.data_phase && ((request & SWD_RnW) == 0)) {
-            _swdio = 0;
-            clock_cycle(32+1);
-        }
-        _swdio = 1;
-        return ack;
-    }
-    clock_cycle(32 + 1 + conf.turnaround);
-    _swdio.output();
-    return ack;
-}
-
-void SWD::pin_delay()
-{
-    __IO int n = _cpu_delay_count;
-    while(n-- > 0)
-        ;
-}
-
-void SWD::clock_cycle(int n)
-{
-    while(n-- > 0) {
-        _swclk = 0;
-        pin_delay();
-        _swclk = 1;
-        pin_delay();
-    }    
-}
-
-void SWD::write_bit(uint32_t data, int n)
-{
-    for(int i = 0; i < n; i++) {
-        _swdio = (data>>i) & 1;
-        clock_cycle();
-    }
-}
-
-uint32_t SWD::read_bit(int n)
-{
-    uint32_t data = 0;
-    for(int i = 0; i < n; i++) {
-        _swclk = 0;
-        pin_delay();
-        uint32_t val = _swdio & 1;
-        data |= val<<i;
-        _swclk = 1;
-        pin_delay();
-    }    
-    return data;
-}
--- a/SWD.h	Wed Sep 11 14:00:40 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-// SWD.h 2013/9/8
-#pragma once
-#include "mbed.h"
-
-#define SWD_OK     0x01
-#define SWD_WAIT   0x02
-#define SWD_FAULT  0x04
-#define SWD_ERROR  0x08
-
-#define SWD_APnDP  0x01
-#define SWD_RnW    0x02
-
-#define DP_ABORT       0<<0|0<<1|0x00
-#define DP_IDCODE      0<<0|1<<1|0x00
-#define DP_CTRL_STAT   0<<0|0<<1|0x04
-#define DP_CTRL_STAT_R 0<<0|1<<1|0x04
-#define DP_SELECT      0<<0|0<<1|0x08
-#define DP_RDBUFF      0<<0|1<<1|0x0c
-
-#define AP_CSW         1<<0|0<<1|0x00
-#define AP_CSW_R       1<<0|1<<1|0x00
-#define AP_TAR         1<<0|0<<1|0x04
-#define AP_TAR_R       1<<0|1<<1|0x04
-#define AP_DRW_W       1<<0|0<<1|0x0c
-#define AP_DRW_R       1<<0|1<<1|0x0c
-
-#define CSYSPWRUPACK 0x80000000
-#define CDBGPWRUPACK 0x20000000
-#define CSYSPWRUPREQ 0x40000000
-#define CDBGPWRUPREQ 0x10000000
-
-#define TRNNORMAL    0x00000000
-#define MASKLANE     0x00000f00
-
-// AP Control and Status Word definitions
-#define CSW_SIZE     0x00000007
-#define CSW_SIZE8    0x00000000
-#define CSW_SIZE16   0x00000001
-#define CSW_SIZE32   0x00000002
-#define CSW_ADDRINC  0x00000030
-#define CSW_NADDRINC 0x00000000
-#define CSW_SADDRINC 0x00000010
-#define CSW_PADDRINC 0x00000020
-#define CSW_DBGSTAT  0x00000040
-#define CSW_TINPROG  0x00000080
-#define CSW_HPROT    0x02000000
-#define CSW_MSTRTYPE 0x20000000
-#define CSW_MSTRCORE 0x00000000
-#define CSW_MSTRDBG  0x20000000
-#define CSW_RESERVED 0x01000000
-
-#define CSW_VALUE  (CSW_RESERVED | CSW_MSTRDBG | CSW_HPROT | CSW_DBGSTAT | CSW_SADDRINC)
-
-class SWD {
-public:
-    SWD(PinName swdio, PinName swclk, PinName reset);
-    void Setup();
-    void SWJSequence(int count, const uint8_t* data);
-    uint8_t SWJPins(uint32_t value, uint32_t select ,int waittime_us = 0);
-    void SWJClock(uint32_t clock_hz);
-    void TransferConfigure(int idle_cycles, int retry_count);
-    void Configure(int turnaround, int data_phase);
-    void JTAG2SWD();
-    uint8_t Transfer(uint8_t request, uint32_t *data);
-    __IO bool TransferAbort;
-    void reset();
-private:
-    uint8_t rawTransfer(uint8_t request, uint32_t *data);
-    void pin_delay();
-    void clock_cycle(int n = 1);
-    void write_bit(uint32_t data, int n = 1);
-    uint32_t read_bit(int n = 1);
-protected:
-    struct {
-        int turnaround;
-        int data_phase;
-    } conf;
-    int idle_cycles;
-    int retry_count;
-    int _cpu_delay_count;
-    DigitalInOut _swdio;
-    DigitalOut _swclk;
-    DigitalInOut _nreset;
-};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SWD.lib	Sat Sep 14 12:55:29 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/va009039/code/SWD/#86fde86e144f
--- a/Semihost.h	Wed Sep 11 14:00:40 2013 +0000
+++ b/Semihost.h	Sat Sep 14 12:55:29 2013 +0000
@@ -1,8 +1,10 @@
-// Semihost.h 2013/9/4
+// Semihost.h 2013/9/14
 #pragma once
 #include "Target2.h"
 #include "mydebug.h"
 
+/** Semihosting
+ */
 class Semihost {
 public:
     Semihost(Target2* target, Serial* usbpc);
@@ -42,21 +44,21 @@
     template<typename T>
     void wr(uint32_t addr, T data) {
         TEST_ASSERT(addr <= 0x10001fff);
-        uint8_t buf[sizeof(T)];
-        *reinterpret_cast<T*>(buf) = data;
         for(int i = 0; i < sizeof(T); i++) {
-            _target->writeMemory8(addr+i, buf[i]);
+            _target->writeMemory8(addr+i, data);
+            data >>= 8;
         }
     }
 
     template<typename T>
     T rd(uint32_t addr) {
         TEST_ASSERT(addr <= 0x10001fff);
-        uint8_t buf[sizeof(T)];
-        for(int i = 0; i < sizeof(T); i++) {
-            buf[i] = _target->readMemory8(addr+i);
+        T data = 0;
+        for(int i = sizeof(T)-1; i >= 0; i--) {
+            data <<= 8;
+            data |= _target->readMemory8(addr+i);
         }
-        return *reinterpret_cast<T*>(buf);
+        return data;
     }
  
 protected:
--- a/Target2.cpp	Wed Sep 11 14:00:40 2013 +0000
+++ b/Target2.cpp	Sat Sep 14 12:55:29 2013 +0000
@@ -1,4 +1,4 @@
-// Target2.cpp 2013/9/11
+// Target2.cpp 2013/9/14
 #include "Target2.h"
 #include "mydebug.h"
 
@@ -17,8 +17,8 @@
 #define FP_CTRL_KEY (1 << 1)
 #define FP_COMP0 (0xE0002008)
 
-Target2::Target2(PinName swdio, PinName swclk, PinName reset, Serial* usbpc)
-    : _swd(swdio, swclk, reset), _pc(usbpc)
+Target2::Target2(PinName swdio, PinName swclk, PinName reset)
+    : _swd(swdio, swclk, reset)
 {
     r0.setup(this, 0);
     r1.setup(this, 1);
@@ -42,7 +42,7 @@
 bool Target2::setup()
 {
     _swd.Setup();
-    _swd.JTAG2SWD();
+    JTAG2SWD();
     
     uint32_t data;
     uint8_t ack = _swd.Transfer(DP_IDCODE, &data);
@@ -119,6 +119,17 @@
     return true;
 }
 
+void Target2::JTAG2SWD()
+{
+    const uint8_t data1[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff};
+    const uint8_t data2[] = {0x9e,0xe7};
+    const uint8_t data3[] = {0x00};
+    _swd.SWJSequence(sizeof(data1)*8, data1);
+    _swd.SWJSequence(sizeof(data2)*8, data2);
+    _swd.SWJSequence(sizeof(data1)*8, data1);
+    _swd.SWJSequence(sizeof(data3)*8, data3);
+}
+
 void Target2::HardwareReset()
 {
     _swd.SWJPins(0x00, 0x80); // nReset off
--- a/Target2.h	Wed Sep 11 14:00:40 2013 +0000
+++ b/Target2.h	Sat Sep 14 12:55:29 2013 +0000
@@ -1,4 +1,4 @@
-// Target2.h 2013/9/8
+// Target2.h 2013/9/14
 #pragma once
 #include "mbed.h"
 #include "SWD.h"
@@ -31,9 +31,16 @@
     uint8_t _reg;    
 };
 
+/** Target MCU interface
+ */
 class Target2 {
 public:
-    Target2(PinName swdio, PinName swclk, PinName reset, Serial* usbpc);
+    /** create target MCU interface
+     * @param swdio SWD(swdio) pin
+     * @param swclk SWD(swclk) pin
+     * @param reset reset pin
+     */
+    Target2(PinName swdio, PinName swclk, PinName reset);
     bool setup();
     uint32_t readMemory(uint32_t addr);
     void readMemory(uint32_t addr, uint32_t* data, int count);
@@ -71,10 +78,10 @@
     CoreReg xpsr;
     
     uint32_t idcode;
-private:
+protected:
     void _setaddr(uint32_t addr); 
     void _setaddr8(uint32_t addr); 
-protected:
+    void JTAG2SWD();
+
     SWD _swd;
-    Serial* _pc;
 };
--- a/main.cpp	Wed Sep 11 14:00:40 2013 +0000
+++ b/main.cpp	Sat Sep 14 12:55:29 2013 +0000
@@ -1,4 +1,4 @@
-// main.cpp 2013/9/11
+// main.cpp 2013/9/14
 #if 1
 #include "Target2.h"
 #include "Flash.h"
@@ -36,7 +36,7 @@
     const char* filename = "/local/1114FN28.LPC";
     pc.printf("%s\n", filename);
     
-    Target2* LPC1114 = new Target2(p21,p22,p17, &pc); // SWDIO(dp12),SWCLK(dp3),nReset(dp23),Stream
+    Target2* LPC1114 = new Target2(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
     LPC1114->setup();
     Flash flash(LPC1114, &pc);
     flash.init();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/BaseDAP.lib	Sat Sep 14 12:55:29 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/va009039/code/BaseDAP/#76588be01e71
--- a/tests/DAP.cpp	Wed Sep 11 14:00:40 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,201 +0,0 @@
-// DAP.cpp 2013/9/9
-#include "DAP.h"
-
-DAP::DAP(SWD* swd) : _swd(swd)
-{
-}
-
-int DAP::Command(uint8_t* request, uint8_t* response)
-{
-    switch(*request) {
-        case 0x00: return Info(request, response);
-        case 0x01: return LED(request, response); 
-        case 0x02: return Connect(request, response); 
-        case 0x03: return Disconnect(request, response);
-        case 0x04: return TransferConfigure(request, response);
-        case 0x05: return Transfer(request, response);
-        case 0x06: return TransferBlock(request, response);
-
-        case 0x08: return WriteABORT(request, response);
-    
-        case 0x10: return SWJ_Pins(request, response);
-        case 0x11: return SWJ_Clock(request, response);
-        case 0x12: return SWJ_Sequence(request, response);
-        case 0x13: return SWD_Configure(request, response);
-        
-        case 0x80: return Vendor0(request, response);
-
-    };
-    *response = 0xff; // invalid
-    return 1;    
-}
-
-int DAP::Info(uint8_t* request, uint8_t* response) // 0x00
-{
-    const char* info_str[] = {
-        NULL,     // 1 VENDOR
-        NULL,     // 2 PRODUCT
-        NULL,     // 3 SER_NUM
-        "1.0",    // 4 FW_VER
-        NULL,     // 5 DEVICE_VENDOR
-        NULL,     // 6 DEVICE_NAME
-    };
-    const char* s;
-    int slen;
-    response[0] = 0x00; // Info
-    int length = 2;
-    int id = request[1];
-    switch(id) {
-        case 1 ... 6: // VENDOR PRODUCT SER_NUM FW_VER DEVICE_VENDOR DEVICE_NAME
-            slen = 0;
-            s = info_str[id-1];
-            if (s) {     
-                slen = strlen(s) + 1;
-                memcpy(response+2, s, slen);
-            }
-            response[1] = slen;    
-            length += slen;
-            break;
-        case 0xf0:          // CAPABILITIES
-            response[1] = sizeof(uint8_t);
-            response[2] = 0x01; // SWD
-            length += sizeof(uint8_t);
-            break;
-        case 0xfe:          // PACKET_COUNT
-            response[1] = sizeof(uint8_t);
-            response[2] = 1;
-            length += sizeof(uint8_t);
-            break;
-        case 0xff:          // PACKET_SIZE
-            response[1] = sizeof(uint16_t);
-            *reinterpret_cast<uint16_t*>(response+2) = 64;
-            length += sizeof(uint16_t);
-            break;
-        default:
-            response[1] = DAP_ERROR;
-            break;
-    }
-    return length;
-}
-
-int DAP::LED(uint8_t* request, uint8_t* response) // 0x01
-{
-    response[0] = 0x01; // LED
-    response[1] = DAP_OK;
-    return 2;
-}
-   
-int DAP::Connect(uint8_t* request, uint8_t* response) // 0x02
-{
-    response[0] = 0x02; // Connect
-    response[1] = DAP_PORT_DISABLED;
-    if (request[1] == DAP_PORT_AUTODETECT || request[1] == DAP_PORT_SWD) {
-        response[1] = DAP_PORT_SWD;
-        _swd->Setup();
-    }
-    return 2;
-}
-
-int DAP::Disconnect(uint8_t* request, uint8_t* response) // 0x03
-{
-    response[0] = 0x03; // disconnect
-    response[1] = DAP_OK;
-    return 2;
-}
-
-int DAP::TransferConfigure(uint8_t* request, uint8_t* response) // 0x04
-{
-    uint8_t idle_cycles = request[1];
-    uint16_t retry_count = *reinterpret_cast<uint16_t*>(request+2);
-    transfer.match_retry = *reinterpret_cast<uint16_t*>(request+4);
-    _swd->TransferConfigure(idle_cycles, retry_count);
-    response[0] = 0x04; //tansfer configure
-    response[1] = DAP_OK;
-    return 2;
-}
-
-int DAP::Transfer(uint8_t* request, uint8_t* response) // 0x05
-{
-    return transfer.Transfer(_swd, request, response);
-}
-
-int DAP::TransferBlock(uint8_t* request, uint8_t* response) // 0x06
-{
-    return transfer.TransferBlock(_swd, request, response);
-}
-
-int DAP::WriteABORT(uint8_t* request, uint8_t* response) // 0x08
-{
-    uint32_t data = *reinterpret_cast<uint32_t*>(request+2);
-    uint8_t ack = _swd->Transfer(DP_ABORT, &data);
-    response[0] = 0x08; // write abort
-    response[1] = ack == SWD_OK ? DAP_OK : DAP_ERROR;
-    return 2;
-}
-
-int DAP::Delay(uint8_t* request, uint8_t* response) // 0x09
-{
-    int waittime_ms = *reinterpret_cast<uint16_t*>(request+1);
-    wait_ms(waittime_ms);
-    response[0] = 0x09;
-    response[1] = DAP_OK;
-    return 2;
-}
-
-int DAP::ResetTarget(uint8_t* request, uint8_t* response) // 0x0A
-{
-    response[0] = 0x0a;
-    response[1] = 0;
-    response[2] = DAP_OK;
-    return 3;
-}
-
-int DAP::SWJ_Pins(uint8_t* request, uint8_t* response) // 0x10
-{
-    uint32_t value = request[1];
-    uint32_t select = request[2];
-    uint32_t waittime_us = *reinterpret_cast<uint32_t*>(request+3);
-    response[0] = 0x10; // swj pins
-    response[1] = _swd->SWJPins(value, select, waittime_us);
-    return 2;    
-}
-
-int DAP::SWJ_Clock(uint8_t* request, uint8_t* response) // 0x11
-{
-    uint32_t clock = *reinterpret_cast<uint32_t*>(request+1);
-    _swd->SWJClock(clock);
-    response[0] = 0x11; // swj clock
-    response[1] = DAP_OK;
-    return 2;
-}
-
-int DAP::SWJ_Sequence(uint8_t* request, uint8_t* response) // 0x12
-{
-    int count = request[1];
-    if (count == 0) {
-        count = 256;
-    }
-    _swd->SWJSequence(count, request+2);
-    response[0] = 0x12; // swj sequence
-    response[1] = DAP_OK;
-    return 2;
-}
-
-int DAP::SWD_Configure(uint8_t* request, uint8_t* response) // 0x13
-{
-    uint8_t cfg = request[1];
-    _swd->Configure((cfg&0x03)+1, cfg&0x04 ? 1: 0); 
-    response[0] = 0x13; // swd configure
-    response[1] = DAP_OK;
-    return 2;
-}
-
-int DAP::Vendor0(uint8_t* request, uint8_t* response) // 0x80
-{
-    const char* board_id = "1040123456789"; // lpc11u24
-    int len = strlen(board_id);
-    response[0] = 0x80;
-    response[1] = len;
-    memcpy(response+2, board_id, len);  
-    return len + 1;
-}
--- a/tests/DAP.h	Wed Sep 11 14:00:40 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-// DAP.h 2013/9/9
-#pragma once
-#include "SWD.h"
-#include "TransferCore.h"
-
-// DAP Status Code
-#define DAP_OK                          0
-#define DAP_ERROR                       0xFF
-
-// DAP Port
-#define DAP_PORT_AUTODETECT             0       // Autodetect Port
-#define DAP_PORT_DISABLED               0       // Port Disabled (I/O pins in High-Z)
-#define DAP_PORT_SWD                    1       // SWD Port (SWCLK, SWDIO) + nRESET
-
-class DAP {
-public:
-    DAP(SWD* swd);
-    int Command(uint8_t* request, uint8_t* response);
-private:    
-    int Info(uint8_t* request, uint8_t* response);          // 0x00
-    int LED(uint8_t* request, uint8_t* response);           // 0x01
-    int Connect(uint8_t* request, uint8_t* response);       // 0x02
-    int Disconnect(uint8_t* request, uint8_t* response);    // 0x03
-    int TransferConfigure(uint8_t* request, uint8_t* response);// 0x04
-    int Transfer(uint8_t* request, uint8_t* response);      // 0x05
-    int TransferBlock(uint8_t* request, uint8_t* response); // 0x06
-
-    int WriteABORT(uint8_t* request, uint8_t* response);    // 0x08
-    int Delay(uint8_t* request, uint8_t* response);         // 0x09
-    int ResetTarget(uint8_t* request, uint8_t* response);   // 0x0A
-    int SWJ_Pins(uint8_t* request, uint8_t* response);      // 0x10
-    int SWJ_Clock(uint8_t* request, uint8_t* response);     // 0x11
-    int SWJ_Sequence(uint8_t* request, uint8_t* response);  // 0x12
-    int SWD_Configure(uint8_t* request, uint8_t* response); // 0x13
-    
-    int Vendor0(uint8_t* request, uint8_t* response); // 0x80
-protected:
-    TransferCore transfer;
-    SWD* _swd;
-};
--- a/tests/TransferCore.cpp	Wed Sep 11 14:00:40 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,184 +0,0 @@
-// TransferCore.cpp 2013/9/10
-#include "TransferCore.h"
-
-void transData::init(uint8_t* base, int pos)
-{
-    _base = base;
-    _pos = pos;
-}
-
-void transData::append(uint32_t data)
-{
-    *reinterpret_cast<uint32_t*>(_base+_pos) = data;
-    _pos += sizeof(uint32_t);
-}
-
-uint8_t* transData::data()
-{
-    return _base;
-}
-
-int transData::length()
-{
-    return _pos;
-}
-
-int TransferCore::Transfer(SWD* swd, uint8_t* request, uint8_t* response) // 0x05
-{
-    _swd = swd;
-    reqData.init(request, 2);
-    resData.init(response, 3);
-    post_read = check_write = false;
-    response_count = 0;
-    uint8_t ack = 0;
-    for(int count = reqData.get<uint8_t>(); count > 0; count--) {
-        uint8_t cmd = reqData.get<uint8_t>();
-        if (cmd & SWD_RnW) { // read register
-            ack = read(cmd);
-            check_write = false;
-        } else { // write register
-            ack = write(cmd);
-        }
-        if (ack != SWD_OK) {
-            break;
-        }
-        response_count++;
-    }
-    if (ack == SWD_OK) {
-        if (post_read) { // read previous data
-            uint32_t data;
-            ack = _swd->Transfer(DP_RDBUFF, &data);
-            resData.append(data);
-        } else if (check_write) { // check last write
-            ack = _swd->Transfer(DP_RDBUFF, NULL);
-        }
-    }
-    resData.data()[0] = 0x05; // transfer
-    resData.data()[1] = response_count;
-    resData.data()[2] = ack;
-    return resData.length();
-}
-
-uint8_t TransferCore::read(uint8_t cmd)
-{
-    uint8_t ack = 0;
-    uint32_t data;
-    if (post_read) {
-        if ((cmd & SWD_APnDP) && !(cmd & DAP_TRANSFER_MATCH_VALUE)) {
-            ack = _swd->Transfer(cmd, &data); // next post_read
-        } else {
-            ack = _swd->Transfer(DP_RDBUFF, &data);
-            post_read = false;
-        }
-        if (ack != SWD_OK) {
-            return ack;
-        }
-        resData.append(data);
-    }
-    if (cmd & DAP_TRANSFER_MATCH_VALUE) {
-        uint32_t match_value = reqData.get<uint32_t>();
-        if (cmd & SWD_APnDP) {
-            ack = _swd->Transfer(cmd, NULL);
-            if (ack != SWD_OK) {
-                return ack;
-            }
-        }
-        for(int retry = match_retry; retry >= 0; retry--) {
-            ack = _swd->Transfer(cmd, &data);
-            if (ack == SWD_OK && (data&match_mask) == match_value) {
-                return ack;
-            }
-        }
-        return ack | DAP_TRANSFER_MISMATCH; 
-    } else {
-        if (cmd & SWD_APnDP) {
-            if (post_read == false) {
-                ack = _swd->Transfer(cmd, NULL);
-                post_read = true;
-            }
-        } else {
-            ack = _swd->Transfer(cmd, &data);
-            resData.append(data);
-        }    
-    }
-    return ack;
-}
-
-uint8_t TransferCore::write(uint8_t cmd)
-{
-    if (post_read) { // read previous data
-        uint32_t data;
-        uint8_t ack = _swd->Transfer(DP_RDBUFF, &data);
-        if (ack != SWD_OK) {
-            return ack;
-        }
-        resData.append(data);
-        post_read = false;
-    }    
-    if (cmd & DAP_TRANSFER_MATCH_MASK) {
-        match_mask = reqData.get<uint32_t>();
-        return SWD_OK;
-    }
-    check_write = true;
-    uint32_t data = reqData.get<uint32_t>();
-    return _swd->Transfer(cmd, &data);
-}
-
-int TransferCore::TransferBlock(SWD* swd, uint8_t* request, uint8_t* response)
-{
-    _swd = swd;
-    reqData.init(request, 2);
-    resData.init(response, 4);
-    uint8_t ack = 0;
-    response_count = 0;
-    int count = reqData.get<uint16_t>();
-    if (count > 0) {
-        uint8_t cmd = reqData.get<uint8_t>();
-        if (cmd & SWD_RnW) { // read register block
-            ack = read_block(cmd, count);
-        } else { // write register block
-            ack = write_block(cmd, count);
-        }
-    }
-    resData.data()[0] = 0x06; // transfer block
-    *reinterpret_cast<uint16_t*>(resData.data()+1) = response_count;
-    resData.data()[3] = ack;    
-    return resData.length(); 
-}
-
-uint8_t TransferCore::read_block(uint8_t cmd, int count)
-{
-    if (cmd & SWD_APnDP) { // post AP read
-        uint8_t ack = _swd->Transfer(cmd, NULL);
-        if (ack != SWD_OK) {
-            return ack;
-        }
-    }
-    uint8_t ack = 0;
-    while(count-- > 0) { // read DP/AP register
-        if (count == 0 && (cmd & SWD_APnDP)) { // last AP read
-            cmd = DP_RDBUFF;
-        }
-        uint32_t data;
-        ack = _swd->Transfer(cmd, &data);
-        if (ack != SWD_OK) {
-            break;
-        }
-        resData.append(data);
-        response_count++;
-    }
-    return ack;
-}
-
-uint8_t TransferCore::write_block(uint8_t cmd, int count)
-{
-    while(count-- > 0) {
-        uint32_t data = reqData.get<uint32_t>();
-        uint8_t ack = _swd->Transfer(cmd, &data);
-        if (ack != SWD_OK) {
-            return ack;
-        }
-        response_count++;
-    }
-    return _swd->Transfer(DP_RDBUFF, NULL);
-}
--- a/tests/TransferCore.h	Wed Sep 11 14:00:40 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-// TransferCore.h 2013/9/10
-#pragma once
-#include "SWD.h"
-
-// DAP Transfer Request
-#define DAP_TRANSFER_MATCH_VALUE        (1<<4)
-#define DAP_TRANSFER_MATCH_MASK         (1<<5)
-
-// DAP Transfer Response
-#define DAP_TRANSFER_MISMATCH           (1<<4)
-
-class transData {
-public:
-    void init(uint8_t* base, int pos);
-    void append(uint32_t data);
-    uint8_t* data();
-    int length();
-
-    template<typename T>
-    T get() {
-        T data = *reinterpret_cast<T*>(_base+_pos);
-        _pos += sizeof(T);
-        return data;
-    }
-protected:
-    uint8_t* _base;
-    int _pos;
-};
-
-class TransferCore {
-public:
-    int Transfer(SWD* swd, uint8_t* request, uint8_t* response);
-    int TransferBlock(SWD* swd, uint8_t* request, uint8_t* response);
-    uint16_t  match_retry; // Number of retries if read value does not match
-    uint32_t  match_mask;  // Match Mask
-private:
-    uint8_t read(uint8_t cmd);
-    uint8_t write(uint8_t cmd);
-    uint8_t read_block(uint8_t cmd, int count);
-    uint8_t write_block(uint8_t cmd, int count);
-
-    bool post_read;
-    bool check_write;
-    transData reqData;  
-    transData resData;
-    int response_count;
-protected:
-    SWD* _swd;
-};
--- a/tests/USBDAP.cpp	Wed Sep 11 14:00:40 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,272 +0,0 @@
-/* Copyright (c) 2010-2011 mbed.org, MIT License
-*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
-* and associated documentation files (the "Software"), to deal in the Software without
-* restriction, including without limitation the rights to use, copy, modify, merge, publish,
-* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included in all copies or
-* substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
-* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "stdint.h"
-#include "USBHAL.h"
-#include "USBDAP.h"
-
-
-USBDAP::USBDAP(uint8_t output_report_length, uint8_t input_report_length, uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect): USBDevice(vendor_id, product_id, product_release)
-{
-    output_length = output_report_length;
-    input_length = input_report_length;
-    if(connect) {
-        USBDevice::connect();
-    }
-}
-
-
-bool USBDAP::send(HID_REPORT *report)
-{
-    return write(EPINT_IN, report->data, report->length, MAX_HID_REPORT_SIZE);
-}
-
-bool USBDAP::sendNB(HID_REPORT *report)
-{
-    return writeNB(EPINT_IN, report->data, report->length, MAX_HID_REPORT_SIZE);
-}
-
-
-bool USBDAP::read(HID_REPORT *report)
-{
-    uint32_t bytesRead = 0;
-    bool result;
-    result = USBDevice::readEP(EPINT_OUT, report->data, &bytesRead, MAX_HID_REPORT_SIZE);
-    if(!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
-        return false;
-    report->length = bytesRead;
-    return result;
-}
-
-
-bool USBDAP::readNB(HID_REPORT *report)
-{
-    uint32_t bytesRead = 0;
-    bool result;
-    result = USBDevice::readEP_NB(EPINT_OUT, report->data, &bytesRead, MAX_HID_REPORT_SIZE);
-    report->length = bytesRead;
-    if(!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
-        return false;
-    return result;
-}
-
-
-uint16_t USBDAP::reportDescLength() {
-    reportDesc();
-    return reportLength;
-}
-
-
-
-//
-//  Route callbacks from lower layers to class(es)
-//
-
-
-// Called in ISR context
-// Called by USBDevice on Endpoint0 request
-// This is used to handle extensions to standard requests
-// and class specific requests
-// Return true if class handles this request
-bool USBDAP::USBCallback_request() {
-    bool success = false;
-    CONTROL_TRANSFER * transfer = getTransferPtr();
-    uint8_t *hidDescriptor;
-
-    // Process additional standard requests
-
-    if ((transfer->setup.bmRequestType.Type == STANDARD_TYPE))
-    {
-        switch (transfer->setup.bRequest)
-        {
-            case GET_DESCRIPTOR:
-                switch (DESCRIPTOR_TYPE(transfer->setup.wValue))
-                {
-                    case REPORT_DESCRIPTOR:
-                        if ((reportDesc() != NULL) \
-                            && (reportDescLength() != 0))
-                        {
-                            transfer->remaining = reportDescLength();
-                            transfer->ptr = reportDesc();
-                            transfer->direction = DEVICE_TO_HOST;
-                            success = true;
-                        }
-                        break;
-                    case HID_DESCRIPTOR:
-                            // Find the HID descriptor, after the configuration descriptor
-                            hidDescriptor = findDescriptor(HID_DESCRIPTOR);
-                            if (hidDescriptor != NULL)
-                            {
-                                transfer->remaining = HID_DESCRIPTOR_LENGTH;
-                                transfer->ptr = hidDescriptor;
-                                transfer->direction = DEVICE_TO_HOST;
-                                success = true;
-                            }
-                            break;
-                     
-                    default:
-                        break;
-                }
-                break;
-            default:
-                break;
-        }
-    }
-
-    // Process class-specific requests
-
-    if (transfer->setup.bmRequestType.Type == CLASS_TYPE)
-    {
-        switch (transfer->setup.bRequest)
-        {
-             case SET_REPORT:
-                // First byte will be used for report ID
-                outputReport.data[0] = transfer->setup.wValue & 0xff;
-                outputReport.length = transfer->setup.wLength + 1;
-
-                transfer->remaining = sizeof(outputReport.data) - 1;
-                transfer->ptr = &outputReport.data[1];
-                transfer->direction = HOST_TO_DEVICE;
-                transfer->notify = true;
-                success = true;
-            default:
-                break;
-        }
-    }
-
-    return success;
-}
-
-
-#define DEFAULT_CONFIGURATION (1)
-
-
-// Called in ISR context
-// Set configuration. Return false if the
-// configuration is not supported
-bool USBDAP::USBCallback_setConfiguration(uint8_t configuration) {
-    if (configuration != DEFAULT_CONFIGURATION) {
-        return false;
-    }
-
-    // Configure endpoints > 0
-    addEndpoint(EPINT_IN, MAX_PACKET_SIZE_EPINT);
-    addEndpoint(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
-
-    // We activate the endpoint to be able to recceive data
-    readStart(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
-    return true;
-}
-
-
-uint8_t * USBDAP::stringIinterfaceDesc() {
-    static uint8_t stringIinterfaceDescriptor[] = {
-        0x08,               //bLength
-        STRING_DESCRIPTOR,  //bDescriptorType 0x03
-        'H',0,'I',0,'D',0,  //bString iInterface - HID
-    };
-    return stringIinterfaceDescriptor;
-}
-
-uint8_t * USBDAP::stringIproductDesc() {
-    static uint8_t stringIproductDescriptor[] = {
-        32,                                                       //bLength
-        STRING_DESCRIPTOR,                                        //bDescriptorType 0x03
-        'K',0,'L',0,'2',0,'5',0,'Z',0,' ',0,'C',0,'M',0,'S',0,'I',0,'S',0,'-',0,'D',0,'A',0,'P',0 // KL25Z CMSIs-DAP
-    };
-    return stringIproductDescriptor;
-}
-
-uint8_t * USBDAP::reportDesc() {
-    static uint8_t reportDescriptor[] = {
-        0x06, 0x00, 0xff,
-        0x09, 0x01,         // usage
-        0xA1, 0x01,         // Collection 0x01
-        0x15, 0x00,         // logical minimum = 0
-        0x26, 0xFF, 0x00,   // logical maximum = 255
-        0x75, 0x08,         // report size = 8 bits
-        0x95, 0x40,         // report count
-        0x09, 0x01,         // usage
-        0x81, 0x02,         // Input (array)
-        0x95, 0x40,         // report count
-        0x09, 0x01,         // usage
-        0x91, 0x02,         // Output (array)
-        0x95, 0x01,         // report count
-        0x09, 0x01,         // usage
-        0xb1, 0x02,
-        0xC0                // end collection
-    };
-    reportLength = sizeof(reportDescriptor);
-    return reportDescriptor;
-}
-
-#define DEFAULT_CONFIGURATION (1)
-#define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \
-                               + (1 * INTERFACE_DESCRIPTOR_LENGTH) \
-                               + (1 * HID_DESCRIPTOR_LENGTH) \
-                               + (2 * ENDPOINT_DESCRIPTOR_LENGTH))
-
-uint8_t * USBDAP::configurationDesc() {
-    static uint8_t configurationDescriptor[] = {
-        CONFIGURATION_DESCRIPTOR_LENGTH,// bLength
-        CONFIGURATION_DESCRIPTOR,       // bDescriptorType
-        LSB(TOTAL_DESCRIPTOR_LENGTH),   // wTotalLength (LSB)
-        MSB(TOTAL_DESCRIPTOR_LENGTH),   // wTotalLength (MSB)
-        0x01,                           // bNumInterfaces
-        DEFAULT_CONFIGURATION,          // bConfigurationValue
-        0x00,                           // iConfiguration
-        C_RESERVED | C_SELF_POWERED,    // bmAttributes
-        C_POWER(0),                     // bMaxPower
-
-        INTERFACE_DESCRIPTOR_LENGTH,    // bLength
-        INTERFACE_DESCRIPTOR,           // bDescriptorType
-        0x00,                           // bInterfaceNumber
-        0x00,                           // bAlternateSetting
-        0x02,                           // bNumEndpoints
-        HID_CLASS,                      // bInterfaceClass
-        HID_SUBCLASS_NONE,              // bInterfaceSubClass
-        HID_PROTOCOL_NONE,              // bInterfaceProtocol
-        0x00,                           // iInterface
-        HID_DESCRIPTOR_LENGTH,          // bLength
-        HID_DESCRIPTOR,                 // bDescriptorType
-        LSB(HID_VERSION_1_11),          // bcdHID (LSB)
-        MSB(HID_VERSION_1_11),          // bcdHID (MSB)
-        0x00,                           // bCountryCode
-        0x01,                           // bNumDescriptors
-        REPORT_DESCRIPTOR,              // bDescriptorType
-        LSB(this->reportDescLength()),  // wDescriptorLength (LSB)
-        MSB(this->reportDescLength()),  // wDescriptorLength (MSB)
-
-        ENDPOINT_DESCRIPTOR_LENGTH,     // bLength
-        ENDPOINT_DESCRIPTOR,            // bDescriptorType
-        PHY_TO_DESC(EPINT_IN),          // bEndpointAddress
-        E_INTERRUPT,                    // bmAttributes
-        LSB(MAX_PACKET_SIZE_EPINT),     // wMaxPacketSize (LSB)
-        MSB(MAX_PACKET_SIZE_EPINT),     // wMaxPacketSize (MSB)
-        1,                             // bInterval (milliseconds)
-
-        ENDPOINT_DESCRIPTOR_LENGTH,     // bLength
-        ENDPOINT_DESCRIPTOR,            // bDescriptorType
-        PHY_TO_DESC(EPINT_OUT),          // bEndpointAddress
-        E_INTERRUPT,                    // bmAttributes
-        LSB(MAX_PACKET_SIZE_EPINT),     // wMaxPacketSize (LSB)
-        MSB(MAX_PACKET_SIZE_EPINT),     // wMaxPacketSize (MSB)
-        1,                             // bInterval (milliseconds)
-    };
-    return configurationDescriptor;
-}
--- a/tests/USBDAP.h	Wed Sep 11 14:00:40 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,172 +0,0 @@
-/* Copyright (c) 2010-2011 mbed.org, MIT License
-*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
-* and associated documentation files (the "Software"), to deal in the Software without
-* restriction, including without limitation the rights to use, copy, modify, merge, publish,
-* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included in all copies or
-* substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
-* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#ifndef USB_DAP_H
-#define USB_DAP_H
-
-/* These headers are included for child class. */
-#include "USBEndpoints.h"
-#include "USBDescriptor.h"
-#include "USBDevice_Types.h"
-
-#include "USBHID_Types.h"
-#include "USBDevice.h"
-
-
-/**
- * USBHID example
- * @code
- * #include "mbed.h"
- * #include "USBHID.h"
- *
- * USBHID hid;
- * HID_REPORT recv;
- * BusOut leds(LED1,LED2,LED3,LED4);
- *
- * int main(void) {
- *    while (1) {
- *        hid.read(&recv);
- *        leds = recv.data[0];
- *    }
- * }
- * @endcode
- */
-
-class USBDAP: public USBDevice {
-public:
-
-    /**
-    * Constructor
-    *
-    * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)
-    * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes)
-    * @param vendor_id Your vendor_id
-    * @param product_id Your product_id
-    * @param product_release Your preoduct_release
-    * @param connect Connect the device
-    */
-    USBDAP(uint8_t output_report_length = 64, uint8_t input_report_length = 64, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0006, uint16_t product_release = 0x0001, bool connect = true);
-
-
-    /**
-    * Send a Report. warning: blocking
-    *
-    * @param report Report which will be sent (a report is defined by all data and the length)
-    * @returns true if successful
-    */
-    bool send(HID_REPORT *report);
-    
-    
-    /**
-    * Send a Report. warning: non blocking
-    *
-    * @param report Report which will be sent (a report is defined by all data and the length)
-    * @returns true if successful
-    */
-    bool sendNB(HID_REPORT *report);
-    
-    /**
-    * Read a report: blocking
-    *
-    * @param report pointer to the report to fill
-    * @returns true if successful
-    */
-    bool read(HID_REPORT * report);
-    
-    /**
-    * Read a report: non blocking
-    *
-    * @param report pointer to the report to fill
-    * @returns true if successful
-    */
-    bool readNB(HID_REPORT * report);
-
-protected:
-    uint16_t reportLength;
-    
-    /*
-    * Get the Report descriptor
-    *
-    * @returns pointer to the report descriptor
-    */
-    virtual uint8_t * reportDesc();
-
-    /*
-    * Get the length of the report descriptor
-    *
-    * @returns the length of the report descriptor
-    */
-    virtual uint16_t reportDescLength();
-
-    /*
-    * Get string product descriptor
-    *
-    * @returns pointer to the string product descriptor
-    */
-    virtual uint8_t * stringIproductDesc();
-    
-    /*
-    * Get string interface descriptor
-    *
-    * @returns pointer to the string interface descriptor
-    */
-    virtual uint8_t * stringIinterfaceDesc();
-    
-    /*
-    * Get configuration descriptor
-    *
-    * @returns pointer to the configuration descriptor
-    */
-    virtual uint8_t * configurationDesc();
-
-
-    /*
-    * HID Report received by SET_REPORT request. Warning: Called in ISR context
-    * First byte of data will be the report ID
-    *
-    * @param report Data and length received
-    */
-    virtual void HID_callbackSetReport(HID_REPORT *report){};
-
-
-    /*
-    * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
-    * This is used to handle extensions to standard requests
-    * and class specific requests
-    *
-    * @returns true if class handles this request
-    */
-    virtual bool USBCallback_request();
-
-
-    /*
-    * Called by USBDevice layer. Set configuration of the device.
-    * For instance, you can add all endpoints that you need on this function.
-    *
-    * @param configuration Number of the configuration
-    * @returns true if class handles this request
-    */
-    virtual bool USBCallback_setConfiguration(uint8_t configuration);
-
-private:
-    HID_REPORT outputReport;
-    uint8_t output_length;
-    uint8_t input_length;
-};
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/USBDAP.lib	Sat Sep 14 12:55:29 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/va009039/code/USBDAP/#6b9154ed73c6
--- a/tests/USBDevice.lib	Wed Sep 11 14:00:40 2013 +0000
+++ b/tests/USBDevice.lib	Sat Sep 14 12:55:29 2013 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/mbed_official/code/USBDevice/#16731886c049
+https://mbed.org/users/mbed_official/code/USBDevice/#d495202c90f4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test1_BaseDAP.cpp	Sat Sep 14 12:55:29 2013 +0000
@@ -0,0 +1,313 @@
+// test1_BaseDAP.cpp 2013/9/14
+#if 0
+#include "BaseDAP.h"
+#include "mytest.h"
+#include "mydebug.h"
+
+Serial pc(USBTX, USBRX);
+
+SWD* swd;
+BaseDAP* dap;
+uint8_t recv[64];
+
+TEST(DAP1,setup) {
+#ifdef TARGET_LPC1768
+    swd = new SWD(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
+#endif
+#ifdef TARGET_KL25Z
+    swd = new SWD(PTB8,PTB9,PTB10); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
+#endif
+    dap = new BaseDAP(swd);
+}
+
+TEST(DAP1,Info_PRODUCT) {
+    const uint8_t req[] = {0x00,0x02};
+    const uint8_t res[] = {0x00,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Info_SER_NUM) {
+    const uint8_t req[] = {0x00,0x03};
+    const uint8_t res[] = {0x00,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Info_FW_VER) {
+    const uint8_t req[] = {0x00,0x04};
+    const uint8_t res[] = {0x00,0x04,0x31,0x2e,0x30,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Info_VENDOR) {
+    const uint8_t req[] = {0x00,0x01};
+    const uint8_t res[] = {0x00,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Info_PRODUCT_2) {
+    const uint8_t req[] = {0x00,0x02};
+    const uint8_t res[] = {0x00,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Info_PACKET_SIZE) {
+    const uint8_t req[] = {0x00,0xff};
+    const uint8_t res[] = {0x00,0x02,0x40,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Info_PACKET_COUNT) {
+    const uint8_t req[] = {0x00,0xfe};
+    const uint8_t res[] = {0x00,0x01,0x01};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Connect_SWD) {
+    const uint8_t req[] = {0x02,0x01};
+    const uint8_t res[] = {0x02,0x01};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,SWJ_Clock_5000_Hz) {
+    const uint8_t req[] = {0x11,0x88,0x13,0x00,0x00};
+    const uint8_t res[] = {0x11,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,TransferConfigure) {
+    const uint8_t req[] = {0x04,0x00,0x64,0x00,0x00,0x00};
+    const uint8_t res[] = {0x04,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,SWD_Configure) {
+    const uint8_t req[] = {0x13,0x00};
+    const uint8_t res[] = {0x13,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,LED_DEBUGGER_CONNECTED_ON) {
+    const uint8_t req[] = {0x01,0x00,0x01};
+    const uint8_t res[] = {0x01,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,SWJ_Sequence_1_51) {
+    const uint8_t req[] = {0x12,0x33, 0xff,0xff,0xff,0xff,0xff,0xff,0xff};
+    const uint8_t res[] = {0x12,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,SWJ_Sequence_2_16) {
+    const uint8_t req[] = {0x12,0x10, 0x9e,0xe7};
+    const uint8_t res[] = {0x12,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,SWJ_Sequence_3_51) {
+    const uint8_t req[] = {0x12,0x33, 0xff,0xff,0xff,0xff,0xff,0xff,0xff};
+    const uint8_t res[] = {0x12,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,SWJ_Sequence_4_8) {
+    const uint8_t req[] = {0x12,0x08, 0x00};
+    const uint8_t res[] = {0x12,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Transfer_DP_IDCODE) {
+    const uint8_t req[] = {0x05, 0x00, 0x01, 0x02};
+    const uint8_t res[] = {0x05, 0x01, 0x01, 0x77,0x14,0xb1,0x0b};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    DBG_HEX(recv, len);
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Transfer_DP_SELECT) {
+    const uint8_t req[] = {0x05, 0x00, 0x01, 0x08, 0x00,0x00,0x00,0x00};
+    //SWD: DP_SELECT 00000000 request=08(DP nW 8) wdata=00000000 rdata=00000000 ack=01
+    //SWD: DP_RDBUFF 10008000 request=0e(DP R c) wdata=ffffffff rdata=10008000 ack=01
+    const uint8_t res[] = {0x05, 0x01, 0x01};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Transfer_DP_CTRL_STAT_W) {
+    const uint8_t req[] = {0x05,0x00, 0x01, 0x04, 0x00,0x00,0x00,0x50};
+    //SWD: DP_CTRL_STAT W 50000000 request=04(DP nW 4) wdata=50000000 rdata=50000000 ack=01
+    //SWD: DP_RDBUFF 10008000 request=0e(DP R c) wdata=ffffffff rdata=10008000 ack=01
+    const uint8_t res[] = {0x05,0x01, 0x01};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Transfer_DP_CTRL_STAT_R) {
+    const uint8_t req[] = {0x05,0x00, 0x01, 0x06};
+    //SWD: DP_CTRL_STAT R f0000040 request=06(DP R 4) wdata=00000040 rdata=f0000040 ack=01
+    const uint8_t res[] = {0x05,0x01, 0x01, 0x40,0x00,0x00,0xf0};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,WriteABORT) {
+    const uint8_t req[] = {0x08,0x00,0x1e,0x00,0x00,0x00};
+    //SWD: DP_ABORT 0000001e request=00(DP nW 0) wdata=0000001e rdata=0000001e ack=01
+    const uint8_t res[] = {0x08,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Transfer_DP_CTRL_STAT_W_2) {
+    const uint8_t req[] = {0x05,0x00, 0x01, 0x04, 0x00,0x00,0x00,0x54};
+    //SWD: DP_CTRL_STAT W 54000000 request=04(DP nW 4) wdata=54000000 rdata=54000000 ack=01
+    //SWD: DP_RDBUFF 10008000 request=0e(DP R c) wdata=ffffffff rdata=10008000 ack=01
+    const uint8_t res[] = {0x05,0x01, 0x01};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Transfer_DP_CTRL_STAT_W_3) {
+    const uint8_t req[] = {0x05,0x00, 0x01, 0x04, 0x00,0x0f,0x00,0x50};
+    //SWD: DP_CTRL_STAT W 50000f00 request=04(DP nW 4) wdata=50000f00 rdata=50000f00 ack=01
+    //SWD: DP_RDBUFF 10008000 request=0e(DP R c) wdata=ffffffff rdata=10008000 ack=01
+    const uint8_t res[] = {0x05,0x01, 0x01};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Transfer_AP_CSW) {
+    const uint8_t req[] = {0x05,0x00, 0x01, 0x01, 0x52,0x00,0x00,0x23};
+    //SWD: AP_CSW W 23000052 request=01(AP nW 0) wdata=23000052 rdata=23000052 ack=01
+    //SWD: DP_RDBUFF 10008000 request=0e(DP R c) wdata=ffffffff rdata=10008000 ack=01
+    const uint8_t res[] = {0x05,0x01, 0x01};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Transfer_AP_TAR) {
+    const uint8_t req[] = {0x05,0x00, 0x01, 0x05, 0xf0,0xff,0x0f,0xe0};
+    //SWD: AP_TAR W e00ffff0 request=05(AP nW 4) wdata=e00ffff0 rdata=e00ffff0 ack=01
+    //SWD: DP_RDBUFF 10008000 request=0e(DP R c) wdata=ffffffff rdata=10008000 ack=01
+    const uint8_t res[] = {0x05,0x01, 0x01};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,TransferBlock_AP_DRW_R) {
+    const uint8_t req[] = {0x06,0x00, 0x04,0x00, 0x0f};
+    //SWD: AP_DRW R 10008000 request=0f(AP R c) wdata=ffffffff rdata=10008000 ack=01
+    //SWD: AP_DRW R 0000000d request=0f(AP R c) wdata=00000006 rdata=0000000d ack=01
+    //SWD: AP_DRW R 00000010 request=0f(AP R c) wdata=0000000d rdata=00000010 ack=01
+    //SWD: AP_DRW R 00000005 request=0f(AP R c) wdata=00000010 rdata=00000005 ack=01
+    //SWD: DP_RDBUFF 000000b1 request=0e(DP R c) wdata=00000005 rdata=000000b1 ack=01
+    const uint8_t res[] = {0x06, 0x04,0x00, 0x01, 
+        0x0d,0x00,0x00,0x00, 0x10,0x00,0x00,0x00, 0x05,0x00,0x00,0x00, 0xb1,0x00,0x00,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, 4) == 0);
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,SWJ_Pins_nRESET_OFF) {
+    const uint8_t req[] = {0x10,0x00,0x80,0x00,0x00,0x00,0x00,};
+    //DAP: SWJ_Pins wait: 0 us nRESET OFF
+    const uint8_t res[] = {0x10,0x03};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,SWJ_Pins_nRESET_ON) {
+    const uint8_t req[] = {0x10,0x80,0x80,0x00,0x00,0x00,0x00,};
+    //DAP: SWJ_Pins wait: 0 us nRESET ON
+    const uint8_t res[] = {0x10,0x83};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,SWJ_Pins) {
+    const uint8_t req[] = {0x10,0x00,0x00,0x00,0x00,0x00,0x00,};
+    //DAP: SWJ_Pins wait: 0 us nRESET ON
+    const uint8_t res[] = {0x10,0x83};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Disconnect) {
+    const uint8_t req[] = {0x03};
+    const uint8_t res[] = {0x03,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,LED_DEBUGGER_CONNECTED_OFF) {
+    const uint8_t req[] = {0x01,0x00,0x00};
+    const uint8_t res[] = {0x01,0x00};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len == sizeof(res));
+    ASSERT_TRUE(memcmp(recv, res, len) == 0);
+}
+
+TEST(DAP1,Vender0) {
+    const uint8_t req[] = {0x80};
+    const uint8_t res[] = {0x80,0x00, '1','0','4','0'};
+    int len = dap->Command((uint8_t*)req, recv);
+    ASSERT_TRUE(len >= sizeof(res));
+    ASSERT_TRUE(recv[0] == 0x80);
+    ASSERT_TRUE(memcmp(recv+2, res+2, 4) == 0); // 1040 lpc11u24
+}
+
+int main() {
+    //pc.baud(921600);
+    pc.baud(9600);
+    DBG("%s", __FILE__);
+
+    RUN_ALL_TESTS();
+    exit(0);
+}
+#endif
--- a/tests/test1_DAP.cpp	Wed Sep 11 14:00:40 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,308 +0,0 @@
-// test1_DAP.cpp 2013/9/10
-#if 0
-#include "DAP.h"
-#include "mytest.h"
-#include "mydebug.h"
-
-Serial pc(USBTX, USBRX);
-
-SWD* swd;
-DAP* dap;
-uint8_t recv[64];
-
-TEST(DAP1,setup) {
-    swd = new SWD(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
-    dap = new DAP(swd);
-}
-
-TEST(DAP1,Info_PRODUCT) {
-    const uint8_t req[] = {0x00,0x02};
-    const uint8_t res[] = {0x00,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Info_SER_NUM) {
-    const uint8_t req[] = {0x00,0x03};
-    const uint8_t res[] = {0x00,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Info_FW_VER) {
-    const uint8_t req[] = {0x00,0x04};
-    const uint8_t res[] = {0x00,0x04,0x31,0x2e,0x30,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Info_VENDOR) {
-    const uint8_t req[] = {0x00,0x01};
-    const uint8_t res[] = {0x00,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Info_PRODUCT_2) {
-    const uint8_t req[] = {0x00,0x02};
-    const uint8_t res[] = {0x00,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Info_PACKET_SIZE) {
-    const uint8_t req[] = {0x00,0xff};
-    const uint8_t res[] = {0x00,0x02,0x40,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Info_PACKET_COUNT) {
-    const uint8_t req[] = {0x00,0xfe};
-    const uint8_t res[] = {0x00,0x01,0x01};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Connect_SWD) {
-    const uint8_t req[] = {0x02,0x01};
-    const uint8_t res[] = {0x02,0x01};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,SWJ_Clock_5000_Hz) {
-    const uint8_t req[] = {0x11,0x88,0x13,0x00,0x00};
-    const uint8_t res[] = {0x11,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,TransferConfigure) {
-    const uint8_t req[] = {0x04,0x00,0x64,0x00,0x00,0x00};
-    const uint8_t res[] = {0x04,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,SWD_Configure) {
-    const uint8_t req[] = {0x13,0x00};
-    const uint8_t res[] = {0x13,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,LED_DEBUGGER_CONNECTED_ON) {
-    const uint8_t req[] = {0x01,0x00,0x01};
-    const uint8_t res[] = {0x01,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,SWJ_Sequence_1_51) {
-    const uint8_t req[] = {0x12,0x33, 0xff,0xff,0xff,0xff,0xff,0xff,0xff};
-    const uint8_t res[] = {0x12,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,SWJ_Sequence_2_16) {
-    const uint8_t req[] = {0x12,0x10, 0x9e,0xe7};
-    const uint8_t res[] = {0x12,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,SWJ_Sequence_3_51) {
-    const uint8_t req[] = {0x12,0x33, 0xff,0xff,0xff,0xff,0xff,0xff,0xff};
-    const uint8_t res[] = {0x12,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,SWJ_Sequence_4_8) {
-    const uint8_t req[] = {0x12,0x08, 0x00};
-    const uint8_t res[] = {0x12,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Transfer_DP_IDCODE) {
-    const uint8_t req[] = {0x05, 0x00, 0x01, 0x02};
-    const uint8_t res[] = {0x05, 0x01, 0x01, 0x77,0x14,0xb1,0x0b};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    DBG_HEX(recv, len);
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Transfer_DP_SELECT) {
-    const uint8_t req[] = {0x05, 0x00, 0x01, 0x08, 0x00,0x00,0x00,0x00};
-    //SWD: DP_SELECT 00000000 request=08(DP nW 8) wdata=00000000 rdata=00000000 ack=01
-    //SWD: DP_RDBUFF 10008000 request=0e(DP R c) wdata=ffffffff rdata=10008000 ack=01
-    const uint8_t res[] = {0x05, 0x01, 0x01};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Transfer_DP_CTRL_STAT_W) {
-    const uint8_t req[] = {0x05,0x00, 0x01, 0x04, 0x00,0x00,0x00,0x50};
-    //SWD: DP_CTRL_STAT W 50000000 request=04(DP nW 4) wdata=50000000 rdata=50000000 ack=01
-    //SWD: DP_RDBUFF 10008000 request=0e(DP R c) wdata=ffffffff rdata=10008000 ack=01
-    const uint8_t res[] = {0x05,0x01, 0x01};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Transfer_DP_CTRL_STAT_R) {
-    const uint8_t req[] = {0x05,0x00, 0x01, 0x06};
-    //SWD: DP_CTRL_STAT R f0000040 request=06(DP R 4) wdata=00000040 rdata=f0000040 ack=01
-    const uint8_t res[] = {0x05,0x01, 0x01, 0x40,0x00,0x00,0xf0};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,WriteABORT) {
-    const uint8_t req[] = {0x08,0x00,0x1e,0x00,0x00,0x00};
-    //SWD: DP_ABORT 0000001e request=00(DP nW 0) wdata=0000001e rdata=0000001e ack=01
-    const uint8_t res[] = {0x08,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Transfer_DP_CTRL_STAT_W_2) {
-    const uint8_t req[] = {0x05,0x00, 0x01, 0x04, 0x00,0x00,0x00,0x54};
-    //SWD: DP_CTRL_STAT W 54000000 request=04(DP nW 4) wdata=54000000 rdata=54000000 ack=01
-    //SWD: DP_RDBUFF 10008000 request=0e(DP R c) wdata=ffffffff rdata=10008000 ack=01
-    const uint8_t res[] = {0x05,0x01, 0x01};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Transfer_DP_CTRL_STAT_W_3) {
-    const uint8_t req[] = {0x05,0x00, 0x01, 0x04, 0x00,0x0f,0x00,0x50};
-    //SWD: DP_CTRL_STAT W 50000f00 request=04(DP nW 4) wdata=50000f00 rdata=50000f00 ack=01
-    //SWD: DP_RDBUFF 10008000 request=0e(DP R c) wdata=ffffffff rdata=10008000 ack=01
-    const uint8_t res[] = {0x05,0x01, 0x01};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Transfer_AP_CSW) {
-    const uint8_t req[] = {0x05,0x00, 0x01, 0x01, 0x52,0x00,0x00,0x23};
-    //SWD: AP_CSW W 23000052 request=01(AP nW 0) wdata=23000052 rdata=23000052 ack=01
-    //SWD: DP_RDBUFF 10008000 request=0e(DP R c) wdata=ffffffff rdata=10008000 ack=01
-    const uint8_t res[] = {0x05,0x01, 0x01};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Transfer_AP_TAR) {
-    const uint8_t req[] = {0x05,0x00, 0x01, 0x05, 0xf0,0xff,0x0f,0xe0};
-    //SWD: AP_TAR W e00ffff0 request=05(AP nW 4) wdata=e00ffff0 rdata=e00ffff0 ack=01
-    //SWD: DP_RDBUFF 10008000 request=0e(DP R c) wdata=ffffffff rdata=10008000 ack=01
-    const uint8_t res[] = {0x05,0x01, 0x01};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,TransferBlock_AP_DRW_R) {
-    const uint8_t req[] = {0x06,0x00, 0x04,0x00, 0x0f};
-    //SWD: AP_DRW R 10008000 request=0f(AP R c) wdata=ffffffff rdata=10008000 ack=01
-    //SWD: AP_DRW R 0000000d request=0f(AP R c) wdata=00000006 rdata=0000000d ack=01
-    //SWD: AP_DRW R 00000010 request=0f(AP R c) wdata=0000000d rdata=00000010 ack=01
-    //SWD: AP_DRW R 00000005 request=0f(AP R c) wdata=00000010 rdata=00000005 ack=01
-    //SWD: DP_RDBUFF 000000b1 request=0e(DP R c) wdata=00000005 rdata=000000b1 ack=01
-    const uint8_t res[] = {0x06, 0x04,0x00, 0x01, 
-        0x0d,0x00,0x00,0x00, 0x10,0x00,0x00,0x00, 0x05,0x00,0x00,0x00, 0xb1,0x00,0x00,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, 4) == 0);
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,SWJ_Pins_nRESET_OFF) {
-    const uint8_t req[] = {0x10,0x00,0x80,0x00,0x00,0x00,0x00,};
-    //DAP: SWJ_Pins wait: 0 us nRESET OFF
-    const uint8_t res[] = {0x10,0x03};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,SWJ_Pins_nRESET_ON) {
-    const uint8_t req[] = {0x10,0x80,0x80,0x00,0x00,0x00,0x00,};
-    //DAP: SWJ_Pins wait: 0 us nRESET ON
-    const uint8_t res[] = {0x10,0x83};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,SWJ_Pins) {
-    const uint8_t req[] = {0x10,0x00,0x00,0x00,0x00,0x00,0x00,};
-    //DAP: SWJ_Pins wait: 0 us nRESET ON
-    const uint8_t res[] = {0x10,0x83};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Disconnect) {
-    const uint8_t req[] = {0x03};
-    const uint8_t res[] = {0x03,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,LED_DEBUGGER_CONNECTED_OFF) {
-    const uint8_t req[] = {0x01,0x00,0x00};
-    const uint8_t res[] = {0x01,0x00};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len == sizeof(res));
-    ASSERT_TRUE(memcmp(recv, res, len) == 0);
-}
-
-TEST(DAP1,Vender0) {
-    const uint8_t req[] = {0x80};
-    const uint8_t res[] = {0x80,0x00, '1','0','4','0'};
-    int len = dap->Command((uint8_t*)req, recv);
-    ASSERT_TRUE(len >= sizeof(res));
-    ASSERT_TRUE(recv[0] == 0x80);
-    ASSERT_TRUE(memcmp(recv+2, res+2, 4) == 0); // 1040 lpc11u24
-}
-
-int main() {
-    pc.baud(921600);
-    //pc.baud(9600);
-    DBG("%s", __FILE__);
-
-    RUN_ALL_TESTS();
-    exit(0);
-}
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test1_SWD.cpp	Sat Sep 14 12:55:29 2013 +0000
@@ -0,0 +1,229 @@
+// test1_SWD.cpp 2013/9/14
+#if 0
+#include "SWD.h"
+#include "mytest.h"
+
+Serial pc(USBTX, USBRX);
+#ifdef TARGET_LPC1768
+SWD swd(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
+#endif
+#ifdef TARGET_KL25Z
+SWD swd(PTB8,PTB9,PTB10); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
+#endif 
+
+
+TEST(SWD1,setup) {
+    swd.Setup();
+}
+
+TEST(SWD1,JTAG2SWD) {
+    const uint8_t data1[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff};
+    const uint8_t data2[] = {0x9e,0xe7};
+    const uint8_t data3[] = {0x00};
+    swd.SWJSequence(sizeof(data1)*8, data1);
+    swd.SWJSequence(sizeof(data2)*8, data2);
+    swd.SWJSequence(sizeof(data1)*8, data1);
+    swd.SWJSequence(sizeof(data3)*8, data3);
+}
+
+TEST(SWD1,idcode) {
+    uint32_t data = 0xffffffff;
+    uint8_t ack = swd.Transfer(DP_IDCODE, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+    ASSERT_TRUE(data == 0x0bb11477);
+}
+
+TEST(SWD1,abort1) {
+    uint32_t data = 0x1e;
+    uint8_t ack = swd.Transfer(DP_ABORT, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+}
+
+TEST(SWD1,select) {
+    uint32_t data = 0x0;
+    uint8_t ack = swd.Transfer(DP_SELECT, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(DP_RDBUFF, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("DP_RDBUFF: %08x\n", data);
+}
+
+TEST(SWD1,ctrl_stat) {
+    uint32_t data = CSYSPWRUPREQ | CDBGPWRUPREQ;
+    ASSERT_TRUE(data == 0x50000000);
+    uint8_t ack = swd.Transfer(DP_CTRL_STAT, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(DP_RDBUFF, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("DP_RDBUFF: %08x\n", data);
+
+    ack = swd.Transfer(DP_CTRL_STAT_R, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("%08x\n", data);
+    ASSERT_TRUE(data == 0xf0000040);
+}
+
+TEST(SWD1,abort2) {
+    uint32_t data = 0x1e;
+    uint8_t ack = swd.Transfer(DP_ABORT, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+}
+
+TEST(SWD1,ctrl_stat1) {
+    //uint32_t data = CSYSPWRUPREQ | CDBGPWRUPREQ | TRNNORMAL;
+    uint32_t data = CSYSPWRUPREQ | CDBGPWRUPREQ | 0x04000000;
+    ASSERT_TRUE(data == 0x54000000);
+    uint8_t ack = swd.Transfer(DP_CTRL_STAT, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(DP_RDBUFF, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("DP_RDBUFF: %08x\n", data);
+}
+
+TEST(SWD1,ctrl_stat2) {
+    uint32_t data = CSYSPWRUPREQ | CDBGPWRUPREQ | MASKLANE;
+    ASSERT_TRUE(data == 0x50000f00);
+    uint8_t ack = swd.Transfer(DP_CTRL_STAT, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(DP_RDBUFF, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("DP_RDBUFF: %08x\n", data);
+}
+
+TEST(SWD1,csw) {
+    uint32_t data = CSW_VALUE|CSW_SIZE32;
+    ASSERT_TRUE(data == 0x23000052);
+    uint8_t ack = swd.Transfer(AP_CSW, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(DP_RDBUFF, &data);
+    DBG("ack=%02x\n", ack);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("DP_RDBUFF: %08x\n", data);
+}
+
+TEST(SWD1,tar) {
+    //uint32_t addr = 0x10000000;
+    uint32_t addr = 0x00000000;
+    uint8_t ack = swd.Transfer(AP_TAR, &addr);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(DP_RDBUFF, NULL);
+    ASSERT_TRUE(ack == SWD_OK);
+}
+
+TEST(SWD1,drw) {
+    uint32_t data = 0xffffffff;
+    uint8_t ack = swd.Transfer(AP_DRW_R, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("data=%08x\n", data);
+
+    ack = swd.Transfer(AP_DRW_R, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("data=%08x\n", data);
+
+    ack = swd.Transfer(AP_DRW_R, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("data=%08x\n", data);
+
+    ack = swd.Transfer(DP_RDBUFF, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("data=%08x\n", data);
+}
+
+TEST(SWD1,MemoryRead) {
+    uint32_t addr = 0;
+    uint32_t data = 0xffffffff;
+    uint32_t dummy = 0xffffffff;
+    
+    uint8_t ack = swd.Transfer(AP_TAR, &addr);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(DP_RDBUFF, NULL);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(AP_DRW_R, &dummy);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("dummy=%08x\n", dummy);
+
+    ack = swd.Transfer(DP_RDBUFF, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("addr=%08x data=%08x\n", addr, data);
+}
+
+TEST(SWD1,DHCSR) {
+    uint32_t addr = 0xE000EDF0; // Debug Halting Control and Status Register
+    uint32_t data = 0xffffffff;
+    uint32_t dummy = 0xffffffff;
+    
+    uint8_t ack = swd.Transfer(AP_TAR, &addr);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(DP_RDBUFF, NULL);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(AP_DRW_R, &dummy);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("dummy=%08x\n", dummy);
+
+    ack = swd.Transfer(DP_RDBUFF, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("addr=%08x data=%08x\n", addr, data);
+}
+
+TEST(SWD1,MemoryRead_fault) {
+    uint32_t addr = 10000000;
+    uint32_t data = 0xffffffff;
+    uint32_t dummy = 0xffffffff;
+    
+    uint8_t ack = swd.Transfer(AP_TAR, &addr);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(DP_RDBUFF, NULL);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(AP_DRW_R, &dummy);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(DP_RDBUFF, &data);
+    ASSERT_TRUE(ack == SWD_FAULT);
+}
+
+TEST(SWD1,abort3) {
+    uint32_t data = 0x1e;
+    uint8_t ack = swd.Transfer(DP_ABORT, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+}
+
+TEST(SWD1,DCRSR) {
+    uint32_t addr = 0xE000EDF4; // Debug Core Register Selector Register 
+    uint32_t data = 0xffffffff;
+    uint32_t dummy = 0xffffffff;
+    
+    uint8_t ack = swd.Transfer(AP_TAR, &addr);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(DP_RDBUFF, NULL);
+    ASSERT_TRUE(ack == SWD_OK);
+
+    ack = swd.Transfer(AP_DRW_R, &dummy);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("dummy=%08x\n", dummy);
+
+    ack = swd.Transfer(DP_RDBUFF, &data);
+    ASSERT_TRUE(ack == SWD_OK);
+    DBG("addr=%08x data=%08x\n", addr, data);
+}
+
+int main() {
+    //pc.baud(921600);
+    pc.baud(9600);
+    DBG("%s", __FILE__);
+
+    RUN_ALL_TESTS();
+}
+#endif
--- a/tests/test1_Target2.cpp	Wed Sep 11 14:00:40 2013 +0000
+++ b/tests/test1_Target2.cpp	Sat Sep 14 12:55:29 2013 +0000
@@ -1,216 +1,181 @@
-// test1_Target2.cpp 2013/9/1
-#if 0
-#include "SWD.h"
-#include "mytest.h"
-
-Serial pc(USBTX, USBRX);
-SWD swd(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
-
-TEST(SWD1,setup) {
-    swd.Setup();
-}
-
-TEST(SWD1,JTAG2SWD) {
-    swd.JTAG2SWD();
-}
-
-TEST(SWD1,idcode) {
-    uint32_t data = 0xffffffff;
-    uint8_t ack = swd.Transfer(DP_IDCODE, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-    ASSERT_TRUE(data == 0x0bb11477);
-}
-
-TEST(SWD1,abort1) {
-    uint32_t data = 0x1e;
-    uint8_t ack = swd.Transfer(DP_ABORT, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-}
-
-TEST(SWD1,select) {
-    uint32_t data = 0x0;
-    uint8_t ack = swd.Transfer(DP_SELECT, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(DP_RDBUFF, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("DP_RDBUFF: %08x\n", data);
-}
-
-TEST(SWD1,ctrl_stat) {
-    uint32_t data = CSYSPWRUPREQ | CDBGPWRUPREQ;
-    ASSERT_TRUE(data == 0x50000000);
-    uint8_t ack = swd.Transfer(DP_CTRL_STAT, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(DP_RDBUFF, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("DP_RDBUFF: %08x\n", data);
-
-    ack = swd.Transfer(DP_CTRL_STAT_R, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("%08x\n", data);
-    ASSERT_TRUE(data == 0xf0000040);
-}
-
-TEST(SWD1,abort2) {
-    uint32_t data = 0x1e;
-    uint8_t ack = swd.Transfer(DP_ABORT, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-}
-
-TEST(SWD1,ctrl_stat1) {
-    //uint32_t data = CSYSPWRUPREQ | CDBGPWRUPREQ | TRNNORMAL;
-    uint32_t data = CSYSPWRUPREQ | CDBGPWRUPREQ | 0x04000000;
-    ASSERT_TRUE(data == 0x54000000);
-    uint8_t ack = swd.Transfer(DP_CTRL_STAT, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(DP_RDBUFF, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("DP_RDBUFF: %08x\n", data);
-}
-
-TEST(SWD1,ctrl_stat2) {
-    uint32_t data = CSYSPWRUPREQ | CDBGPWRUPREQ | MASKLANE;
-    ASSERT_TRUE(data == 0x50000f00);
-    uint8_t ack = swd.Transfer(DP_CTRL_STAT, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(DP_RDBUFF, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("DP_RDBUFF: %08x\n", data);
-}
-
-TEST(SWD1,csw) {
-    uint32_t data = CSW_VALUE|CSW_SIZE32;
-    ASSERT_TRUE(data == 0x23000052);
-    uint8_t ack = swd.Transfer(AP_CSW, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(DP_RDBUFF, &data);
-    DBG("ack=%02x\n", ack);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("DP_RDBUFF: %08x\n", data);
-}
-
-TEST(SWD1,tar) {
-    //uint32_t addr = 0x10000000;
-    uint32_t addr = 0x00000000;
-    uint8_t ack = swd.Transfer(AP_TAR, &addr);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(DP_RDBUFF, NULL);
-    ASSERT_TRUE(ack == SWD_OK);
-}
-
-TEST(SWD1,drw) {
-    uint32_t data = 0xffffffff;
-    uint8_t ack = swd.Transfer(AP_DRW_R, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("data=%08x\n", data);
-
-    ack = swd.Transfer(AP_DRW_R, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("data=%08x\n", data);
-
-    ack = swd.Transfer(AP_DRW_R, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("data=%08x\n", data);
-
-    ack = swd.Transfer(DP_RDBUFF, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("data=%08x\n", data);
-}
-
-TEST(SWD1,MemoryRead) {
-    uint32_t addr = 0;
-    uint32_t data = 0xffffffff;
-    uint32_t dummy = 0xffffffff;
-    
-    uint8_t ack = swd.Transfer(AP_TAR, &addr);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(DP_RDBUFF, NULL);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(AP_DRW_R, &dummy);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("dummy=%08x\n", dummy);
-
-    ack = swd.Transfer(DP_RDBUFF, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("addr=%08x data=%08x\n", addr, data);
-}
-
-TEST(SWD1,DHCSR) {
-    uint32_t addr = 0xE000EDF0; // Debug Halting Control and Status Register
-    uint32_t data = 0xffffffff;
-    uint32_t dummy = 0xffffffff;
-    
-    uint8_t ack = swd.Transfer(AP_TAR, &addr);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(DP_RDBUFF, NULL);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(AP_DRW_R, &dummy);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("dummy=%08x\n", dummy);
-
-    ack = swd.Transfer(DP_RDBUFF, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("addr=%08x data=%08x\n", addr, data);
-}
-
-TEST(SWD1,MemoryRead_fault) {
-    uint32_t addr = 10000000;
-    uint32_t data = 0xffffffff;
-    uint32_t dummy = 0xffffffff;
-    
-    uint8_t ack = swd.Transfer(AP_TAR, &addr);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(DP_RDBUFF, NULL);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(AP_DRW_R, &dummy);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(DP_RDBUFF, &data);
-    ASSERT_TRUE(ack == SWD_FAULT);
-}
-
-TEST(SWD1,abort3) {
-    uint32_t data = 0x1e;
-    uint8_t ack = swd.Transfer(DP_ABORT, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-}
-
-TEST(SWD1,DCRSR) {
-    uint32_t addr = 0xE000EDF4; // Debug Core Register Selector Register 
-    uint32_t data = 0xffffffff;
-    uint32_t dummy = 0xffffffff;
-    
-    uint8_t ack = swd.Transfer(AP_TAR, &addr);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(DP_RDBUFF, NULL);
-    ASSERT_TRUE(ack == SWD_OK);
-
-    ack = swd.Transfer(AP_DRW_R, &dummy);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("dummy=%08x\n", dummy);
-
-    ack = swd.Transfer(DP_RDBUFF, &data);
-    ASSERT_TRUE(ack == SWD_OK);
-    DBG("addr=%08x data=%08x\n", addr, data);
-}
-
-int main() {
-    pc.baud(921600);
-    DBG("%s", __FILE__);
-
-    RUN_ALL_TESTS();
-}
-#endif
+// test1_Target2.cpp 2013/9/14
+#if 0
+#include "Target2.h"
+#include "mytest.h"
+
+Serial pc(USBTX, USBRX);
+#ifdef TARGET_LPC1768
+Target2 target(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
+#endif
+#ifdef TARGET_KL25Z
+Target2 target(PTB8,PTB9,PTB10); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
+#endif
+
+TEST(Target2,setup) {
+    ASSERT_TRUE(target.setup());
+}
+
+TEST(Target2,readMemory1) {
+    uint32_t data = target.readMemory(0); // sp
+    ASSERT_TRUE(data == 0x10001000);
+}
+
+TEST(Target2,readMemory2) {
+    for(uint32_t addr = 0; addr < 0x1c; addr += 4) {
+        uint32_t data = target.readMemory(addr);
+        //TEST_PRINT("addr=%08x data=%08x\n", addr, data);
+    }
+}
+
+TEST(Target2,readMemory3) {
+    for(uint32_t addr = 0; addr < 0x100; addr += 4) {
+        uint32_t data = target.readMemory(addr);
+    }
+}
+
+TEST(Target2,DHCSR1) {
+    uint32_t data = target.readMemory(0xE000EDF0);
+    
+}
+
+TEST(Target2,getStatus1) {
+    int status = target.getStatus();
+    ASSERT_TRUE(status == TARGET_RUNNING);
+}
+
+TEST(Target2,halt1) {
+    target.halt();
+    int status = target.getStatus();
+    ASSERT_TRUE(status == TARGET_HALTED);
+}
+
+TEST(Target2,resume1) {
+    target.resume();
+    int status = target.getStatus();
+    ASSERT_TRUE(status == TARGET_RUNNING);
+}
+
+TEST(Target2,writeMemory1) {
+    uint32_t addr = 0x10000000;
+    target.halt();
+    int status = target.getStatus();
+    ASSERT_TRUE(status == TARGET_HALTED);
+
+    uint32_t data = target.readMemory(addr);
+    target.writeMemory(addr, 0x12345678);
+    ASSERT_TRUE(target.readMemory(addr) == 0x12345678);
+    target.writeMemory(addr, data);
+    ASSERT_TRUE(target.readMemory(addr) == data);
+
+    target.resume();
+    status = target.getStatus();
+    ASSERT_TRUE(status == TARGET_RUNNING);
+}
+
+TEST(Target2,writeMemory2) {
+    uint32_t addr = 0x10001000-4;
+    uint32_t data = target.readMemory(addr);
+    target.writeMemory(addr, 0x12345678);
+    ASSERT_TRUE(target.readMemory(addr) == 0x12345678);
+    target.writeMemory(addr, data);
+    ASSERT_TRUE(target.readMemory(addr) == data);
+}
+
+TEST(CoreReg,r0) {
+    uint32_t r0 = target.r0.read();
+}
+
+TEST(CoreReg,r1) {
+    target.halt();
+    uint32_t backup = target.r1.read();
+    target.r1.write(0x11223344);
+    uint32_t data = target.r1.read();
+    ASSERT_TRUE(data == 0x11223344);
+    target.r1.write(backup);
+    target.resume();
+}
+
+TEST(CoreReg,r2) {
+    target.halt();
+    uint32_t backup = target.r2;
+    target.r2 = 0x11223344;
+    ASSERT_TRUE(target.r2 == 0x11223344);
+    target.r2 = backup;
+    target.resume();
+}
+
+TEST(CoreReg,pc) {
+    uint32_t pc = target.pc.read();
+    //TEST_PRINT("pc=%08x\n", pc);
+}
+
+TEST(Target2,wait_status1) {
+    target.halt();
+    bool r = target.wait_status(TARGET_HALTED);
+    ASSERT_TRUE(r);
+    target.resume();
+    r = target.wait_status(TARGET_HALTED, 50);
+    ASSERT_TRUE(!r);
+}
+
+TEST(Target2,writeMemory3) {
+    target.halt();
+    bool r = target.wait_status(TARGET_HALTED);
+    ASSERT_TRUE(r);
+
+    uint8_t buf[256];
+    for(int i = 0; i < sizeof(buf); i++) {
+        buf[i] = i;
+    }
+    uint32_t addr = 0x10000000;
+    target.writeMemory(addr, (uint32_t*)buf, sizeof(buf)/sizeof(uint32_t));
+
+    uint8_t rbuf[256];
+    target.readMemory(addr, (uint32_t*)rbuf, sizeof(rbuf)/sizeof(uint32_t));
+
+    ASSERT_TRUE(memcmp(buf, rbuf, sizeof(buf)) == 0);
+}
+
+#define SYST_CSR 0xe000e010
+
+#define ICER  0xe000e180
+#define ICPR  0xe000e280
+
+#define CPUID 0xe000ed00
+#define ICSR  0xe000ed04
+
+TEST(Target2,test_SCB) {
+    target.resume();
+    for(int i = 0; i < 3; i++) {
+        uint32_t pc = target.pc.read();
+        TEST_PRINT("pc=%08x", pc);
+
+        uint32_t syst_csr = target.readMemory(SYST_CSR);
+        TEST_PRINT("SYST_CSR=%08x", syst_csr);
+        uint32_t icer = target.readMemory(ICER);
+        TEST_PRINT("ICER=%08x", icer);
+        uint32_t icpr = target.readMemory(ICPR);
+        TEST_PRINT("ICPR=%08x", icpr);
+        uint32_t cpuid = target.readMemory(CPUID);
+        TEST_PRINT("CPUID=%08x", cpuid);
+        uint32_t icsr = target.readMemory(ICSR);
+        TEST_PRINT("ICSR=%08x", icsr);
+    }
+    for(int i = 0; i < 100; i++) {
+        uint32_t syst_csr = target.readMemory(SYST_CSR);
+        if (syst_csr != 0) {
+            TEST_PRINT("SYST_CSR=%08x", syst_csr);
+            break;
+        }
+    }
+}
+
+int main() {
+    //pc.baud(921600);
+    pc.baud(9600);
+    DBG("%s", __FILE__);
+
+    RUN_ALL_TESTS();
+}
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test2_BaseDAP.cpp	Sat Sep 14 12:55:29 2013 +0000
@@ -0,0 +1,104 @@
+// test2_BaseDAP.cpp 2013/9/13
+#if 0
+#include "BaseDAP.h"
+#include "USBDAP.h"
+#include "mytest.h"
+#include "mydebug.h"
+
+Serial pc(USBTX, USBRX);
+
+#ifdef TARGET_LPC1768
+SWD swd(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
+DigitalOut connected(LED1);
+DigitalOut running(LED2);
+class myDAP : public BaseDAP {
+public:
+    myDAP(SWD* swd):BaseDAP(swd){};
+    virtual void infoLED(int select, int value) {
+        switch(select) {
+            case 0: connected = value; break;
+            case 1: running = value; break;
+        }
+    } 
+};
+#endif
+
+#ifdef TARGET_KL25Z
+SWD swd(PTB8,PTB9,PTB10); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
+DigitalOut connected(LED_GREEN);
+DigitalOut running(LED_RED);
+class myDAP : public BaseDAP {
+public:
+    myDAP(SWD* swd):BaseDAP(swd){};
+    virtual void infoLED(int select, int value) {
+        switch(select) {
+            case 0:
+                connected = value^1; 
+                running = 1;
+                break;
+            case 1: 
+                running = value^1; 
+                connected = 1;
+                break;
+        }
+    } 
+};
+#endif
+
+myDAP* dap = NULL;
+USBDAP* hid = NULL;
+
+HID_REPORT send_report;
+HID_REPORT recv_report;
+
+TEST(DAP2,setup2) {
+    dap = new myDAP(&swd);
+}
+
+TEST(DAP2,setup3) {
+    hid = new USBDAP(64, 64, 0x0d28, 0x0204);
+}
+
+TEST(DAP2,test1) {
+    ASSERT_TRUE(hid);
+    ASSERT_TRUE(dap);
+    if(hid->readNB(&recv_report)) {
+        dap->Command(recv_report.data, send_report.data);
+        send_report.length = 64;
+        hid->send(&send_report);
+    }
+}
+
+static void hex_dump(uint8_t* buf, int size)
+{
+    for(int i = 0; i < size; i++) {
+        printf("%02x ", buf[i]);
+    }
+    printf("\n");
+}
+
+TEST(DAP2,forever1) {
+    while(1) {
+        if(hid->readNB(&recv_report)) {
+            //DBG("%02x", recv_report.data[0]);
+            hex_dump(recv_report.data, 32);
+            uint8_t cmd = recv_report.data[0];
+            dap->Command(recv_report.data, send_report.data);
+            send_report.length = 64;
+            uint8_t* buf = send_report.data;
+            DBG("%02x: %02x %02x %02x %02x %02x", cmd, buf[0], buf[1], buf[2], buf[3], buf[4]); 
+            bool r = hid->send(&send_report);
+            ASSERT_TRUE(r);
+        }
+    }    
+}
+
+int main() {
+    pc.baud(921600);
+    //pc.baud(9600);
+    DBG("%s", __FILE__);
+
+    RUN_ALL_TESTS();
+    exit(0);
+}
+#endif
--- a/tests/test2_DAP.cpp	Wed Sep 11 14:00:40 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-// test2_DAP.cpp 2013/9/11
-#if 0
-#include "DAP.h"
-#include "USBDAP.h"
-#include "mytest.h"
-#include "mydebug.h"
-
-Serial pc(USBTX, USBRX);
-
-SWD* swd = NULL;
-DAP* dap = NULL;
-USBDAP* hid = NULL;
-
-HID_REPORT send_report;
-HID_REPORT recv_report;
-
-TEST(DAP2,setup1) {
-    swd = new SWD(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
-}
-
-TEST(DAP2,setup2) {
-    ASSERT_TRUE(swd);
-    dap = new DAP(swd);
-}
-
-TEST(DAP2,setup3) {
-    hid = new USBDAP(64, 64, 0x0d28, 0x0204);
-}
-
-TEST(DAP2,test1) {
-    ASSERT_TRUE(hid);
-    ASSERT_TRUE(dap);
-    if(hid->readNB(&recv_report)) {
-        dap->Command(recv_report.data, send_report.data);
-        send_report.length = 64;
-        hid->send(&send_report);
-    }
-}
-
-static void hex_dump(uint8_t* buf, int size)
-{
-    for(int i = 0; i < size; i++) {
-        printf("%02x ", buf[i]);
-    }
-    printf("\n");
-}
-
-TEST(DAP2,forever1) {
-    while(1) {
-        if(hid->readNB(&recv_report)) {
-            //DBG("%02x", recv_report.data[0]);
-            hex_dump(recv_report.data, 32);
-            uint8_t cmd = recv_report.data[0];
-            dap->Command(recv_report.data, send_report.data);
-            send_report.length = 64;
-            uint8_t* buf = send_report.data;
-            DBG("%02x: %02x %02x %02x %02x %02x", cmd, buf[0], buf[1], buf[2], buf[3], buf[4]); 
-            bool r = hid->send(&send_report);
-            ASSERT_TRUE(r);
-        }
-    }    
-}
-
-int main() {
-    pc.baud(921600);
-    //pc.baud(9600);
-    DBG("%s", __FILE__);
-
-    RUN_ALL_TESTS();
-    exit(0);
-}
-#endif
--- a/tests/test2_Target2.cpp	Wed Sep 11 14:00:40 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,175 +0,0 @@
-// test2_Target2.cpp 2013/9/1
-#if 0
-#include "Target2.h"
-#include "mytest.h"
-
-Serial pc(USBTX, USBRX);
-Target2 target(p21,p22,p17,&pc); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
-
-TEST(Target2,setup) {
-    ASSERT_TRUE(target.setup());
-}
-
-TEST(Target2,readMemory1) {
-    uint32_t data = target.readMemory(0); // sp
-    ASSERT_TRUE(data == 0x10001000);
-}
-
-TEST(Target2,readMemory2) {
-    for(uint32_t addr = 0; addr < 0x1c; addr += 4) {
-        uint32_t data = target.readMemory(addr);
-        //TEST_PRINT("addr=%08x data=%08x\n", addr, data);
-    }
-}
-
-TEST(Target2,readMemory3) {
-    for(uint32_t addr = 0; addr < 0x100; addr += 4) {
-        uint32_t data = target.readMemory(addr);
-    }
-}
-
-TEST(Target2,DHCSR1) {
-    uint32_t data = target.readMemory(0xE000EDF0);
-    
-}
-
-TEST(Target2,getStatus1) {
-    int status = target.getStatus();
-    ASSERT_TRUE(status == TARGET_RUNNING);
-}
-
-TEST(Target2,halt1) {
-    target.halt();
-    int status = target.getStatus();
-    ASSERT_TRUE(status == TARGET_HALTED);
-}
-
-TEST(Target2,resume1) {
-    target.resume();
-    int status = target.getStatus();
-    ASSERT_TRUE(status == TARGET_RUNNING);
-}
-
-TEST(Target2,writeMemory1) {
-    uint32_t addr = 0x10000000;
-    target.halt();
-    int status = target.getStatus();
-    ASSERT_TRUE(status == TARGET_HALTED);
-
-    uint32_t data = target.readMemory(addr);
-    target.writeMemory(addr, 0x12345678);
-    ASSERT_TRUE(target.readMemory(addr) == 0x12345678);
-    target.writeMemory(addr, data);
-    ASSERT_TRUE(target.readMemory(addr) == data);
-
-    target.resume();
-    status = target.getStatus();
-    ASSERT_TRUE(status == TARGET_RUNNING);
-}
-
-TEST(Target2,writeMemory2) {
-    uint32_t addr = 0x10001000-4;
-    uint32_t data = target.readMemory(addr);
-    target.writeMemory(addr, 0x12345678);
-    ASSERT_TRUE(target.readMemory(addr) == 0x12345678);
-    target.writeMemory(addr, data);
-    ASSERT_TRUE(target.readMemory(addr) == data);
-}
-
-TEST(CoreReg,r0) {
-    uint32_t r0 = target.r0.read();
-}
-
-TEST(CoreReg,r1) {
-    target.halt();
-    uint32_t backup = target.r1.read();
-    target.r1.write(0x11223344);
-    uint32_t data = target.r1.read();
-    ASSERT_TRUE(data == 0x11223344);
-    target.r1.write(backup);
-    target.resume();
-}
-
-TEST(CoreReg,r2) {
-    target.halt();
-    uint32_t backup = target.r2;
-    target.r2 = 0x11223344;
-    ASSERT_TRUE(target.r2 == 0x11223344);
-    target.r2 = backup;
-    target.resume();
-}
-
-TEST(CoreReg,pc) {
-    uint32_t pc = target.pc.read();
-    //TEST_PRINT("pc=%08x\n", pc);
-}
-
-TEST(Target2,wait_status1) {
-    target.halt();
-    bool r = target.wait_status(TARGET_HALTED);
-    ASSERT_TRUE(r);
-    target.resume();
-    r = target.wait_status(TARGET_HALTED, 50);
-    ASSERT_TRUE(!r);
-}
-
-TEST(Target2,writeMemory3) {
-    target.halt();
-    bool r = target.wait_status(TARGET_HALTED);
-    ASSERT_TRUE(r);
-
-    uint8_t buf[256];
-    for(int i = 0; i < sizeof(buf); i++) {
-        buf[i] = i;
-    }
-    uint32_t addr = 0x10000000;
-    target.writeMemory(addr, (uint32_t*)buf, sizeof(buf)/sizeof(uint32_t));
-
-    uint8_t rbuf[256];
-    target.readMemory(addr, (uint32_t*)rbuf, sizeof(rbuf)/sizeof(uint32_t));
-
-    ASSERT_TRUE(memcmp(buf, rbuf, sizeof(buf)) == 0);
-}
-
-#define SYST_CSR 0xe000e010
-
-#define ICER  0xe000e180
-#define ICPR  0xe000e280
-
-#define CPUID 0xe000ed00
-#define ICSR  0xe000ed04
-
-TEST(Target2,test_SCB) {
-    target.resume();
-    for(int i = 0; i < 3; i++) {
-        uint32_t pc = target.pc.read();
-        TEST_PRINT("pc=%08x", pc);
-
-        uint32_t syst_csr = target.readMemory(SYST_CSR);
-        TEST_PRINT("SYST_CSR=%08x", syst_csr);
-        uint32_t icer = target.readMemory(ICER);
-        TEST_PRINT("ICER=%08x", icer);
-        uint32_t icpr = target.readMemory(ICPR);
-        TEST_PRINT("ICPR=%08x", icpr);
-        uint32_t cpuid = target.readMemory(CPUID);
-        TEST_PRINT("CPUID=%08x", cpuid);
-        uint32_t icsr = target.readMemory(ICSR);
-        TEST_PRINT("ICSR=%08x", icsr);
-    }
-    for(int i = 0; i < 100; i++) {
-        uint32_t syst_csr = target.readMemory(SYST_CSR);
-        if (syst_csr != 0) {
-            TEST_PRINT("SYST_CSR=%08x", syst_csr);
-            break;
-        }
-    }
-}
-
-int main() {
-    pc.baud(921600);
-    DBG("%s", __FILE__);
-
-    RUN_ALL_TESTS();
-}
-#endif
-
--- a/tests/test_Flash.cpp	Wed Sep 11 14:00:40 2013 +0000
+++ b/tests/test_Flash.cpp	Sat Sep 14 12:55:29 2013 +0000
@@ -167,7 +167,7 @@
     pc.baud(921600);
     DBG("%s", __FILE__);
 
-    target = new Target2(p21,p22,p17, &pc); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
+    target = new Target2(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
     target->setup();
     flash = new Flash(target, &pc);
 
--- a/tests/test_Semihost.cpp	Wed Sep 11 14:00:40 2013 +0000
+++ b/tests/test_Semihost.cpp	Sat Sep 14 12:55:29 2013 +0000
@@ -1,4 +1,4 @@
-// test_Semihost.cpp 2013/9/10
+// test_Semihost.cpp 2013/9/14
 #if 0
 #include "Semihost.h"
 #include "Flash.h"
@@ -6,7 +6,7 @@
 
 LocalFileSystem local("local");
 Serial pc(USBTX, USBRX);
-Target2 target(p21,p22,p17,&pc); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
+Target2 target(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
 Serial target_uart(p9,p10); // RXD(dp15),TXD(dp16)
 
 Semihost* sh;