Kazuki Yamamoto / Mbed 2 deprecated 11u35_usbLocalFilesystem Featured

Dependencies:   BaseDAP SWD USBDAP USBLocalFileSystem mbed DA14580 SWSPI W25X40BV

USB memory + Writer for DA14580 BLE chip + CMSIS-DAP debugger + USB-UART functions in one chip

One button input loads your application into DA14580 or DA14580 included BLE modules

Quote:

Current compatible hardware description can be found at https://github.com/K4zuki/da14580/releases/tag/MurataBLEr04

Files at this revision

API Documentation at this revision

Comitter:
k4zuki
Date:
Wed Aug 19 15:50:36 2015 +0000
Parent:
2:228291df190e
Child:
4:64a29271d7b8
Commit message:
update formatting

Changed in this revision

DA14580.lib Show annotated file Show diff for this revision Revisions of this file
DA14580/DA14580.cpp Show diff for this revision Revisions of this file
DA14580/DA14580.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DA14580.lib	Wed Aug 19 15:50:36 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/k4zuki/code/DA14580/#043522e836ab
--- a/DA14580/DA14580.cpp	Wed Aug 19 13:23:10 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,197 +0,0 @@
-#include "mbed.h"
-#include "DA14580.h"
-
-/*
-
-DigitalOut myled(LED1);
-
-Serial pc(USBTX,USBRX);
-Serial ble(p28,p27);
-
-LocalFileSystem local( "local" );
-
-#define     SOURCE_FILE         "/local/_loader"
-#define     TARGET_FILE         "/local/_bin"
-
-int file_size( FILE *fp );
-enum XMODEM_CONST{
-SOH = (0x01),
-STX = (0x02),
-EOT = (0x04),
-ACK = (0x06),
-DLE = (0x10),
-NAK = (0x15),
-CAN = (0x18),
-};
-*/
-DA14580::DA14580( PinName TX, PinName RX, PinName RESET ) : _ble(TX,RX), _reset(RESET)
-{
-    init();
-    ;
-}
-
-DA14580::DA14580( Serial &ble, PinName RESET ) : _ble(ble), _reset(RESET)
-{
-    init();
-    ;
-}
-
-void DA14580::init(){
-
-    _ble.baud(57600);
-    _crc = 0x00;
-    _recieve = 0;
-    _read = 0;
-    _filesize = 0;
-    _reset = 0;
-    _timeout = 100;
-    _status = SUCCESS;
-}
-
-int DA14580::load(){
-
-    _status = SUCCESS;
-
-    _fp = fopen( LOADER_FILE, "rb" );
-    if (_fp) {
-        _filesize = file_size(_fp);
-//        pc.printf("0x%04X\n\r",_filesize);
-        while((_timeout--) >0){
-            if( _ble.readable() ){
-                _recieve = _ble.getc();
-                if(_recieve == STX) {
-                    _ble.putc(SOH);
-//                    pc.putc('!');
-                    break;
-                }
-            }
-        }
-        if(_timeout <= 0){
-            _status = E_TIMEOUT_STX;
-        }else{
-            _timeout = 100;
-            _ble.putc(_filesize & 0xff);
-            _ble.putc( (_filesize >> 8) & 0xff);
-            while((_timeout--) >0){
-                if( _ble.readable() ){
-                    _recieve = _ble.getc();
-                    if(_recieve == ACK) {
-//                        pc.printf("ok!\n\r");
-                        break;
-                    }
-                }
-            }
-            if(_timeout <= 0){
-                _status = E_ACK_NOT_RETURNED;
-            }else{
-                _timeout = 100;
-                for(int i = 0; i < _filesize; i++){
-                    _read = getc(_fp);
-                    _ble.putc(_read);
-                    _crc = _crc ^ _read;
-                    if((i % 16) == 0){
-//                        pc.printf("\n\r");
-                    }
-//                    pc.printf("%02X ",_read);
-                }
-//                pc.printf("\n\r0x%02X ",_crc);
-                while((_timeout--) >0){
-                    if( _ble.readable() ){
-                        _recieve = _ble.getc();
-                        if(_recieve == _crc) {
-                            _ble.putc(ACK);
-//                            pc.printf("-=-=DONE=-=-\n\r");
-                            break;
-                        }
-                    }
-                }
-                if(_timeout <= 0){
-                    _status = E_ACK_NOT_RETURNED;
-                }
-            }
-        }
-        fclose(_fp);
-#if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler
-        free(_fp);
-#endif
-    }else{
-        _status = E_FILE_NOT_FOUND;
-    }
-    return _status;
-
-
-}
-
-int DA14580::file_size( FILE *fp )
-{
-    int     size;
-
-    fseek( fp, 0, SEEK_END ); // seek to end of file
-    size    = ftell( fp );    // get current file pointer
-    fseek( fp, 0, SEEK_SET ); // seek back to beginning of file
-
-    return size;
-}
-
-/*
-int main()
-{
-    uint8_t recieve;
-    uint8_t read;
-    int filesize=0;
-    FILE* fp;
-    ble.baud(57600);
-    int crc=0x00;
-
-    fp = fopen( SOURCE_FILE, "rb" );
-    if (fp) {
-        filesize=file_size(fp);
-        pc.printf("0x%04X\n\r",filesize);
-    }
-
-    while(1) {
-        recieve=ble.getc();
-        if(recieve == STX) {
-            ble.putc(SOH);
-            pc.putc('!');
-            break;
-        }
-    }
-    ble.putc(filesize&0xff);
-    ble.putc( (filesize>>8)&0xff);
-    while(1) {
-        recieve=ble.getc();
-        if(recieve == ACK) {
-            pc.printf("ok!\n\r");
-//            ble.putc(0x01);
-            break;
-        }
-    }
-    for(int i=0;i<filesize;i++){
-        read=getc(fp);
-        ble.putc(read);
-        crc=crc^read;
-        if((i%16)==0){
-            pc.printf("\n\r");
-        }
-        pc.printf("%02X ",read);
-    }
-    pc.printf("\n\r0x%02X ",crc);
-    while(1) {
-        recieve=ble.getc();
-        if(recieve == crc) {
-            ble.putc(ACK);
-            pc.printf("-=-=DONE=-=-\n\r");
-            break;
-        }
-    }
-    fclose(fp);
-    myled = 1;
-    while(1) {
-        recieve=ble.getc();
-        pc.putc(recieve);
-        wait_ms(20);
-    }
-}
-
-*/
--- a/DA14580/DA14580.h	Wed Aug 19 13:23:10 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,83 +0,0 @@
-/**
- * @file DA1458X.h
- * @brief DA1458X writer
- **/
-#ifndef DA1458X_H
-#define DA1458X_H
-
-#include "mbed.h"
-
-#define     LOADER_FILE         "/local/loader.bin"
-#define     TARGET_FILE         "/local/target.bin"
-
-/** \class DA14580
- * \brief mbed library for Dialog Semiconductor DA14580 Bluetooth LE chip
- *
- * Example:
- * @code
- * #include "mbed.h"
- * #include "DA14580.h"
- *
- * DA14580 BLE(P0_18, P0_19, P0_1);
- * Serial pc(USBTX, USBRX);
- *
- * int main()
- * {
- *    int result=0;
- *    pc.baud(115200);
- *
- *   wait_ms(1);
- *   fp = fopen( SOURCE_FILE, "rb" );
- *   result = BLE.load(fp);
- *   fclose(fp);
-#if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler
- *   free(fp);
-#endif
- *   pc.printf("Result = %d \n\r",&result);
- * }
- * @endcode
- */
-
-enum XMODEM_CONST {
-    SOH = (0x01),
-    STX = (0x02),
-    EOT = (0x04),
-    ACK = (0x06),
-    DLE = (0x10),
-    NAK = (0x15),
-    CAN = (0x18),
-};
-
-enum DA14580_STATUS{
-    SUCCESS,
-    E_NOT_CONNECTED,
-    E_FILE_NOT_FOUND,
-    E_TIMEOUT_STX,
-    E_ACK_NOT_RETURNED,
-    E_CRC_MISMATCH
-};
-
-class DA14580
-{
-public:
-    DA14580( PinName TX, PinName RX, PinName RESET );
-    DA14580( Serial &ble, PinName RESET );
-    ~DA14580();
-
-    void init();
-    int load();
-    int file_size( FILE *fp ); // copied from ika_shouyu_poppoyaki
-    RawSerial _ble;
-
-private:
-    uint8_t _recieve;
-    uint8_t _read;
-    int _filesize;
-    int _timeout;
-    int _status;
-    FILE* _fp;
-    int _crc;
-    DigitalInOut _reset;
-};
-
-#endif //DA1458X_H
--- a/main.cpp	Wed Aug 19 13:23:10 2015 +0000
+++ b/main.cpp	Wed Aug 19 15:50:36 2015 +0000
@@ -3,6 +3,7 @@
 #include "USBDAP.h"
 #include "BaseDAP.h"
 #include "USB_HID.h"
