sakura.io file download example for mbed LPC1768
Revision 0:a5e8e3df9f1d, committed 2018-05-21
- Comitter:
- misodengaku
- Date:
- Mon May 21 05:07:42 2018 +0000
- Child:
- 1:b744d5683139
- Commit message:
- init
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Mon May 21 05:07:42 2018 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Mon May 21 05:07:42 2018 +0000 @@ -0,0 +1,87 @@ +# Getting started with Blinky on mbed OS + +This guide reviews the steps required to get Blinky working on an mbed OS platform. + +Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). + +## Import the example application + +From the command-line, import the example: + +``` +mbed import mbed-os-example-blinky +cd mbed-os-example-blinky +``` + +### Now compile + +Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: + +``` +mbed compile -m K64F -t ARM +``` + +Your PC may take a few minutes to compile your code. At the end, you see the following result: + +``` +[snip] ++----------------------------+-------+-------+------+ +| Module | .text | .data | .bss | ++----------------------------+-------+-------+------+ +| Misc | 13939 | 24 | 1372 | +| core/hal | 16993 | 96 | 296 | +| core/rtos | 7384 | 92 | 4204 | +| features/FEATURE_IPV4 | 80 | 0 | 176 | +| frameworks/greentea-client | 1830 | 60 | 44 | +| frameworks/utest | 2392 | 512 | 292 | +| Subtotals | 42618 | 784 | 6384 | ++----------------------------+-------+-------+------+ +Allocated Heap: unknown +Allocated Stack: unknown +Total Static RAM memory (data + bss): 7168 bytes +Total RAM memory (data + bss + heap + stack): 7168 bytes +Total Flash memory (text + data + misc): 43402 bytes +Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin +``` + +### Program your board + +1. Connect your mbed device to the computer over USB. +1. Copy the binary file to the mbed device. +1. Press the reset button to start the program. + +The LED on your platform turns on and off. + +## Export the project to Keil MDK, and debug your application + +From the command-line, run the following command: + +``` +mbed export -m K64F -i uvision +``` + +To debug the application: + +1. Start uVision. +1. Import the uVision project generated earlier. +1. Compile your application, and generate an `.axf` file. +1. Make sure uVision is configured to debug over CMSIS-DAP (From the Project menu > Options for Target '...' > Debug tab > Use CMSIS-DAP Debugger). +1. Set breakpoints, and start a debug session. + + + +## Troubleshooting + +1. Make sure `mbed-cli` is working correctly and its version is `>1.0.0` + + ``` + mbed --version + ``` + + If not, you can update it: + + ``` + pip install mbed-cli --upgrade + ``` + +2. If using Keil MDK, make sure you have a license installed. [MDK-Lite](http://www.keil.com/arm/mdk.asp) has a 32 KB restriction on code size. \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SakuraIO.lib Mon May 21 05:07:42 2018 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/teams/SAKURA-Internet/code/SakuraIO/#70faddd6241b
Binary file img/uvision.png has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon May 21 05:07:42 2018 +0000
@@ -0,0 +1,143 @@
+#include "mbed.h"
+#include "SakuraIO.h"
+
+Serial pc(USBTX, USBRX);
+DigitalOut myled(LED1);
+LocalFileSystem local("local");
+
+void rx_interrupt();
+void err2str(int err);
+
+int main()
+{
+ FILE *fp ;
+ pc.baud(115200);
+ fp = fopen("/local/file.bin", "wb");
+ if (fp == NULL) {
+ pc.printf("error: fp is null\r\n");
+ }
+
+ I2C i2c(p9, p10);
+ SakuraIO_I2C sakuraio(i2c);
+
+ pc.printf("waiting to come online");
+ for (;;) {
+ if ((sakuraio.getConnectionStatus() & 0x80) == 0x80)
+ break;
+ pc.printf(".");
+ wait_ms(1000);
+ }
+ pc.printf("ok\r\n");
+
+ uint8_t status = 0;
+ while (status != 1) {
+ status = sakuraio.startFileDownload(1);
+ pc.printf("file req result: %d\r\n", status);
+ if (status != CMD_ERROR_NONE) {
+ err2str(status);
+ pc.printf("\r\n");
+ }
+ wait_ms(100);
+ pc.printf("cancel\r\n");
+ uint8_t cancel_result = sakuraio.cancelFileDownload();
+ err2str(cancel_result);
+ pc.printf("\r\n");
+ wait_ms(100);
+ }
+
+
+
+ uint32_t received_size = 0;
+
+ uint8_t file_status = 0;
+ uint32_t file_total_size = 0, file_crc32 = 0;
+ uint64_t file_timestamp = 0;
+ while(file_status == 0) {
+
+ sakuraio.getFileMetaData(&file_status, &file_total_size, &file_timestamp, &file_crc32);
+
+ pc.printf("metadata status: %d filesize: %d crc32: %08x\r\n", file_status, file_total_size, file_crc32);
+
+ pc.printf("date ");
+ for (int i = 0; i < 8; i++) {
+ pc.printf("%02x ", ((uint8_t *)&file_timestamp)[i]);
+ }
+ pc.printf("\r\n");
+ wait(1);
+ }
+
+ while (1) {
+ status = 0;
+ uint32_t s = 0;
+ uint8_t a = sakuraio.getFileDownloadStatus(&status, &s);
+ pc.printf("result: ");
+ err2str(a);
+ pc.printf("status %d size %d\r\n", status, s);
+ wait_ms(500);
+
+ uint8_t buf[255] = {0};
+ uint8_t len = 251; // request size
+ uint8_t fileget = sakuraio.getFileData(&len, buf);
+// if (fileget != cmd_error_none) {
+// pc.printf("download waiting...\r\n");
+// wait_ms(1000);
+// continue;
+// //break;
+// }
+
+ pc.printf("file get ");
+ err2str(fileget);
+ if (fileget != 1) {
+ pc.printf("error: get_data returned invalid status\r\n");
+ while(1) {
+ wait(1);
+ }
+ }
+ pc.printf("len %d\r\n", len);
+ received_size += len;
+ pc.printf("received %08x\r\n", len);
+ for (int i = 0; i < len; i++) {
+ pc.printf("%02x ", buf[i]);
+ }
+ fwrite(buf, len, 1, fp);
+ pc.printf("\r\n");
+ pc.printf("%d / %d (%f%%)\r\n", received_size, file_total_size, ((double)received_size / file_total_size) * 100);
+ if (received_size >= file_total_size) {
+ break;
+ }
+ wait_ms(100);
+ }
+ fclose(fp);
+ pc.printf("download complete!\r\n");
+
+ // block
+ while (1)
+ ;
+}
+
+void err2str(int err)
+{
+ switch (err) {
+ case CMD_ERROR_NONE:
+ printf("no error.");
+ break;
+ case CMD_ERROR_PARITY:
+ printf("parity error.");
+ break;
+ case CMD_ERROR_MISSING:
+ printf("command missing.");
+ break;
+ case CMD_ERROR_INVALID_SYNTAX:
+ printf("invalid syntax.");
+ break;
+ case CMD_ERROR_RUNTIME:
+ printf("runtime error.");
+ break;
+ case CMD_ERROR_LOCKED:
+ printf("command locked.");
+ break;
+ case CMD_ERROR_BUSY:
+ printf("busy.");
+ break;
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon May 21 05:07:42 2018 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/6213f644d804 \ No newline at end of file
SAKURA Internet