Sakura.io LTE module firmware updater.

Dependencies:   SakuraIO mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SakuraIO.h"
00003 
00004 #define     SAKURAIO_SDA      PC_9
00005 #define     SAKURAIO_SCL      PA_8
00006 #define     SAKURAIO_PIN_RST  PC_6
00007 #define     SAKURAIO_PIN_WKIN PC_7
00008 
00009 Serial        pc(USBTX, USBRX);
00010 SakuraIO_I2C  sakuraio(SAKURAIO_SDA, SAKURAIO_SCL);
00011 DigitalInOut  sakuraIoReset(SAKURAIO_PIN_RST, PIN_OUTPUT, OpenDrain, 1);
00012 DigitalInOut  sakuraIoWakeIn(SAKURAIO_PIN_WKIN, PIN_INPUT, PullUp, 1);
00013 
00014 int main()
00015 {
00016     wait(5);
00017     pc.printf("waiting for connection .");
00018     int status;
00019     do {
00020         status = sakuraio.getConnectionStatus();
00021         pc.printf(".");
00022         wait(1);
00023     } while (status != 0x80);
00024 
00025     pc.printf(" connected\r\n");
00026     pc.printf("updating firmware ");
00027 
00028     // prepare for firmware update
00029     sakuraio.unlock();
00030 
00031     switch (status = sakuraio.updateFirmware()) {
00032         case 0x01:
00033             pc.printf("start ");
00034             break;
00035         case 0x02:
00036             error("parity error\r\n");
00037             break;
00038         case 0x03:
00039             error("unsupported request\r\n");
00040             break;
00041         case 0x04:
00042             error("argument error\r\n");
00043             break;
00044         case 0x05:
00045             error("result error\r\n");
00046             break;
00047     }
00048 
00049     while(1) {
00050         status = sakuraio.getFirmwareUpdateStatus();
00051         pc.printf("update status=%d\r\n", status);
00052         bool running = status & (1 << 7);
00053         bool error = status & (1 << 6);
00054         int errCode = status & 0b00111111;
00055 
00056         if (running) {
00057             pc.printf(".");
00058 
00059             wait(1);
00060             continue;
00061         } else {
00062             switch (errCode) {
00063                 case 0x00:
00064                     pc.printf("firmware update succeeded.\r\n");
00065                     break;
00066                 case 0x01:
00067                     pc.printf("firmware already updated.\r\n");
00068                     break;
00069                 case 0x02:
00070                     pc.printf("failed to download latest firmware\r\n");
00071                     break;
00072                 case 0x03:
00073                     pc.printf("failed to download firmware\r\n");
00074                     break;
00075                 case 0x04:
00076                     pc.printf("firmware verify failed\r\n");
00077                     break;
00078             }
00079             break;
00080         }
00081     }
00082 }