Prepare example app Connect+FW Update

Fork of example-DISCO_L475_IOT-mbed-Cloud-connect by ST

Files at this revision

API Documentation at this revision

Comitter:
MarceloSalazar
Date:
Sun Oct 14 19:01:53 2018 +0100
Parent:
8:18cf5ea7f4c5
Commit message:
Add support for FW Update

Changed in this revision

bootloader/LICENSE Show annotated file Show diff for this revision Revisions of this file
bootloader/mbed-bootloader-L475VG.bin Show annotated file Show diff for this revision Revisions of this file
bootloader/mbed_app.json 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_app.json Show annotated file Show diff for this revision Revisions of this file
update_default_resources.c Show annotated file Show diff for this revision Revisions of this file
wifi-ism43362.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bootloader/LICENSE	Sun Oct 14 19:01:53 2018 +0100
@@ -0,0 +1,49 @@
+Permissive Binary License
+
+Version 1.0, September 2015
+
+Redistribution.  Redistribution and use in binary form, without
+modification, are permitted provided that the following conditions are
+met:
+
+1) Redistributions must reproduce the above copyright notice and the
+   following disclaimer in the documentation and/or other materials
+   provided with the distribution.
+
+2) Unless to the extent explicitly permitted by law, no reverse
+   engineering, decompilation, or disassembly of this software is
+   permitted.
+
+3) Redistribution as part of a software development kit must include the
+   accompanying file named "DEPENDENCIES" and any dependencies listed in
+   that file.
+
+4) Neither the name of the copyright holder nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission. 
+
+Limited patent license. The copyright holders (and contributors) grant a
+worldwide, non-exclusive, no-charge, royalty-free patent license to
+make, have made, use, offer to sell, sell, import, and otherwise
+transfer this software, where such license applies only to those patent
+claims licensable by the copyright holders (and contributors) that are
+necessarily infringed by this software. This patent license shall not
+apply to any combinations that include this software.  No hardware is
+licensed hereunder.
+
+If you institute patent litigation against any entity (including a
+cross-claim or counterclaim in a lawsuit) alleging that the software
+itself infringes your patent(s), then your rights granted under this
+license shall terminate as of the date such litigation is filed.
+
+DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
+NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
Binary file bootloader/mbed-bootloader-L475VG.bin has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bootloader/mbed_app.json	Sun Oct 14 19:01:53 2018 +0100
@@ -0,0 +1,65 @@
+{
+    "macros": [
+        "MBEDTLS_USER_CONFIG_FILE=\"bootloader_mbedtls_user_config.h\"",
+        "MAX_COPY_RETRIES=1",
+        "SHOW_PROGRESS_BAR=1",
+        "MAX_BOOT_RETRIES=3",
+        "ARM_UC_USE_PAL_CRYPTO=0",
+        "ARM_BOOTLOADER_USE_NVSTORE_ROT=1",
+        "ARM_UC_USE_PAL_BLOCKDEVICE=1",
+        "ARM_UC_PAAL_TRACE_ENABLE=0",
+        "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE",
+        "DEFAULT_MAX_APPLICATION_SIZE=(MBED_CONF_APP_FLASH_START_ADDRESS + MBED_CONF_APP_FLASH_SIZE - MBED_CONF_APP_APPLICATION_START_ADDRESS)",
+        "DISABLE_ERROR_DESCRIPTION=1",
+        "Mutex=PlatformMutex"
+    ],
+    "config": {
+        "application-start-address": {
+            "help": "Address to the beginning of the active application firmware in flash",
+            "value": null
+        },
+        "application-jump-address": {
+            "help": "Jump address for running the active application firmware",
+            "value": null
+        },
+        "max-application-size": {
+            "help": "Maximum size of the active application",
+            "value": null
+        },
+        "flash-start-address": {
+            "help": "Start address of internal flash. Only used in this config to help the definition of other macros.",
+            "value": null
+        },
+        "flash-size": {
+            "help": "Total size of internal flash. Only used in this config to help the definition of other macros.",
+            "value": null
+        }
+    },
+    "target_overrides": {
+        "*": {
+            "target.features_remove": ["LWIP"],
+            "target.features_add"   : ["COMMON_PAL"],
+            "platform.stdio-baud-rate"    : 115200,
+            "platform.stdio-flush-at-exit": false,
+            "update-client.storage-address"  : "(1024*1024*64)",
+            "update-client.storage-size"     : "(1024*1024*2)",
+            "update-client.storage-locations": 1,
+            "update-client.firmware-header-version": "2"
+        },
+         "DISCO_L475VG_IOT01A": {
+            "flash-start-address"              : "0x08000000",
+            "flash-size"                       : "(1024*1024)",
+            "nvstore.area_1_address"           : "(0x08000000+((1024-4)*1024))",
+            "nvstore.area_1_size"              : "(2*1024)",
+            "nvstore.area_2_address"           : "(0x08000000+((1024-2)*1024))",
+            "nvstore.area_2_size"              : "(2*1024)",
+            "update-client.application-details": "(MBED_CONF_APP_FLASH_START_ADDRESS+64*1024)",
+            "application-start-address"        : "(MBED_CONF_APP_FLASH_START_ADDRESS+65*1024)",
+            "max-application-size"             : "DEFAULT_MAX_APPLICATION_SIZE",
+            "sd.SPI_MOSI"  : "D11",
+            "sd.SPI_MISO"  : "D12",
+            "sd.SPI_CLK"   : "D13",
+            "sd.SPI_CS"    : "D10"
+        }
+    }
+}
--- a/main.cpp	Sun Oct 14 17:15:45 2018 +0000
+++ b/main.cpp	Sun Oct 14 19:01:53 2018 +0100
@@ -15,26 +15,23 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 // ----------------------------------------------------------------------------
-
+#ifndef MBED_TEST_MODE
 #include "mbed.h"
 #include "simple-mbed-cloud-client.h"
