Sakura.io LTE module firmware updater.

Dependencies:   SakuraIO mbed

Firmware updater for sakura.io LTE module.

Files at this revision

API Documentation at this revision

Comitter:
key3
Date:
Fri Apr 21 08:23:40 2017 +0000
Commit message:
sakura.io LTE module firmware updater;

Changed in this revision

SakuraIO.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c438a500505d SakuraIO.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SakuraIO.lib	Fri Apr 21 08:23:40 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/teams/SAKURA-Internet/code/SakuraIO/#34a0233cdf04
diff -r 000000000000 -r c438a500505d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Apr 21 08:23:40 2017 +0000
@@ -0,0 +1,82 @@
+#include "mbed.h"
+#include "SakuraIO.h"
+
+#define     SAKURAIO_SDA      PC_9
+#define     SAKURAIO_SCL      PA_8
+#define     SAKURAIO_PIN_RST  PC_6
+#define     SAKURAIO_PIN_WKIN PC_7
+
+Serial        pc(USBTX, USBRX);
+SakuraIO_I2C  sakuraio(SAKURAIO_SDA, SAKURAIO_SCL);
+DigitalInOut  sakuraIoReset(SAKURAIO_PIN_RST, PIN_OUTPUT, OpenDrain, 1);
+DigitalInOut  sakuraIoWakeIn(SAKURAIO_PIN_WKIN, PIN_INPUT, PullUp, 1);
+
+int main()
+{
+    wait(5);
+    pc.printf("waiting for connection .");
+    int status;
+    do {
+        status = sakuraio.getConnectionStatus();
+        pc.printf(".");
+        wait(1);
+    } while (status != 0x80);
+
+    pc.printf(" connected\r\n");
+    pc.printf("updating firmware ");
+
+    // prepare for firmware update
+    sakuraio.unlock();
+
+    switch (status = sakuraio.updateFirmware()) {
+        case 0x01:
+            pc.printf("start ");
+            break;
+        case 0x02:
+            error("parity error\r\n");
+            break;
+        case 0x03:
+            error("unsupported request\r\n");
+            break;
+        case 0x04:
+            error("argument error\r\n");
+            break;
+        case 0x05:
+            error("result error\r\n");
+            break;
+    }
+
+    while(1) {
+        status = sakuraio.getFirmwareUpdateStatus();
+        pc.printf("update status=%d\r\n", status);
+        bool running = status & (1 << 7);
+        bool error = status & (1 << 6);
+        int errCode = status & 0b00111111;
+
+        if (running) {
+            pc.printf(".");
+
+            wait(1);
+            continue;
+        } else {
+            switch (errCode) {
+                case 0x00:
+                    pc.printf("firmware update succeeded.\r\n");
+                    break;
+                case 0x01:
+                    pc.printf("firmware already updated.\r\n");
+                    break;
+                case 0x02:
+                    pc.printf("failed to download latest firmware\r\n");
+                    break;
+                case 0x03:
+                    pc.printf("failed to download firmware\r\n");
+                    break;
+                case 0x04:
+                    pc.printf("firmware verify failed\r\n");
+                    break;
+            }
+            break;
+        }
+    }
+}
diff -r 000000000000 -r c438a500505d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Apr 21 08:23:40 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/97feb9bacc10
\ No newline at end of file