Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BaseDAP SWD USBDAP USBLocalFileSystem mbed DA14580 SWSPI W25X40BV
main.cpp
00001 #include "mbed.h" 00002 #include "USBLocalFileSystem.h" 00003 #include "BaseDAP.h" 00004 #include "USB_HID.h" 00005 #include "DA14580.h" 00006 #include "W25X40BV.h" 00007 //#include "loader.h" 00008 #include "mystorage.h" 00009 00010 /** r0.4_aef7891 00011 - UART - 00012 TX = P0_19 00013 RX = P0_18 00014 - SWD - 00015 SWDIO = P0_14 00016 SWCLK = P0_13 00017 NSRST = P0_2 00018 TGT_RST = P1_19 00019 - SPI Flash - 00020 MOSI = P0_16 00021 MISO = P0_23 00022 SCK = P0_15 00023 CS = P1_15 00024 - 580 - 00025 MOSI = P0_9 00026 MISO = P0_7 00027 SCK = P0_8 00028 CS = P0_21 00029 - LED - 00030 RED = P0_5 00031 GREEN = P0_4 00032 BLUE = P0_20 00033 */ 00034 00035 #undef LOADER_FILE 00036 #define LOADER_FILE "/local/loader.bin" 00037 00038 #undef TARGET_FILE 00039 #define TARGET_FILE "/local/target.bin" 00040 00041 /* 00042 - SWD - 00043 SWDIO = P0_14 00044 SWCLK = P0_13 00045 NSRST = P0_2 00046 TGT_RST = P1_19 00047 */ 00048 SWD swd(P0_14, P0_13, P0_2); // SWDIO,SWCLK,nRESET 00049 InterruptIn TGT_RST_IN(P1_19); 00050 volatile bool isISP = false; 00051 void TGT_RST_IN_int(); 00052 00053 /* 00054 - LED - 00055 RED = P0_5 00056 GREEN = P0_4 00057 BLUE = P0_20 00058 */ 00059 DigitalOut connected(P0_5); 00060 DigitalOut running(P0_4); 00061 00062 /* 00063 - UART - 00064 TX = P0_19 00065 RX = P0_18 00066 */ 00067 DA14580 BLE(P0_19, P0_18, P0_2); // TX, RX, RESET 00068 00069 int file_size( FILE *fp ); 00070 00071 class myDAP : public BaseDAP 00072 { 00073 public: 00074 myDAP(SWD* swd):BaseDAP(swd) {}; 00075 virtual void infoLED(int select, int value) { 00076 switch(select) { 00077 case 0: 00078 connected = value^1; 00079 running = 1; 00080 break; 00081 case 1: 00082 running = value^1; 00083 connected = 1; 00084 break; 00085 } 00086 } 00087 }; 00088 00089 /* 00090 - SPI Flash - 00091 MOSI = P0_16 00092 MISO = P0_23 00093 SCK = P0_15 00094 CS = P1_15 00095 */ 00096 MyStorage LocalFS(P0_16, P0_23, P0_15, P1_15); // mosi, miso, sclk, cs 00097 int main() 00098 { 00099 USBLocalFileSystem* usb_local = new USBLocalFileSystem(&LocalFS, "local"); 00100 //PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name 00101 00102 USB_HID* _hid = usb_local->getUsb()->getHID(); 00103 HID_REPORT recv_report; 00104 HID_REPORT send_report; 00105 myDAP* dap = new myDAP(&swd); 00106 00107 running.write(1); 00108 TGT_RST_IN.mode(PullUp); 00109 char* STAT_MSG[6]={ 00110 "SUCCESS", 00111 "NOT CONNECTED", 00112 "FILE NOT FOUND", 00113 "STX TIMEOUT", 00114 "NO ACKNOWLEDGE", 00115 "CRC MISMATCHED" 00116 }; 00117 00118 00119 TGT_RST_IN.mode(PullUp); 00120 TGT_RST_IN.fall(&TGT_RST_IN_int); 00121 int result = 0; 00122 00123 bool _hidresult; 00124 usb_local->lock(false); 00125 while(1) { 00126 usb_local->lock(true); 00127 usb_local->remount(); 00128 connected.write(1); 00129 00130 if(isISP) { 00131 running.write(0); 00132 result = BLE.load(TARGET_FILE); 00133 running.write(1); 00134 usb_local->puts(STAT_MSG[result]); 00135 usb_local->putc(0x07); //bell 00136 usb_local->puts("\n\r"); 00137 isISP = false; 00138 } 00139 usb_local->lock(false); 00140 _hidresult = _hid->readNB(&recv_report); 00141 if( _hidresult ) { 00142 00143 dap->Command(recv_report.data, send_report.data); 00144 send_report.length = 64; 00145 _hid->send(&send_report); 00146 } 00147 if(BLE._ble.readable()) { 00148 usb_local->putc(BLE._ble.getc()); 00149 } 00150 wait_us(1000); 00151 connected = 0; 00152 } 00153 } 00154 00155 int file_size( FILE *fp ) 00156 { 00157 int size; 00158 00159 fseek( fp, 0, SEEK_END ); // seek to end of file 00160 size = ftell( fp ); // get current file pointer 00161 fseek( fp, 0, SEEK_SET ); // seek back to beginning of file 00162 00163 return size; 00164 } 00165 00166 void TGT_RST_IN_int() 00167 { 00168 isISP = true; 00169 }
Generated on Mon Jul 25 2022 10:58:37 by
1.7.2