Просмотр исходного кода

Merge branch 'fix/zephyr_example_improvements' into 'master'

fix: Zephyr example improvements

Closes ESF-83

See merge request espressif/esp-serial-flasher!78
Roland Dobai 2 лет назад
Родитель
Сommit
3f47cc8356

+ 8 - 8
.gitlab-ci.yml

@@ -16,9 +16,9 @@ variables:
   ARM_TOOLCHAIN_URL: https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2?revision=05382cca-1721-44e1-ae19-1e7c3dc96118&la=en&hash=D7C9D18FCA2DD9F894FD9F3C3DC9228498FA281A
   ARM_TOOLCHAIN_URL: https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2?revision=05382cca-1721-44e1-ae19-1e7c3dc96118&la=en&hash=D7C9D18FCA2DD9F894FD9F3C3DC9228498FA281A
   QEMU_PATH: /opt/qemu/bin/qemu-system-xtensa
   QEMU_PATH: /opt/qemu/bin/qemu-system-xtensa
   ZEPHYR_REPO: https://github.com/zephyrproject-rtos/zephyr.git
   ZEPHYR_REPO: https://github.com/zephyrproject-rtos/zephyr.git
-  ZEPHYR_REPO_REV: v3.2.0
-  ZEPHYR_TOOLCHAIN: https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/toolchain_linux-x86_64_xtensa-espressif_esp32_zephyr-elf.tar.gz
-  ZEPHYR_SDK: https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_linux-aarch64_minimal.tar.gz
+  ZEPHYR_REPO_REV: v3.5.0
+  ZEPHYR_TOOLCHAIN: https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.3/toolchain_linux-x86_64_xtensa-espressif_esp32_zephyr-elf.tar.xz
+  ZEPHYR_SDK: https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.3/zephyr-sdk-0.16.3_linux-aarch64_minimal.tar.xz
 
 
 .build_idf_template:
 .build_idf_template:
   stage: build
   stage: build
@@ -95,10 +95,10 @@ build_zephyr:
     - git clone --single-branch --depth=1 -b ${ZEPHYR_REPO_REV} ${ZEPHYR_REPO}
     - git clone --single-branch --depth=1 -b ${ZEPHYR_REPO_REV} ${ZEPHYR_REPO}
     - mkdir $CI_PROJECT_DIR/zephyrproject-rtos/zephyr-sdk
     - mkdir $CI_PROJECT_DIR/zephyrproject-rtos/zephyr-sdk
     - cd $CI_PROJECT_DIR/zephyrproject-rtos/zephyr-sdk
     - cd $CI_PROJECT_DIR/zephyrproject-rtos/zephyr-sdk
-    - wget --no-verbose -O zephyr_sdk.tar.gz ${ZEPHYR_SDK}
-    - tar xvf zephyr_sdk.tar.gz --strip-components=1
-    - wget --no-verbose -O esp32_toolchain.tar.gz ${ZEPHYR_TOOLCHAIN}
-    - tar xvf esp32_toolchain.tar.gz
+    - wget --no-verbose -O zephyr_sdk.tar.xz ${ZEPHYR_SDK}
+    - tar xvf zephyr_sdk.tar.xz --strip-components=1
+    - wget --no-verbose -O esp32_toolchain.tar.xz ${ZEPHYR_TOOLCHAIN}
+    - tar xvf esp32_toolchain.tar.xz
     - export ZEPHYR_SDK_INSTALL_DIR=$(pwd)
     - export ZEPHYR_SDK_INSTALL_DIR=$(pwd)
     - export ZEPHYR_TOOLCHAIN_VARIANT="zephyr"
     - export ZEPHYR_TOOLCHAIN_VARIANT="zephyr"
     - cd $CI_PROJECT_DIR/zephyrproject-rtos/zephyr
     - cd $CI_PROJECT_DIR/zephyrproject-rtos/zephyr
