Demonstrates how to import classes and libraries into a simple application. The original Mbed OS 5 wifi example has been imported and configured for the ST IDW04A1

Dependencies:   wifi-x-nucleo-idw01m1

Files at this revision

API Documentation at this revision

Comitter:
timo_k2
Date:
Wed May 20 15:57:51 2020 +0000
Commit message:
Demonstrates how to import classes and libraries to a simple application. The original mbed OS5 wifi -example library has been imported and configured for the ST IDW04A1 Wifi-module.

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
img/uvision.png 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-os.lib 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
wifi-x-nucleo-idw01m1.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ce9de1636bd7 .gitignore
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Wed May 20 15:57:51 2020 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
diff -r 000000000000 -r ce9de1636bd7 README.md
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Wed May 20 15:57:51 2020 +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.
+
+![Image of uVision](img/uvision.png)
+
+## 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
diff -r 000000000000 -r ce9de1636bd7 img/uvision.png
Binary file img/uvision.png has changed
diff -r 000000000000 -r ce9de1636bd7 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed May 20 15:57:51 2020 +0000
@@ -0,0 +1,157 @@
+/* WiFi Example
+ * Copyright (c) 2018 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "mbed.h"
+#include "TCPSocket.h"
+
+#define WIFI_IDW0XX1    2
+
+#if (defined(TARGET_DISCO_L475VG_IOT01A) || defined(TARGET_DISCO_F413ZH))
+#include "ISM43362Interface.h"
+ISM43362Interface wifi(MBED_CONF_APP_WIFI_SPI_MOSI, MBED_CONF_APP_WIFI_SPI_MISO, MBED_CONF_APP_WIFI_SPI_SCLK, MBED_CONF_APP_WIFI_SPI_NSS, MBED_CONF_APP_WIFI_RESET, MBED_CONF_APP_WIFI_DATAREADY, MBED_CONF_APP_WIFI_WAKEUP, false);
+
+#else // External WiFi modules
+
+#if MBED_CONF_APP_WIFI_SHIELD == WIFI_IDW0XX1
+#include "SpwfSAInterface.h"
+SpwfSAInterface wifi(MBED_CONF_APP_WIFI_TX, MBED_CONF_APP_WIFI_RX);
+#endif // MBED_CONF_APP_WIFI_SHIELD == WIFI_IDW0XX1
+
+#endif
+
+const char *sec2str(nsapi_security_t sec)
+{
+    switch (sec) {
+        case NSAPI_SECURITY_NONE:
+            return "None";
+        case NSAPI_SECURITY_WEP:
+            return "WEP";
+        case NSAPI_SECURITY_WPA:
+            return "WPA";
+        case NSAPI_SECURITY_WPA2:
+            return "WPA2";
+        case NSAPI_SECURITY_WPA_WPA2:
+            return "WPA/WPA2";
+        case NSAPI_SECURITY_UNKNOWN:
+        default:
+            return "Unknown";
+    }
+}
+
+int scan_demo(WiFiInterface *wifi)
+{
+    WiFiAccessPoint *ap;
+
+    printf("Scan:\n");
+
+    int count = wifi->scan(NULL,0);
+    printf("%d networks available.\n", count);
+
+    /* Limit number of network arbitrary to 15 */
+    count = count < 15 ? count : 15;
+
+    ap = new WiFiAccessPoint[count];
+    count = wifi->scan(ap, count);
+    for (int i = 0; i < count; i++)
+    {
+        printf("Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\n", ap[i].get_ssid(),
+               sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2],
+               ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel());
+    }
+
+    delete[] ap;
+    return count;
+}
+
+void http_demo(NetworkInterface *net)
+{
+    TCPSocket socket;
+    nsapi_error_t response;
+
+    printf("Sending HTTP request to www.arm.com...\n");
+
+    // Open a socket on the network interface, and create a TCP connection to www.arm.com
+    socket.open(net);
+    response = socket.connect("www.arm.com", 80);
+    if(0 != response) {
+        printf("Error connecting: %d\n", response);
+        socket.close();
+        return;
+    }
+
+    // Send a simple http request
+    char sbuffer[] = "GET / HTTP/1.1\r\nHost: www.arm.com\r\n\r\n";
+    nsapi_size_t size = strlen(sbuffer);
+    response = 0;
+    while(size)
+    {
+        response = socket.send(sbuffer+response, size);
+        if (response < 0) {
+            printf("Error sending data: %d\n", response);
+            socket.close();
+            return;
+        } else {
+            size -= response;
+            // Check if entire message was sent or not
+            printf("sent %d [%.*s]\n", response, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
+        }
+    }
+
+    // Recieve a simple http response and print out the response line
+    char rbuffer[64];
+    response = socket.recv(rbuffer, sizeof rbuffer);
+    if (response < 0) {
+        printf("Error receiving data: %d\n", response);
+    } else {
+        printf("recv %d [%.*s]\n", response, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);
+    }
+
+    // Close the socket to return its memory and bring down the network interface
+    socket.close();
+}
+
+int main()
+{
+    int count = 0;
+
+    printf("WiFi example\n\n");
+
+    count = scan_demo(&wifi);
+    if (count == 0) {
+        printf("No WIFI APNs found - can't continue further.\n");
+        return -1;
+    }
+
+    printf("\nConnecting to %s...\n", MBED_CONF_APP_WIFI_SSID);
+    int ret = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
+    if (ret != 0) {
+        printf("\nConnection error\n");
+        return -1;
+    }
+
+    printf("Success\n\n");
+    printf("MAC: %s\n", wifi.get_mac_address());
+    printf("IP: %s\n", wifi.get_ip_address());
+    printf("Netmask: %s\n", wifi.get_netmask());
+    printf("Gateway: %s\n", wifi.get_gateway());
+    printf("RSSI: %d\n\n", wifi.get_rssi());
+
+    http_demo(&wifi);
+
+    wifi.disconnect();
+
+    printf("\nDone\n");
+}
diff -r 000000000000 -r ce9de1636bd7 mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed May 20 15:57:51 2020 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#1b2a68ae204b70a7aaf3818dc8fa3881250b13b0
diff -r 000000000000 -r ce9de1636bd7 mbed_app.json
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Wed May 20 15:57:51 2020 +0000
@@ -0,0 +1,36 @@
+{
+    "config": {
+    "wifi-shield": {
+            "help": "Options are internal, WIFI_ESP8266, WIFI_IDW0XX1",
+            "value": "WIFI_IDW0XX1"
+    },
+        "wifi-ssid": {
+            "help": "WiFi SSID",
+            "value": "\"Nelli\""
+        },
+        "wifi-password": {
+            "help": "WiFi Password",
+            "value": "\"labradori83\""
+        },
+        "wifi-tx": {
+            "help": "TX pin for serial connection to external device",
+            "value": "D8"
+        },
+        "wifi-rx": {
+            "help": "RX pin for serial connection to external device",
+            "value": "D2"
+        }
+    },
+    "target_overrides": {
+        "*": {
+            "platform.stdio-convert-newlines": true,
+            "idw0xx1.expansion-board": "IDW04A1",
+        "drivers.uart-serial-txbuf-size": 750,
+        "drivers.uart-serial-rxbuf-size": 750
+        },
+    "UBLOX_EVK_ODIN_W2": {
+            "target.device_has": ["EMAC"]
+    }
+    },
+    "macros": ["IDW04A1_WIFI_HW_BUG_WA"]
+}
diff -r 000000000000 -r ce9de1636bd7 wifi-x-nucleo-idw01m1.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wifi-x-nucleo-idw01m1.lib	Wed May 20 15:57:51 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/karen801/code/wifi-x-nucleo-idw01m1/#79ce2b184a43