aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2020-09-23 21:55:38 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2020-09-24 10:16:53 +0000
commit739da0f02dcf6542b235ae34b7f44c9f927be98e (patch)
tree8a266e91d512fb105c454ac50ae81ff1c031efab
parent12d227409e1143b55bc1e49bfaef402fb641cd56 (diff)
baremetal: Add WiFi AP example for ESP8266 MCU using GCC toolchain
This example implements the non-connectable WiFi access point running on the ESP8266-WROOM-02 module: * https://www.espressif.com/sites/default/files/documentation/0c-esp-wroom-02_datasheet_en.pdf For compilation of this module requires the GCC-based proprietary (pre-compiled) ESP8266 NON-OS SDK: * https://github.com/espressif/ESP8266_NONOS_SDK Change-Id: I035e9d8dc621d0981783008fe12af378ee9b02e6 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--examples/baremetal/baremetal.qbs1
-rw-r--r--examples/baremetal/esp8266/README.md34
-rw-r--r--examples/baremetal/esp8266/access-point/access-point.qbs30
-rw-r--r--examples/baremetal/esp8266/access-point/user_config.h62
-rw-r--r--examples/baremetal/esp8266/access-point/user_main.c105
-rw-r--r--examples/baremetal/esp8266/esp8266.qbs59
-rw-r--r--examples/baremetal/esp8266/qbs/imports/Esp8266SdkProbe.qbs25
-rw-r--r--examples/baremetal/esp8266/qbs/modules/esp8266_sdk/Esp8266SdkModule.qbs68
8 files changed, 384 insertions, 0 deletions
diff --git a/examples/baremetal/baremetal.qbs b/examples/baremetal/baremetal.qbs
index 8cb9692f2..9d7e82ef8 100644
--- a/examples/baremetal/baremetal.qbs
+++ b/examples/baremetal/baremetal.qbs
@@ -61,5 +61,6 @@ Project {
"cy7c68013a/cy7c68013a.qbs",
"stm32f103/stm32f103.qbs",
"pca10040/pca10040.qbs",
+ "esp8266/esp8266.qbs",
]
}
diff --git a/examples/baremetal/esp8266/README.md b/examples/baremetal/esp8266/README.md
new file mode 100644
index 000000000..a9b4ef92d
--- /dev/null
+++ b/examples/baremetal/esp8266/README.md
@@ -0,0 +1,34 @@
+This example demonstrates how to build a bare-metal application using
+GCC toolchain for Espressif ESP8266-WROOM02 MCU.
+
+An application is designed to be flashed on the external SPI FLASH
+with the following parameters:
+
+ * SPI FLASH size: 16 MBit (2048 + 2048 KBytes)
+ * SPI FLASH mode: DIO
+ * SPI FLASH clock: 40 MHz
+ * SPI FLASH map type: 5
+
+An application is running as WiFi access point that discards all
+connection attempts, and has the following WiFi parameters:
+ * SSID: "HELLO FROM QBS"
+ * Authentication mode: "open"
+ * Beacon interval: 1000 milliseconds
+ * Channel number: 3
+
+An application requires the ESP8266 NON-OS SDK:
+
+ * https://github.com/espressif/ESP8266_NONOS_SDK
+
+the path to which should be set via the ESP8266_NON_OS_SDK_ROOT
+environment variable.
+
+To convert the ELF application to the final binary image (and also for
+re-program the ESP8266 MCU), you can use the open source 'esptool'
+utility (using the SPI FLASH parameters, provided above):
+
+ * https://github.com/espressif/esptool
+
+The following toolchains are supported:
+
+ * GNU ESP8266 Toolchain
diff --git a/examples/baremetal/esp8266/access-point/access-point.qbs b/examples/baremetal/esp8266/access-point/access-point.qbs
new file mode 100644
index 000000000..fd2890fbd
--- /dev/null
+++ b/examples/baremetal/esp8266/access-point/access-point.qbs
@@ -0,0 +1,30 @@
+import qbs
+
+CppApplication {
+ condition: qbs.toolchain.contains("gcc") && qbs.architecture === "xtensa"
+
+ Depends { name: "esp8266_sdk" }
+
+ cpp.cLanguageVersion: "c99"
+ cpp.positionIndependentCode: false
+
+ // This required because ESP8266 SDK includes this 'user_config.h' internally.
+ cpp.includePaths: ["."]
+
+ cpp.staticLibraries: [
+ "c",
+ "crypto",
+ "gcc",
+ "lwip",
+ "main",
+ "net80211",
+ "phy",
+ "pp",
+ "wpa"
+ ]
+
+ files: [
+ "user_config.h",
+ "user_main.c"
+ ]
+}
diff --git a/examples/baremetal/esp8266/access-point/user_config.h b/examples/baremetal/esp8266/access-point/user_config.h
new file mode 100644
index 000000000..307f93dd5
--- /dev/null
+++ b/examples/baremetal/esp8266/access-point/user_config.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qbs.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND 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
+** OWNER 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."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ESP8266_USER_CONFIG_H
+#define ESP8266_USER_CONFIG_H
+
+// From ESP8266 SDK.
+#include <user_interface.h>
+
+#define ESP_SSID_CFG "HELLO FROM QBS\0"
+#define ESP_AUTO_MODE_CFG (AUTH_OPEN)
+#define ESP_BEACON_INTERVAL_MS_CFG (1000)
+#define ESP_CHANNEL_NO_CFG (3)
+
+#endif // ESP8266_USER_CONFIG_H
diff --git a/examples/baremetal/esp8266/access-point/user_main.c b/examples/baremetal/esp8266/access-point/user_main.c
new file mode 100644
index 000000000..be2a8e92d
--- /dev/null
+++ b/examples/baremetal/esp8266/access-point/user_main.c
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qbs.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND 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
+** OWNER 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."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "user_config.h"
+
+// From ESP8266 SDK.
+#include <osapi.h>
+
+static const partition_item_t esp_partitions[] = {
+ {SYSTEM_PARTITION_BOOTLOADER, ESP_PART_BL_ADDR, ESP_PART_BOOTLOADER_SIZE},
+ {SYSTEM_PARTITION_OTA_1, ESP_PART_APP1_ADDR, ESP_PART_APPLICATION_SIZE},
+ {SYSTEM_PARTITION_OTA_2, ESP_PART_APP2_ADDR, ESP_PART_APPLICATION_SIZE},
+ {SYSTEM_PARTITION_RF_CAL, ESP_PART_RF_CAL_ADDR, ESP_PART_RF_CAL_SIZE},
+ {SYSTEM_PARTITION_PHY_DATA, ESP_PART_PHY_DATA_ADDR, ESP_PART_PHY_DATA_SIZE},
+ {SYSTEM_PARTITION_SYSTEM_PARAMETER, ESP_PART_SYS_PARAM_ADDR, ESP_PART_SYS_PARAM_SIZE}
+};
+
+enum {
+ ESP_PART_COUNT = sizeof(esp_partitions) / sizeof(esp_partitions[0])
+};
+
+LOCAL void ICACHE_FLASH_ATTR user_init_done(void)
+{
+ os_printf("esp: initialization completed\n");
+}
+
+void ICACHE_FLASH_ATTR user_pre_init(void)
+{
+ const bool ok = system_partition_table_regist(esp_partitions, ESP_PART_COUNT, SPI_FLASH_SIZE_MAP);
+ if (!ok) {
+ os_printf("esp: partitions registration failed\n");
+ while (true);
+ }
+}
+
+void ICACHE_FLASH_ATTR user_init(void)
+{
+ os_printf("esp: SDK version: %s\n", system_get_sdk_version());
+ os_printf("esp: reset reason: %u\n", system_get_rst_info()->reason);
+
+ const bool ok = wifi_set_opmode(SOFTAP_MODE);
+ if (!ok) {
+ os_printf("esp: set softap mode failed\n");
+ } else {
+ struct softap_config ap_cfg = {0};
+ ap_cfg.authmode = ESP_AUTO_MODE_CFG;
+ ap_cfg.beacon_interval = ESP_BEACON_INTERVAL_MS_CFG;
+ ap_cfg.channel = ESP_CHANNEL_NO_CFG;
+ ap_cfg.max_connection = 0;
+ ap_cfg.ssid_hidden = false;
+ os_memcpy(&ap_cfg.ssid, ESP_SSID_CFG, sizeof(ESP_SSID_CFG));
+ const bool ok = wifi_softap_set_config(&ap_cfg);
+ if (!ok)
+ os_printf("esp: set softap configuration failed\n");
+ }
+
+ system_init_done_cb(user_init_done);
+}
diff --git a/examples/baremetal/esp8266/esp8266.qbs b/examples/baremetal/esp8266/esp8266.qbs
new file mode 100644
index 000000000..6056a33e0
--- /dev/null
+++ b/examples/baremetal/esp8266/esp8266.qbs
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qbs.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND 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
+** OWNER 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."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import qbs
+
+Project {
+ name: "Examples for esp8266-wroom-02 board"
+ qbsSearchPaths: "qbs"
+ references: [
+ "access-point/access-point.qbs"
+ ]
+}
diff --git a/examples/baremetal/esp8266/qbs/imports/Esp8266SdkProbe.qbs b/examples/baremetal/esp8266/qbs/imports/Esp8266SdkProbe.qbs
new file mode 100644
index 000000000..faa8b1efd
--- /dev/null
+++ b/examples/baremetal/esp8266/qbs/imports/Esp8266SdkProbe.qbs
@@ -0,0 +1,25 @@
+import qbs.Environment
+import qbs.File
+import qbs.FileInfo
+import qbs.Probes
+
+Probes.PathProbe {
+ // Inputs.
+ environmentPaths: Environment.getEnv("ESP8266_NON_OS_SDK_ROOT")
+ // Outputs.
+ property string includesPath;
+ property string libsPath;
+ property string linkerScriptsPath;
+ configure: {
+ for (var i in environmentPaths) {
+ var rootPath = environmentPaths[i];
+ if (!File.exists(rootPath))
+ continue;
+ includesPath = FileInfo.joinPaths(rootPath, "include");
+ libsPath = FileInfo.joinPaths(rootPath, "lib");
+ linkerScriptsPath = FileInfo.joinPaths(rootPath, "ld");
+ found = true;
+ return;
+ }
+ }
+}
diff --git a/examples/baremetal/esp8266/qbs/modules/esp8266_sdk/Esp8266SdkModule.qbs b/examples/baremetal/esp8266/qbs/modules/esp8266_sdk/Esp8266SdkModule.qbs
new file mode 100644
index 000000000..ba7cbbe44
--- /dev/null
+++ b/examples/baremetal/esp8266/qbs/modules/esp8266_sdk/Esp8266SdkModule.qbs
@@ -0,0 +1,68 @@
+import qbs
+
+Module {
+ Depends { name: "cpp" }
+
+ Esp8266SdkProbe { id: esp_sdk_probe }
+
+ validate: {
+ if (!esp_sdk_probe.found)
+ throw "ESP8266 NON OS SDK not found. Please set the ESP8266_NON_OS_SDK_ROOT env variable."
+ }
+
+ cpp.systemIncludePaths: [esp_sdk_probe.includesPath]
+ cpp.libraryPaths: [esp_sdk_probe.libsPath]
+ cpp.driverFlags: ["-nostdlib"]
+
+ cpp.cFlags: [
+ "-Wpointer-arith",
+ "-Wundef",
+ "-fno-inline-functions",
+ "-mlongcalls",
+ "-mtext-section-literals",
+ "-ffunction-sections",
+ "-fdata-sections",
+ "-fno-builtin-printf",
+ "-fno-guess-branch-probability",
+ "-freorder-blocks-and-partition",
+ "-fno-cse-follow-jumps"
+ ]
+
+ cpp.linkerFlags: [
+ "--no-check-sections",
+ "--gc-sections",
+ "--start-group"
+ ]
+
+ cpp.defines: [
+ "ICACHE_FLASH",
+ "USE_OPTIMIZE_PRINTF",
+
+ // Target specific defines for the external 40MHz DIO
+ // SPI 16 Mbit FLASH (2048 KByte + 2048 KByte) FOTA.
+ "SPI_FLASH_SIZE_MAP=5",
+ "ESP_PART_BL_ADDR=0x000000",
+ "ESP_PART_APP1_ADDR=0x001000",
+ "ESP_PART_APP2_ADDR=0x101000",
+ "ESP_PART_RF_CAL_ADDR=0x1FB000",
+ "ESP_PART_PHY_DATA_ADDR=0x1FC000",
+ "ESP_PART_SYS_PARAM_ADDR=0x1FD000",
+ "ESP_PART_BOOTLOADER_SIZE=0x001000",
+ "ESP_PART_APPLICATION_SIZE=0x0E0000",
+ "ESP_PART_RF_CAL_SIZE=0x001000",
+ "ESP_PART_PHY_DATA_SIZE=0x001000",
+ "ESP_PART_SYS_PARAM_SIZE=0x003000"
+ ]
+
+ property string _linker_scripts_path: esp_sdk_probe.linkerScriptsPath + "/"
+
+ Group {
+ name: "ESP8266 Linker Scripts"
+ prefix: esp8266_sdk._linker_scripts_path + "/"
+ fileTags: ["linkerscript"]
+ files: [
+ "eagle.rom.addr.v6.ld",
+ "eagle.app.v6.new.2048.ld"
+ ]
+ }
+}