+#include "DA14580.h"
 
 #include "at45db161d.h"
 
@@ -18,6 +19,9 @@
 #define WRITE_BUFFER 1
 #define READ_BUFFER 2
 
+#define     LOADER_FILE         "/local/loader.bin"
+#define     TARGET_FILE         "/local/target.bin"
+
 //SWD swd(p25,p24,p23); // SWDIO,SWCLK,nRESET
 SWD swd(P0_5,P0_4,P0_21); // SWDIO,SWCLK,nRESET
 DigitalOut connected(P0_20);
@@ -25,24 +29,13 @@
 
 SPI spi(P0_9,P0_8,P0_10); // mosi, miso, sclk
 ATD45DB161D memory(spi, P0_7);
-Serial ble(P0_19,P0_18);
+RawSerial ble(P0_19,P0_18);
+DA14580 BLE(ble, P0_1);
 
-#define     SOURCE_FILE         "/local/loader.bin"
-#define     TARGET_FILE         "/local/target.bin"
 int file_size( FILE *fp );
 void flash_write (int addr, char *buf, int len);
 void flash_read (int addr, char *buf, int len);
 
-enum XMODEM_CONST {
-    SOH = (0x01),
-    STX = (0x02),
-    EOT = (0x04),
-    ACK = (0x06),
-    DLE = (0x10),
-    NAK = (0x15),
-    CAN = (0x18),
-};
-
 class myDAP : public BaseDAP
 {
 public:
@@ -77,10 +70,14 @@
 //    int crc=0x00;
 
 
+    int result=0;
     while(1) {
         usb_local->lock(true);
         usb_local->remount();
         char filename[32];
+
+        result = BLE.load();
+        usb_local->putc(result);
         /*
         fp = fopen( SOURCE_FILE, "rb" )
         if (fp) {
@@ -97,13 +94,13 @@
                 }
                 fclose(fp);
 #if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler
+#warning "free(fp)"
                 free(fp);
 #endif
             }
         }
 
 
-        usb_local->lock(false);
         USBStorage2* _usb = usb_local->getUsb();
         USB_HID* _hid = _usb->getHID();
         HID_REPORT recv_report;
@@ -113,7 +110,8 @@
             send_report.length = 64;
             _usb->send(&send_report);
         }
-        wait_ms(100*5);
+        usb_local->lock(false);
+        wait_ms(1000*5);
     }
 }
 
@@ -129,7 +127,8 @@
 }
 
 
-void flash_write (int addr, char *buf, int len) {
+void flash_write (int addr, char *buf, int len)
+{
     int i;
     memory.BufferWrite(WRITE_BUFFER, addr % PAGE_SIZE);
     for (i = 0; i < len; i ++) {
@@ -138,7 +137,8 @@
     memory.BufferToPage(WRITE_BUFFER, addr / PAGE_SIZE, 1);
 }
 
-void flash_read (int addr, char *buf, int len) {
+void flash_read (int addr, char *buf, int len)
+{
     int i;
     memory.PageToBuffer(addr / PAGE_SIZE, READ_BUFFER);
     memory.BufferRead(READ_BUFFER, addr % PAGE_SIZE, 1);