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 1:484bd6db1378, committed 2015-08-18
- Comitter:
- k4zuki
- Date:
- Tue Aug 18 17:41:45 2015 +0000
- Parent:
- 0:eba731be11fb
- Child:
- 2:228291df190e
- Commit message:
- Mixed up BLE writer and Flash read/writer (both still unused)
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/at45db161d.lib Tue Aug 18 17:41:45 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/okini3939/code/at45db161d/#b379e16fdf6f
--- a/main.cpp Mon Aug 17 19:20:25 2015 +0000
+++ b/main.cpp Tue Aug 18 17:41:45 2015 +0000
@@ -4,9 +4,44 @@
#include "BaseDAP.h"
#include "USB_HID.h"
+#include "at45db161d.h"
+
+#undef PAGE_SIZE
+//#define PAGE_SIZE 264 // AT45DB081D (1MB)
+#define PAGE_SIZE 256 // AT25XE011 (1Mbit)
+//#define PAGE_SIZE 528 // AT45DB321D (4MB)
+
+//#define PAGE_NUM 4095 // AT45DB081D (1MB)
+#define PAGE_NUM 512 // AT25XE011 (1Mbit)
+//#define PAGE_NUM 8192 // AT45DB321D (4MB)
+
+#define WRITE_BUFFER 1
+#define READ_BUFFER 2
+
SWD swd(p25,p24,p23); // SWDIO,SWCLK,nRESET
-DigitalOut connected(LED1);
-DigitalOut running(LED2);
+//SWD swd(P0_5,P0_4,P0_21); // SWDIO,SWCLK,nRESET
+DigitalOut connected(P0_20);
+DigitalOut running(P0_21);
+
+//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"
+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
{
@@ -26,20 +61,35 @@
}
};
+
int main()
{
USBLocalFileSystem* usb_local = new USBLocalFileSystem(P0_9, P0_8, P0_10, P0_7,"local"); // RamDisk(64KB)
+// USBLocalFileSystem* usb_local = new USBLocalFileSystem(P0_14, P0_15, P0_16, P0_32,"local"); // SD
+ usb_local->lock(true);
myDAP* dap = new myDAP(&swd);
-// USBStorage2* _usb = usb_local->getUsb();
-// USB_HID* _hid = _usb->getHID();
+// uint8_t recieve;
+// uint8_t read;
+// int filesize=0;
+ FILE* fp;
+// ble.baud(57600);
+// int crc=0x00;
+
while(1) {
usb_local->lock(true);
usb_local->remount();
char filename[32];
+ /*
+ fp = fopen( SOURCE_FILE, "rb" )
+ if ( fp) {
+ filesize=file_size(fp);
+ pc.printf("0x%04X\n\r",filesize);
+ }
+ */
if (usb_local->find(filename, sizeof(filename), "*.TXT")) {
- FILE* fp = fopen(filename, "r");
+ fp = fopen(filename, "r");
if (fp) {
int c;
while((c = fgetc(fp)) != EOF) {
@@ -52,15 +102,48 @@
}
}
+
+ usb_local->lock(false);
+ USBStorage2* _usb = usb_local->getUsb();
+ USB_HID* _hid = _usb->getHID();
HID_REPORT recv_report;
- if( usb_local->getUsb()->getHID()->readNB(&recv_report) ) {
+ if( _hid->readNB(&recv_report) ) {
HID_REPORT send_report;
dap->Command(recv_report.data, send_report.data);
send_report.length = 64;
- usb_local->getUsb()->getHID()->send(&send_report);
+ _hid->send(&send_report);
}
-
- usb_local->lock(false);
wait_ms(100*5);
}
-}
\ No newline at end of file
+}
+
+int 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;
+}
+
+
+void flash_write (int addr, char *buf, int len) {
+ int i;
+ memory.BufferWrite(WRITE_BUFFER, addr % PAGE_SIZE);
+ for (i = 0; i < len; i ++) {
+ spi.write(buf[i]);
+ }
+ memory.BufferToPage(WRITE_BUFFER, addr / PAGE_SIZE, 1);
+}
+
+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);
+ for (i = 0; i < len; i ++) {
+ buf[i] = spi.write(0xff);
+ }
+}
+
--- a/mbed.bld Mon Aug 17 19:20:25 2015 +0000 +++ b/mbed.bld Tue Aug 18 17:41:45 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/b9ad9a133dc7 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/8ed44a420e5c \ No newline at end of file