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
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
Revision 2:228291df190e, committed 2015-08-19
- Comitter:
- k4zuki
- Date:
- Wed Aug 19 13:23:10 2015 +0000
- Parent:
- 1:484bd6db1378
- Child:
- 3:6af8771e7f71
- Commit message:
- 11U35 CMSIS-DAP; add DA14580.h/.cpp
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DA14580/DA14580.cpp Wed Aug 19 13:23:10 2015 +0000
@@ -0,0 +1,197 @@
+#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);
+ }
+}
+
+*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DA14580/DA14580.h Wed Aug 19 13:23:10 2015 +0000
@@ -0,0 +1,83 @@
+/**
+ * @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/USBLocalFileSystem.lib Tue Aug 18 17:41:45 2015 +0000 +++ b/USBLocalFileSystem.lib Wed Aug 19 13:23:10 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/k4zuki/code/USBLocalFileSystem/#9c95f21a578d +https://developer.mbed.org/users/k4zuki/code/USBLocalFileSystem/#69413260c643
--- a/main.cpp Tue Aug 18 17:41:45 2015 +0000
+++ b/main.cpp Wed Aug 19 13:23:10 2015 +0000
@@ -18,14 +18,14 @@
#define WRITE_BUFFER 1
#define READ_BUFFER 2
-SWD swd(p25,p24,p23); // SWDIO,SWCLK,nRESET
-//SWD swd(P0_5,P0_4,P0_21); // SWDIO,SWCLK,nRESET
+//SWD swd(p25,p24,p23); // SWDIO,SWCLK,nRESET
+SWD swd(P0_5,P0_4,P0_21); // SWDIO,SWCLK,nRESET
DigitalOut connected(P0_20);
-DigitalOut running(P0_21);
+DigitalOut running(P0_2);
-//SPI spi(P0_9,P0_8,P0_10); // mosi, miso, sclk
-//ATD45DB161D memory(spi, P0_7);
-//Serial ble(P0_19,P0_18);
+SPI spi(P0_9,P0_8,P0_10); // mosi, miso, sclk
+ATD45DB161D memory(spi, P0_7);
+Serial ble(P0_19,P0_18);
#define SOURCE_FILE "/local/loader.bin"
#define TARGET_FILE "/local/target.bin"
@@ -83,7 +83,7 @@
char filename[32];
/*
fp = fopen( SOURCE_FILE, "rb" )
- if ( fp) {
+ if (fp) {
filesize=file_size(fp);
pc.printf("0x%04X\n\r",filesize);
}
@@ -107,11 +107,11 @@
USBStorage2* _usb = usb_local->getUsb();
USB_HID* _hid = _usb->getHID();
HID_REPORT recv_report;
- if( _hid->readNB(&recv_report) ) {
+ if( _usb->readNB(&recv_report) ) {
HID_REPORT send_report;
dap->Command(recv_report.data, send_report.data);
send_report.length = 64;
- _hid->send(&send_report);
+ _usb->send(&send_report);
}
wait_ms(100*5);
}