@@ -111,7 +111,7 @@ build_zephyr:
     - unset IDF_PATH
     - unset IDF_PATH
     - west zephyr-export
     - west zephyr-export
     - west update hal_espressif
     - west update hal_espressif
-    - west build -p -b esp32 $CI_PROJECT_DIR/examples/zephyr_example -DZEPHYR_EXTRA_MODULES=$CI_PROJECT_DIR
+    - west build -p -b esp32_devkitc_wroom $CI_PROJECT_DIR/examples/zephyr_example -DZEPHYR_EXTRA_MODULES=$CI_PROJECT_DIR
 
 
 run_tests:
 run_tests:
   stage: test
   stage: test

+ 17 - 15
examples/zephyr_example/README.md

@@ -2,8 +2,8 @@
 
 
 ## Overview
 ## Overview
 
 
-This sample code demonstrates how to flash ESP32/ESP32-S2/ESP8266 from another (host) MCU using
-esp_serial_flash component API. In this case, ESP32 is also used as host MCU.
+This sample code demonstrates how to flash an Espressif SoC from another (host) MCU using
+esp_serial_flash component API. In this case, the ESP32 is used as host MCU.
 Binaries to be flashed from host MCU to another Espressif SoC can be found in `binaries` folder
 Binaries to be flashed from host MCU to another Espressif SoC can be found in `binaries` folder
 and are converted into C-array during build process.
 and are converted into C-array during build process.
 
 
@@ -11,7 +11,7 @@ Following steps are performed in order to re-program target's memory:
 
 
 1. Peripherals are initialized (GPIO for BOOT and EN pins and UART).
 1. Peripherals are initialized (GPIO for BOOT and EN pins and UART).
 2. UART1 (can be changed) through which new binary will be transfered is initialized.
 2. UART1 (can be changed) through which new binary will be transfered is initialized.
-3. Host puts slave device into boot mode tries to connect by calling `esp_loader_connect()`.
+3. Host puts target device into boot mode tries to connect by calling `esp_loader_connect()`.
 4. Binary file is opened and its size is acquired, as it has to be known before flashing.
 4. Binary file is opened and its size is acquired, as it has to be known before flashing.
 5. Then `esp_loader_flash_start()` is called to enter flashing mode and erase amount of memory to be flashed.
 5. Then `esp_loader_flash_start()` is called to enter flashing mode and erase amount of memory to be flashed.
 6. `esp_loader_flash_write()` function is called repeatedly until the whole binary image is transfered.
 6. `esp_loader_flash_write()` function is called repeatedly until the whole binary image is transfered.
@@ -23,31 +23,33 @@ phase, and can be changed before calling `esp_loader_connect`, if necessary.
 
 
 ## Hardware Required
 ## Hardware Required
 
 
-* Two development boards with ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.).
+* Any supported Espressif SoC board for the target
+* An ESP32-DevKitC board for the host
 * One or two USB cables for power supply and programming.
 * One or two USB cables for power supply and programming.
 
 
 ## Hardware connection
 ## Hardware connection
 
 
-Table below shows connection between two ESP32 devices.
+Table below shows connection between the two devices:
 
 
-| ESP32 (host) | ESP32 (slave) |
-|:------------:|:-------------:|
-|    IO4       |      IO0      |
-|    IO2       |     RESET     |
-|    IO9       |      TX0      |
-|    IO10      |      RX0      |
-
-Note: interconnection is the same for all three targets (slaves).
+| ESP32 (host) | Espressif SoC (target) |
+|:------------:|:----------------------:|
+|    IO4       |           IO0          |
+|    IO2       |          RESET         |
+|    IO9       |           TX0          |
+|    IO10      |           RX0          |
 
 
 ## Build and flash
 ## Build and flash
 
 
-To run the example, type the following command:
+To run the example, type the following commands:
 
 
 ```c
 ```c
-west build -p -b esp32
+west init
+west update
+west build -p -b <supported board>
 west flash
 west flash
 west espressif monitor
 west espressif monitor
 ```
 ```