-#include "SDBlockDevice.h"
 #include "FATFileSystem.h"
-#include "ISM43362Interface.h"
 
 // An event queue is a very useful structure to debounce information between contexts (e.g. ISR and normal threads)
 // This is great because things such as network operations are illegal in ISR, so updating a resource in a button's fall() function is not allowed
 EventQueue eventQueue;
 
-// Declaring net interface as a global variable instead of local to avoid stack overflow
-ISM43362Interface net;
+// Default network interface object
+NetworkInterface *net;
 
-// Storage implementation definition, currently using SDBlockDevice (SPI flash, DataFlash, and internal flash are also available)
-SDBlockDevice sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS);
-FATFileSystem fs("sd", &sd);
+// Default block device
+BlockDevice* bd = BlockDevice::get_default_instance();
+FATFileSystem fs("sd", bd);
 
-
-// Declaring pointers for access to Mbed Cloud Client resources outside of main()
+// Declaring pointers for access to Pelion Client resources outside of main()
 MbedCloudClientResource *button_res;
 MbedCloudClientResource *pattern_res;
 
@@ -100,28 +97,30 @@
  * @param endpoint Information about the registered endpoint such as the name (so you can find it back in portal)
  */
 void registered(const ConnectorClientEndpointInfo *endpoint) {
-    printf("Connected to Mbed Cloud. Endpoint Name: %s\n", endpoint->internal_endpoint_name.c_str());
+    printf("Connected to Pelion Device Management. Endpoint Name: %s\n", endpoint->internal_endpoint_name.c_str());
 }
 
 int main(void) {
-    printf("Starting Simple Mbed Cloud Client example\n");
+    printf("Starting Simple Pelion Device Management Client example\n");
     printf("Connecting to the network using Wifi...\n");
 
     // Connect to the internet (DHCP is expected to be on)
-    nsapi_error_t status = net.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, (strlen(MBED_CONF_APP_WIFI_PASSWORD) > 1) ? NSAPI_SECURITY_WPA_WPA2 : NSAPI_SECURITY_NONE);
+    net = NetworkInterface::get_default_instance();
 
-    if (status != 0) {
+    nsapi_error_t status = net->connect();
+
+    if (status != NSAPI_ERROR_OK) {
         printf("Connecting to the network failed %d!\n", status);
         return -1;
     }
 
-    printf("Connected to the network successfully. IP address: %s\n", net.get_ip_address());
+    printf("Connected to the network successfully. IP address: %s\n", net->get_ip_address());
 
-    // SimpleMbedCloudClient handles registering over LwM2M to Mbed Cloud
-    SimpleMbedCloudClient client(&net, &sd, &fs);
+    // SimpleMbedCloudClient handles registering over LwM2M to Pelion DM
+    SimpleMbedCloudClient client(net, bd, &fs);
     int client_status = client.init();
     if (client_status != 0) {
-        printf("Initializing Mbed Cloud Client failed (%d)\n", client_status);
+        printf("Pelion Client initialization failed (%d)\n", client_status);
         return -1;
     }
 
@@ -141,12 +140,12 @@
     blink_res->methods(M2MMethod::POST);
     blink_res->attach_post_callback(blink_callback);
 
-    printf("Initialized Mbed Cloud Client. Registering...\n");
+    printf("Initialized Pelion Client. Registering...\n");
 
     // Callback that fires when registering is complete
     client.on_registered(&registered);
 
-    // Register with Mbed Cloud
+    // Register with Pelion DM
     client.register_and_connect();
 
     // Placeholder for callback to update local resource when GET comes.
@@ -157,3 +156,4 @@
     // You can easily run the eventQueue in a separate thread if required
     eventQueue.dispatch_forever();
 }
+#endif
--- a/mbed_app.json	Sun Oct 14 17:15:45 2018 +0000
+++ b/mbed_app.json	Sun Oct 14 19:01:53 2018 +0100
@@ -5,33 +5,47 @@
         "MBED_CLIENT_USER_CONFIG_FILE=\"mbed_cloud_client_user_config.h\"",
         "MBED_CLOUD_CLIENT_USER_CONFIG_FILE=\"mbed_cloud_client_user_config.h\"",
         "PAL_DTLS_PEER_MIN_TIMEOUT=5000",
