![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
USB composite device example program, drag-and-drop flash writer.
Dependencies: SWD USBDevice mbed BaseDAP
Diff: Target2.cpp
- Revision:
- 1:ea8e179320d7
- Parent:
- 0:2385683c867a
diff -r 2385683c867a -r ea8e179320d7 Target2.cpp --- a/Target2.cpp Tue Sep 17 04:33:44 2013 +0000 +++ b/Target2.cpp Sat Sep 28 03:21:14 2013 +0000 @@ -1,4 +1,4 @@ -// Target2.cpp 2013/9/17 +// Target2.cpp 2013/9/23 #include "Target2.h" #include "mydebug.h" @@ -18,7 +18,17 @@ #define FP_COMP0 (0xE0002008) Target2::Target2(PinName swdio, PinName swclk, PinName reset) - : _swd(swdio, swclk, reset) +{ + _swd = new SWD(swdio, swclk, reset); + inst(); +} + +Target2::Target2(SWD* swd) : _swd(swd) +{ + inst(); +} + +void Target2::inst() { r0.setup(this, 0); r1.setup(this, 1); @@ -41,47 +51,46 @@ bool Target2::setup() { - _swd.Setup(); + _swd->Setup(); JTAG2SWD(); uint32_t data; - uint8_t ack = _swd.Transfer(DP_IDCODE, &data); + uint8_t ack = _swd->Transfer(DP_IDCODE, &data); TEST_ASSERT(ack == SWD_OK); if (ack != SWD_OK) { return false; } idcode = data; - //TEST_ASSERT(data == 0x0bb11477); Abort(); data = 0x0; - ack = _swd.Transfer(DP_SELECT, &data); + ack = _swd->Transfer(DP_SELECT, &data); TEST_ASSERT(ack == SWD_OK); if (ack != SWD_OK) { return false; } - ack = _swd.Transfer(DP_RDBUFF, &data); + ack = _swd->Transfer(DP_RDBUFF, &data); TEST_ASSERT(ack == SWD_OK); if (ack != SWD_OK) { return false; } data = CSYSPWRUPREQ | CDBGPWRUPREQ; - ack = _swd.Transfer(DP_CTRL_STAT, &data); + ack = _swd->Transfer(DP_CTRL_STAT, &data); TEST_ASSERT(ack == SWD_OK); if (ack != SWD_OK) { return false; } - ack = _swd.Transfer(DP_RDBUFF, &data); + ack = _swd->Transfer(DP_RDBUFF, &data); TEST_ASSERT(ack == SWD_OK); if (ack != SWD_OK) { return false; } - ack = _swd.Transfer(DP_CTRL_STAT_R, &data); + ack = _swd->Transfer(DP_CTRL_STAT_R, &data); TEST_ASSERT(ack == SWD_OK); if (ack != SWD_OK) { return false; @@ -89,26 +98,26 @@ TEST_ASSERT(data == 0xf0000040); data = CSYSPWRUPREQ | CDBGPWRUPREQ | 0x04000000; - ack = _swd.Transfer(DP_CTRL_STAT, &data); + ack = _swd->Transfer(DP_CTRL_STAT, &data); TEST_ASSERT(ack == SWD_OK); if (ack != SWD_OK) { return false; } - ack = _swd.Transfer(DP_RDBUFF, &data); + ack = _swd->Transfer(DP_RDBUFF, &data); TEST_ASSERT(ack == SWD_OK); if (ack != SWD_OK) { return false; } data = CSYSPWRUPREQ | CDBGPWRUPREQ | MASKLANE; - ack = _swd.Transfer(DP_CTRL_STAT, &data); + ack = _swd->Transfer(DP_CTRL_STAT, &data); TEST_ASSERT(ack == SWD_OK); if (ack != SWD_OK) { return false; } - ack = _swd.Transfer(DP_RDBUFF, &data); + ack = _swd->Transfer(DP_RDBUFF, &data); TEST_ASSERT(ack == SWD_OK); if (ack != SWD_OK) { return false; @@ -118,7 +127,7 @@ void Target2::SWJClock(uint32_t clock_hz) { - _swd.SWJClock(clock_hz); + _swd->SWJClock(clock_hz); } void Target2::JTAG2SWD() @@ -126,16 +135,16 @@ 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); + _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 - _swd.SWJPins(0x80, 0x80); // nReset on + _swd->SWJPins(0x00, 0x80); // nReset off + _swd->SWJPins(0x80, 0x80); // nReset on } void Target2::SoftwareReset() @@ -148,10 +157,10 @@ _setaddr(addr); uint32_t data; - uint8_t ack = _swd.Transfer(AP_DRW_R, &data); // dummy read + uint8_t ack = _swd->Transfer(AP_DRW_R, &data); // dummy read TEST_ASSERT(ack == SWD_OK); - ack = _swd.Transfer(DP_RDBUFF, &data); + ack = _swd->Transfer(DP_RDBUFF, &data); TEST_ASSERT(ack == SWD_OK); return data; } @@ -164,14 +173,14 @@ _setaddr(addr); - uint8_t ack = _swd.Transfer(AP_DRW_R, NULL); // dummy read + uint8_t ack = _swd->Transfer(AP_DRW_R, NULL); // dummy read TEST_ASSERT(ack == SWD_OK); for(int i = 0; i < count-1; i++) { - ack = _swd.Transfer(AP_DRW_R, data++); + ack = _swd->Transfer(AP_DRW_R, data++); TEST_ASSERT(ack == SWD_OK); } - ack = _swd.Transfer(DP_RDBUFF, data); + ack = _swd->Transfer(DP_RDBUFF, data); TEST_ASSERT(ack == SWD_OK); } @@ -185,7 +194,7 @@ _setaddr(addr); while(count-- > 0) { - uint8_t ack = _swd.Transfer(AP_DRW_W, data); + uint8_t ack = _swd->Transfer(AP_DRW_W, data); TEST_ASSERT(ack == SWD_OK); data++; } @@ -196,10 +205,10 @@ _setaddr8(addr); uint32_t data32; - uint8_t ack = _swd.Transfer(AP_DRW_R, &data32); // dummy read + uint8_t ack = _swd->Transfer(AP_DRW_R, &data32); // dummy read TEST_ASSERT(ack == SWD_OK); - ack = _swd.Transfer(DP_RDBUFF, &data32); + ack = _swd->Transfer(DP_RDBUFF, &data32); TEST_ASSERT(ack == SWD_OK); return (data32 >> ((addr & 0x03) << 3)) & 0xff; } @@ -210,46 +219,46 @@ uint32_t data32 = data; data32 <<= ((addr & 0x03) << 3); - uint8_t ack = _swd.Transfer(AP_DRW_W, &data32); + uint8_t ack = _swd->Transfer(AP_DRW_W, &data32); TEST_ASSERT(ack == SWD_OK); } void Target2::_setaddr(uint32_t addr) { uint32_t ctl = CSW_VALUE|CSW_SIZE32; - uint8_t ack = _swd.Transfer(AP_CSW, &ctl); + uint8_t ack = _swd->Transfer(AP_CSW, &ctl); TEST_ASSERT(ack == SWD_OK); - ack = _swd.Transfer(DP_RDBUFF, NULL); + ack = _swd->Transfer(DP_RDBUFF, NULL); TEST_ASSERT(ack == SWD_OK); - ack = _swd.Transfer(AP_TAR, &addr); + ack = _swd->Transfer(AP_TAR, &addr); TEST_ASSERT(ack == SWD_OK); - ack = _swd.Transfer(DP_RDBUFF, NULL); + ack = _swd->Transfer(DP_RDBUFF, NULL); TEST_ASSERT(ack == SWD_OK); } void Target2::_setaddr8(uint32_t addr) { uint32_t ctl = CSW_VALUE|CSW_SIZE8; - uint8_t ack = _swd.Transfer(AP_CSW, &ctl); + uint8_t ack = _swd->Transfer(AP_CSW, &ctl); TEST_ASSERT(ack == SWD_OK); - ack = _swd.Transfer(DP_RDBUFF, NULL); + ack = _swd->Transfer(DP_RDBUFF, NULL); TEST_ASSERT(ack == SWD_OK); - ack = _swd.Transfer(AP_TAR, &addr); + ack = _swd->Transfer(AP_TAR, &addr); TEST_ASSERT(ack == SWD_OK); - ack = _swd.Transfer(DP_RDBUFF, NULL); + ack = _swd->Transfer(DP_RDBUFF, NULL); TEST_ASSERT(ack == SWD_OK); } void Target2::Abort() { uint32_t data = 0x1e; - uint8_t ack = _swd.Transfer(DP_ABORT, &data); + uint8_t ack = _swd->Transfer(DP_ABORT, &data); TEST_ASSERT(ack == SWD_OK); }