This shows you the differences between two versions of the page.
|
iothings:laboratoare:2025:lab11 [2025/12/13 15:28] dan.tudose created |
iothings:laboratoare:2025:lab11 [2025/12/13 15:29] (current) dan.tudose |
||
|---|---|---|---|
| Line 4: | Line 4: | ||
| - setting up a fresh Zephyr development environment (“from scratch”) on a computer | - setting up a fresh Zephyr development environment (“from scratch”) on a computer | ||
| - | - building Zephyr’s ``hello_world`` sample for an **ESP32‑C6** target | + | - building Zephyr’s ''hello_world'' sample for an **ESP32‑C6** target |
| - flashing it onto the **Sparrow** node | - flashing it onto the **Sparrow** node | ||
| - seeing the “Hello World” log over the **USB** connection | - seeing the “Hello World” log over the **USB** connection | ||
| Line 26: | Line 26: | ||
| ==== 1.2 Create a Zephyr workspace and Python virtual environment ==== | ==== 1.2 Create a Zephyr workspace and Python virtual environment ==== | ||
| - | Pick a workspace folder. In this tutorial I’ll use ``~/zephyrproject`` on Linux/macOS. | + | Pick a workspace folder. In this tutorial I’ll use ''~/zephyrproject'' on Linux/macOS. |
| - | (Windows users can use something like ``C:\zephyrproject``.) | + | (Windows users can use something like ''C:\zephyrproject''.) |
| <code bash> | <code bash> | ||
| Line 78: | Line 78: | ||
| </code> | </code> | ||
| - | (That exact command appears in the Getting Started flow and is commonly the next step after ``west update``.) | + | (That exact command appears in the Getting Started flow and is commonly the next step after ''west update''.) |
| ==== 1.5 Install the Zephyr SDK (toolchain) ==== | ==== 1.5 Install the Zephyr SDK (toolchain) ==== | ||
| Line 85: | Line 85: | ||
| https://docs.zephyrproject.org/latest/develop/toolchains/zephyr_sdk.html | https://docs.zephyrproject.org/latest/develop/toolchains/zephyr_sdk.html | ||
| - | Install the Zephyr SDK for your OS, then ensure your environment can find it (either via the SDK setup script registering it, or via environment variables like ``ZEPHYR_SDK_INSTALL_DIR`` / ``ZEPHYR_TOOLCHAIN_VARIANT=zephyr``). | + | Install the Zephyr SDK for your OS, then ensure your environment can find it (either via the SDK setup script registering it, or via environment variables like ''ZEPHYR_SDK_INSTALL_DIR'' / ''ZEPHYR_TOOLCHAIN_VARIANT=zephyr''). |
| **Note:** ESP32‑C6 is **RISC‑V** based, so you’ll need the RISC‑V toolchain that’s included with the Zephyr SDK. | **Note:** ESP32‑C6 is **RISC‑V** based, so you’ll need the RISC‑V toolchain that’s included with the Zephyr SDK. | ||
| Line 94: | Line 94: | ||
| ==== 2.1 Fetch Espressif RF binary blobs ==== | ==== 2.1 Fetch Espressif RF binary blobs ==== | ||
| - | Zephyr’s Espressif HAL requires binary blobs (RF calibration, etc.). Zephyr board docs for Espressif boards call this out and recommend fetching after ``west update``. | + | Zephyr’s Espressif HAL requires binary blobs (RF calibration, etc.). Zephyr board docs for Espressif boards call this out and recommend fetching after ''west update''. |
| - | Example (ESP32 DevKitC doc): it explicitly instructs ``west blobs fetch hal_espressif``. | + | Example (ESP32 DevKitC doc): it explicitly instructs ''west blobs fetch hal_espressif''. |
| Run: | Run: | ||
| Line 119: | Line 119: | ||
| - | ==== 3.1 Approach A: Use ``xiao_esp32c6`` as a close match ==== | + | ==== 3.1 Approach A: Use ''xiao_esp32c6'' as a close match ==== |
| Zephyr includes the **Seeed Studio XIAO ESP32C6** board, which is explicitly documented as an **ESP32‑C6 board with 4MB of flash** and a USB‑C port for programming/debugging. | Zephyr includes the **Seeed Studio XIAO ESP32C6** board, which is explicitly documented as an **ESP32‑C6 board with 4MB of flash** and a USB‑C port for programming/debugging. | ||
| Line 126: | Line 126: | ||
| Important: this board has two cores (HP + LP). A Zephyr issue notes you must specify the core qualifier, e.g.: | Important: this board has two cores (HP + LP). A Zephyr issue notes you must specify the core qualifier, e.g.: | ||
| - | * ``xiao_esp32c6/esp32c6/hpcore`` (High‑Performance core) | + | * ''xiao_esp32c6/esp32c6/hpcore'' (High‑Performance core) |
| - | * ``xiao_esp32c6/esp32c6/lpcore`` (Low‑Power core) | + | * ''xiao_esp32c6/esp32c6/lpcore'' (Low‑Power core) |
| - | Source: Zephyr issue describing valid targets for ``xiao_esp32c6``. | + | Source: Zephyr issue describing valid targets for ''xiao_esp32c6''. |
| For “Hello World”, use **HP core**. | For “Hello World”, use **HP core**. | ||
| Line 143: | Line 143: | ||
| - | ==== 3.2 Approach A alternate: Use ``esp32c6_devkitc`` + force 4MB flash ==== | + | ==== 3.2 Approach A alternate: Use ''esp32c6_devkitc'' + force 4MB flash ==== |
| Zephyr’s **ESP32‑C6‑DevKitC** documentation states the module has **8 MB flash**. | Zephyr’s **ESP32‑C6‑DevKitC** documentation states the module has **8 MB flash**. | ||
| Line 150: | Line 150: | ||
| If you build with that board unmodified, you risk generating a partition layout that assumes 8 MB. | If you build with that board unmodified, you risk generating a partition layout that assumes 8 MB. | ||
| - | Zephyr supports applying build “snippets” to override common settings. Snippets can be applied with the ``-S`` option to ``west build``. | + | Zephyr supports applying build “snippets” to override common settings. Snippets can be applied with the ''-S'' option to ''west build''. |
| Docs: https://docs.zephyrproject.org/latest/build/snippets/using.html | Docs: https://docs.zephyrproject.org/latest/build/snippets/using.html | ||
| - | Many Espressif boards support snippet variants like ``flash-4M`` / ``flash-8M`` (the XIAO ESP32C6 page lists these variants). | + | Many Espressif boards support snippet variants like ''flash-4M'' / ''flash-8M'' (the XIAO ESP32C6 page lists these variants). |
| - | So you *can* build with DevKitC + ``-S flash-4M`` — but for Sparrow, using a 4 MB native board definition (XIAO) is usually cleaner. | + | So you *can* build with DevKitC + ''-S flash-4M'' — but for Sparrow, using a 4 MB native board definition (XIAO) is usually cleaner. |
| Line 182: | Line 182: | ||
| Create these files: | Create these files: | ||
| - | * ``CMakeLists.txt`` | + | * ''CMakeLists.txt'' |
| - | * ``prj.conf`` | + | * ''prj.conf'' |
| - | * ``src/main.c`` | + | * ''src/main.c'' |
| - | * a board overlay file under ``boards/`` | + | * a board overlay file under ''boards/'' |
| You can copy the sample hello_world, but I recommend creating a tiny app so you fully control the console configuration. | You can copy the sample hello_world, but I recommend creating a tiny app so you fully control the console configuration. | ||
| Line 230: | Line 230: | ||
| ==== 4.2 Devicetree overlay: force console to USB Serial/JTAG ==== | ==== 4.2 Devicetree overlay: force console to USB Serial/JTAG ==== | ||
| - | On ESP32 chips with a USB Serial/JTAG device exposed to Zephyr as a UART, you can route the console by changing the devicetree ``chosen`` nodes. | + | On ESP32 chips with a USB Serial/JTAG device exposed to Zephyr as a UART, you can route the console by changing the devicetree ''chosen'' nodes. |
| A Zephyr issue discussing USB serial output on ESP32 shows an overlay pattern like: | A Zephyr issue discussing USB serial output on ESP32 shows an overlay pattern like: | ||
| - | * set ``zephyr,console`` to ``&usb_serial`` | + | * set ''zephyr,console'' to ''&usb_serial'' |
| - | * enable the ``usb_serial`` node | + | * enable the ''usb_serial'' node |
| - | (See Zephyr issue #60825 about using ``usb_serial`` for console on ESP32-class devices.) | + | (See Zephyr issue #60825 about using ''usb_serial'' for console on ESP32-class devices.) |
| Create the overlay directory: | Create the overlay directory: | ||
| Line 247: | Line 247: | ||
| Because the board target includes qualifiers, Zephyr looks for overlay filenames like: | Because the board target includes qualifiers, Zephyr looks for overlay filenames like: | ||
| - | * ``boards/xiao_esp32c6_esp32c6_hpcore.overlay`` | + | * ''boards/xiao_esp32c6_esp32c6_hpcore.overlay'' |
| Create: | Create: | ||
| Line 290: | Line 290: | ||
| </code> | </code> | ||
| - | If you get an error about “Board qualifiers not found”, ensure you used the full target name including ``/esp32c6/hpcore``. | + | If you get an error about “Board qualifiers not found”, ensure you used the full target name including ''/esp32c6/hpcore''. |
| (See the Zephyr issue listing valid xiao_esp32c6 targets.) | (See the Zephyr issue listing valid xiao_esp32c6 targets.) | ||
| Line 304: | Line 304: | ||
| </code> | </code> | ||
| - | If ``west flash`` doesn’t pick the correct port automatically, the ESP32 west runner supports options including ``--esp-device`` (serial port), ``--esp-baud-rate``, and ``--esp-flash-size``. A Zephyr ESP32 runner option list (mirrored documentation) shows: | + | If ''west flash'' doesn’t pick the correct port automatically, the ESP32 west runner supports options including ''--esp-device'' (serial port), ''--esp-baud-rate'', and ''--esp-flash-size''. A Zephyr ESP32 runner option list (mirrored documentation) shows: |
| - | * ``--esp-device ESP_DEVICE`` (serial port to flash; default uses ``$ESPTOOL_PORT`` or auto‑scan) | + | * ''--esp-device ESP_DEVICE'' (serial port to flash; default uses ''$ESPTOOL_PORT'' or auto‑scan) |
| - | * ``--esp-baud-rate`` | + | * ''--esp-baud-rate'' |
| - | * ``--esp-flash-size`` (default “detect”) | + | * ''--esp-flash-size'' (default “detect”) |
| Example (Linux): | Example (Linux): | ||
| Line 331: | Line 331: | ||
| * a different USB cable/port | * a different USB cable/port | ||
| * pressing BOOT while resetting (if your Sparrow hardware revision requires it) | * pressing BOOT while resetting (if your Sparrow hardware revision requires it) | ||
| - | * lowering baud rate: ``--esp-baud-rate 115200`` | + | * lowering baud rate: ''--esp-baud-rate 115200'' |
| Line 338: | Line 338: | ||
| You have two common options: | You have two common options: | ||
| - | * **Use Zephyr’s Espressif monitor extension:** many Espressif board docs recommend ``west espressif monitor``. | + | * **Use Zephyr’s Espressif monitor extension:** many Espressif board docs recommend ''west espressif monitor''. |
| - | * **Use a normal serial terminal:** ``screen``, ``minicom``, PuTTY, etc. | + | * **Use a normal serial terminal:** ''screen'', ''minicom'', PuTTY, etc. |
| Example with west: | Example with west: | ||
| Line 347: | Line 347: | ||
| </code> | </code> | ||
| - | If you need to choose the port explicitly, note that older Zephyr tooling discussions show the monitor supports a ``-p`` (port) style option; if your environment doesn’t, use a standard serial terminal as a fallback. | + | If you need to choose the port explicitly, note that older Zephyr tooling discussions show the monitor supports a ''-p'' (port) style option; if your environment doesn’t, use a standard serial terminal as a fallback. |
| Fallback example (Linux): | Fallback example (Linux): | ||
| Line 363: | Line 363: | ||
| ===== 5. Ensuring the 4 MB flash layout is correct ===== | ===== 5. Ensuring the 4 MB flash layout is correct ===== | ||
| - | If you used ``xiao_esp32c6``, you’re already matching a documented **4MB** ESP32‑C6 board. | + | If you used ''xiao_esp32c6'', you’re already matching a documented **4MB** ESP32‑C6 board. |
| (Zephyr XIAO ESP32C6 board doc.) | (Zephyr XIAO ESP32C6 board doc.) | ||
| If you instead build with an ESP32‑C6 board definition that assumes **8 MB** (like DevKitC), use a **flash size snippet**. | If you instead build with an ESP32‑C6 board definition that assumes **8 MB** (like DevKitC), use a **flash size snippet**. | ||
| - | Zephyr’s snippet system is applied with ``west build -S <snippet>``. | + | Zephyr’s snippet system is applied with ''west build -S <snippet>''. |
| Docs: https://docs.zephyrproject.org/latest/build/snippets/using.html | Docs: https://docs.zephyrproject.org/latest/build/snippets/using.html | ||
| Line 377: | Line 377: | ||
| </code> | </code> | ||
| - | The XIAO ESP32C6 board documentation lists snippet variants like ``flash-4M`` / ``flash-8M`` / ``flash-16M`` / ``flash-32M`` / ``flash-64M``. Use the one that matches your module. | + | The XIAO ESP32C6 board documentation lists snippet variants like ''flash-4M'' / ''flash-8M'' / ''flash-16M'' / ''flash-32M'' / ''flash-64M''. Use the one that matches your module. |
| (Zephyr XIAO ESP32C6 board doc.) | (Zephyr XIAO ESP32C6 board doc.) | ||
| Line 388: | Line 388: | ||
| 1. Create an out‑of‑tree board folder, e.g.: | 1. Create an out‑of‑tree board folder, e.g.: | ||
| - | * ``<your_workspace>/modules/your_sparrow_board/boards/espressif/esp32c6_sparrow/`` | + | * ''<your_workspace>/modules/your_sparrow_board/boards/espressif/esp32c6_sparrow/'' |
| 2. Start from a close upstream template: | 2. Start from a close upstream template: | ||
| - | * ``boards/seeed/xiao_esp32c6`` (4MB, USB‑C) | + | * ''boards/seeed/xiao_esp32c6'' (4MB, USB‑C) |
| - | * or ``boards/espressif/esp32c6_devkitc`` (upstream Espressif board) | + | * or ''boards/espressif/esp32c6_devkitc'' (upstream Espressif board) |
| 3. Update the board devicetree: | 3. Update the board devicetree: | ||
| * set correct GPIOs for I2C (SDA/SCL), neopixel pin, SPI chip selects, etc. | * set correct GPIOs for I2C (SDA/SCL), neopixel pin, SPI chip selects, etc. | ||
| Line 414: | Line 414: | ||
| ==== 7.1 “esptool.py not found” ==== | ==== 7.1 “esptool.py not found” ==== | ||
| - | If ``west flash`` complains about missing ``esptool.py``, it usually means your Espressif HAL/tools were not fully fetched or your environment is inconsistent. | + | If ''west flash'' complains about missing ''esptool.py'', it usually means your Espressif HAL/tools were not fully fetched or your environment is inconsistent. |
| Double-check: | Double-check: | ||
| - | * you ran ``west update`` | + | * you ran ''west update'' |
| - | * you ran ``west blobs fetch hal_espressif`` (and didn’t ignore errors) | + | * you ran ''west blobs fetch hal_espressif'' (and didn’t ignore errors) |
| - | * your Python venv is activated and has Zephyr requirements installed (``west packages pip --install``) | + | * your Python venv is activated and has Zephyr requirements installed (''west packages pip --install'') |
| There are Zephyr discussions where users hit “esptool.py not found” when their module/tools were missing. (Search for that message if you encounter it.) | There are Zephyr discussions where users hit “esptool.py not found” when their module/tools were missing. (Search for that message if you encounter it.) | ||
| Line 443: | Line 443: | ||
| </code> | </code> | ||
| - | * Ensure your overlay routes the console to ``&usb_serial``. | + | * Ensure your overlay routes the console to ''&usb_serial''. |
| Line 455: | Line 455: | ||
| Fixes: | Fixes: | ||
| * verify the overlay filename matches your board target (slashes become underscores): | * verify the overlay filename matches your board target (slashes become underscores): | ||
| - | * ``xiao_esp32c6/esp32c6/hpcore`` → ``boards/xiao_esp32c6_esp32c6_hpcore.overlay`` | + | * ''xiao_esp32c6/esp32c6/hpcore'' → ''boards/xiao_esp32c6_esp32c6_hpcore.overlay'' |
| * rebuild from scratch: | * rebuild from scratch: | ||
| <code bash> | <code bash> | ||