-        "MBED_CONF_APP_MAIN_STACK_SIZE=6000",
+        "MBED_CONF_APP_MAIN_STACK_SIZE=7000",
         "ARM_UC_USE_PAL_BLOCKDEVICE=1",
-        "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE",
-        "_RTE_"
+        "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE"
     ],
     "target_overrides": {
         "*": {
             "platform.stdio-baud-rate": 115200,
-            "platform.stdio-convert-newlines": true,
-            "update-client.storage-address"  : "(1024*1024*64)",
-            "update-client.storage-size"     : "(1024*1024*2)",
-            "update-client.storage-locations": "1",
-            "mbed-trace.enable": null
+            "platform.stdio-convert-newlines"   : true,
+            "update-client.storage-address"     : "(1024*1024*64)",
+            "update-client.storage-size"        : "(1024*1024*2)",
+            "update-client.storage-locations"   : "1",
+            "mbed-trace.enable"                 : null,
+            "nsapi.default-wifi-security"       : "WPA_WPA2",
+            "nsapi.default-wifi-ssid"           : "\"SSID\"",
+            "nsapi.default-wifi-password"       : "\"Password\""
         },
         "DISCO_L475VG_IOT01A": {
-            "sotp-section-1-address"           : "(0x08000000+((1024-32)*1024))",
-            "sotp-section-1-size"              : "(16*1024)",
-            "sotp-section-2-address"           : "(0x08000000+((1024-16)*1024))",
-            "sotp-section-2-size"              : "(16*1024)",
-            "sotp-num-sections"                : 2
+            "target.network-default-interface-type" : "WIFI",
+            "target.features_add"               : ["STORAGE", "BOOTLOADER"],
+            "target.components_add"             : ["SD"],
+            "sd.SPI_MOSI"                       : "D11",
+            "sd.SPI_MISO"                       : "D12",
+            "sd.SPI_CLK"                        : "D13",
+            "sd.SPI_CS"                         : "D10",
+            "target.app_offset"                 : "0x10400",
+            "target.header_offset"              : "0x10000",
+            "target.bootloader_img"             : "bootloader/mbed-bootloader-L475VG.bin",
+            "sotp-section-1-address"            : "(0x08000000+((1024-4)*1024))",
+            "sotp-section-1-size"               : "(2*1024)",
+            "sotp-section-2-address"            : "(0x08000000+((1024-2)*1024))",
+            "sotp-section-2-size"               : "(2*1024)",
+            "sotp-num-sections"                 : 2,
+            "update-client.application-details" : "(0x08000000+64*1024)",
+            "update-client.bootloader-details"  : "0x080082A0"
         },
         "DISCO_F413ZH": {
-            "sotp-section-1-address"           : "(0x08000000+((1536-256)*1024))",
-            "sotp-section-1-size"              : "(128*1024)",
-            "sotp-section-2-address"           : "(0x08000000+((1536-128)*1024))",
-            "sotp-section-2-size"              : "(128*1024)",
-            "sotp-num-sections"                : 2
+            "sotp-section-1-address"            : "(0x08000000+((1536-256)*1024))",
+            "sotp-section-1-size"               : "(128*1024)",
+            "sotp-section-2-address"            : "(0x08000000+((1536-128)*1024))",
+            "sotp-section-2-size"               : "(128*1024)",
+            "sotp-num-sections"                 : 2
         }
 
     },
@@ -44,14 +58,6 @@
             "help": "Enable Developer mode to skip Factory enrollment",
             "value": 1
         },
-        "wifi-ssid": {
-            "help": "WiFi SSID",
-            "value": "\"SSID\""
-        },
-        "wifi-password": {
-            "help": "WiFi Password",
-            "value": "\"PASSWORD\""
-        },
         "sotp-section-1-address": {
             "help": "Flash sector address for SOTP sector 1",
             "macro_name": "PAL_INTERNAL_FLASH_SECTION_1_ADDRESS",
--- a/update_default_resources.c	Sun Oct 14 17:15:45 2018 +0000
+++ b/update_default_resources.c	Sun Oct 14 19:01:53 2018 +0100
@@ -1,5 +1,5 @@
 // ----------------------------------------------------------------------------
-// Copyright 2016-2018 ARM Ltd.
+// Copyright 2016-2017 ARM Ltd.
 //
 // SPDX-License-Identifier: Apache-2.0
 //
--- a/wifi-ism43362.lib	Sun Oct 14 17:15:45 2018 +0000
+++ b/wifi-ism43362.lib	Sun Oct 14 19:01:53 2018 +0100
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/wifi-ism43362/#9ee7fb19814e46b6e90b1eaec26ef36b523ec024
+https://github.com/ARMmbed/wifi-ism43362/#49d0f834dc420c98631fc33777aace9a31d8d584