semihost server example program
Dependencies: SWD mbed USBLocalFileSystem BaseDAP USBDAP
test2_BaseDAP.cpp
00001 // test2_BaseDAP.cpp 2013/9/13 00002 #if 0 00003 #include "BaseDAP.h" 00004 #include "USBDAP.h" 00005 #include "mytest.h" 00006 #include "mydebug.h" 00007 00008 Serial pc(USBTX, USBRX); 00009 00010 #ifdef TARGET_LPC1768 00011 SWD swd(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23) 00012 DigitalOut connected(LED1); 00013 DigitalOut running(LED2); 00014 class myDAP : public BaseDAP { 00015 public: 00016 myDAP(SWD* swd):BaseDAP(swd){}; 00017 virtual void infoLED(int select, int value) { 00018 switch(select) { 00019 case 0: connected = value; break; 00020 case 1: running = value; break; 00021 } 00022 } 00023 }; 00024 #endif 00025 00026 #ifdef TARGET_KL25Z 00027 SWD swd(PTB8,PTB9,PTB10); // SWDIO(dp12),SWCLK(dp3),nReset(dp23) 00028 DigitalOut connected(LED_GREEN); 00029 DigitalOut running(LED_RED); 00030 class myDAP : public BaseDAP { 00031 public: 00032 myDAP(SWD* swd):BaseDAP(swd){}; 00033 virtual void infoLED(int select, int value) { 00034 switch(select) { 00035 case 0: 00036 connected = value^1; 00037 running = 1; 00038 break; 00039 case 1: 00040 running = value^1; 00041 connected = 1; 00042 break; 00043 } 00044 } 00045 }; 00046 #endif 00047 00048 myDAP* dap = NULL; 00049 USBDAP* hid = NULL; 00050 00051 HID_REPORT send_report; 00052 HID_REPORT recv_report; 00053 00054 TEST(DAP2,setup2) { 00055 dap = new myDAP(&swd); 00056 } 00057 00058 TEST(DAP2,setup3) { 00059 hid = new USBDAP(64, 64, 0x0d28, 0x0204); 00060 } 00061 00062 TEST(DAP2,test1) { 00063 ASSERT_TRUE(hid); 00064 ASSERT_TRUE(dap); 00065 if(hid->readNB(&recv_report)) { 00066 dap->Command(recv_report.data, send_report.data); 00067 send_report.length = 64; 00068 hid->send(&send_report); 00069 } 00070 } 00071 00072 static void hex_dump(uint8_t* buf, int size) 00073 { 00074 for(int i = 0; i < size; i++) { 00075 printf("%02x ", buf[i]); 00076 } 00077 printf("\n"); 00078 } 00079 00080 TEST(DAP2,forever1) { 00081 while(1) { 00082 if(hid->readNB(&recv_report)) { 00083 //DBG("%02x", recv_report.data[0]); 00084 hex_dump(recv_report.data, 32); 00085 uint8_t cmd = recv_report.data[0]; 00086 dap->Command(recv_report.data, send_report.data); 00087 send_report.length = 64; 00088 uint8_t* buf = send_report.data; 00089 DBG("%02x: %02x %02x %02x %02x %02x", cmd, buf[0], buf[1], buf[2], buf[3], buf[4]); 00090 bool r = hid->send(&send_report); 00091 ASSERT_TRUE(r); 00092 } 00093 } 00094 } 00095 00096 int main() { 00097 pc.baud(921600); 00098 //pc.baud(9600); 00099 DBG("%s", __FILE__); 00100 00101 RUN_ALL_TESTS(); 00102 exit(0); 00103 } 00104 #endif
Generated on Wed Jul 13 2022 16:56:23 by 1.7.2