+>**Note:** You can find the supported boards in the boards folder.
 
 
 (To exit the serial monitor, type ``ctrl-c``.)
 (To exit the serial monitor, type ``ctrl-c``.)
 
 

+ 1 - 1
examples/zephyr_example/boards/esp32.overlay → examples/zephyr_example/boards/esp32_devkitc_wroom.overlay

@@ -12,7 +12,7 @@
 	aliases {
 	aliases {
 		en = &en_button;
 		en = &en_button;
 		boot = &boot_button;
 		boot = &boot_button;
-		uart1 = &uart1;
+		uart = &uart1;
 	};
 	};
 
 
 	gpio_keys {
 	gpio_keys {

+ 34 - 0
examples/zephyr_example/boards/esp32_devkitc_wrover.overlay

@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <zephyr/dt-bindings/pinctrl/esp-pinctrl-common.h>
+#include <dt-bindings/pinctrl/esp32-pinctrl.h>
+#include <zephyr/dt-bindings/pinctrl/esp32-gpio-sigmap.h>
+
+/ {
+	aliases {
+		en = &en_button;
+		boot = &boot_button;
+		uart = &uart1;
+	};
+
+	gpio_keys {
+		compatible = "gpio-keys";
+		en_button: en_button {
+			gpios = <&gpio0 2 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>;
+		};
+		boot_button: boot_button {
+			gpios = <&gpio0 4 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>;
+		};
+	};
+};
+
+&uart1 {
+	status = "okay";
+	current-speed = <115200>;
+	pinctrl-0 = <&uart1_default>;
+	pinctrl-names = "default";
+};

+ 3 - 1
examples/zephyr_example/sample.yaml

@@ -3,5 +3,7 @@ sample:
   name: zephyr_flasher
   name: zephyr_flasher
 tests:
 tests:
   sample.esp_flasher.zephyr_example:
   sample.esp_flasher.zephyr_example:
-    platform_allow: esp32
+    platform_allow:
+      - esp32_devkitc_wroom
+      - esp32_devkitc_wrover
     tags: esp32
     tags: esp32

+ 4 - 2
examples/zephyr_example/src/main.c

@@ -25,13 +25,13 @@
 #define DEFAULT_BAUDRATE 115200
 #define DEFAULT_BAUDRATE 115200
 
 
 /* Get UART DTS entry used as flash interface */
 /* Get UART DTS entry used as flash interface */
-static const struct device *esp_uart_dev = DEVICE_DT_GET(DT_ALIAS(uart1));
+static const struct device *esp_uart_dev = DEVICE_DT_GET(DT_ALIAS(uart));
 /* Get GPIO pin connected to the ESP's enable pin. */
 /* Get GPIO pin connected to the ESP's enable pin. */
 static const struct gpio_dt_spec esp_enable_spec = GPIO_DT_SPEC_GET(DT_ALIAS(en), gpios);
 static const struct gpio_dt_spec esp_enable_spec = GPIO_DT_SPEC_GET(DT_ALIAS(en), gpios);
 /* Get GPIO pin  connected to the ESP's boot pin. */
 /* Get GPIO pin  connected to the ESP's boot pin. */
 static const struct gpio_dt_spec esp_boot_spec = GPIO_DT_SPEC_GET(DT_ALIAS(boot), gpios);
 static const struct gpio_dt_spec esp_boot_spec = GPIO_DT_SPEC_GET(DT_ALIAS(boot), gpios);
 
 
-void main(void)
+int main(void)
 {
 {
 	example_binaries_t bin;
 	example_binaries_t bin;
 
 
@@ -78,4 +78,6 @@ void main(void)
 	loader_port_change_transmission_rate(DEFAULT_BAUDRATE);
 	loader_port_change_transmission_rate(DEFAULT_BAUDRATE);
 
 
 	loader_port_reset_target();
 	loader_port_reset_target();
+
+	return 0;
 }
 }