This is an old revision of the document!
Table of Contents
Zephyr
Länkar
- https://embedded.fm/episodes/475?rq=zephyr – Nämner bland annat att det finns några tänkta sätt att strukturera sina projekt för att inte blanda in sin projekt-kod i zephyr-repot
Shawn Hymel / Digikey
Dokumentation
Vanliga kommandon
Bygg Zephyr-projekt med overlay
west build -p always -b esp32c6_devkitc -- -DDTC_OVERLAY_FILE=boards/esp32s3_devkitc.overlay
Öppna menuconfig
west build -p always -b esp32c6_devkitc -t menuconfig
Bygg med extra conf file
west build -p always -b esp32c6_devkitc -- -DEXTRA_CONF_FILE=boards/esp32s3_devkitc.conf
Ladda kod
python -m esptool --port COM19 --chip auto --baud 921600 --before default_reset --after hard_reset write_flash -u --flash_size detect 0x0 .\build\zephyr\zephyr.bin
KConfig
Öppna menuconfig
west build -p always -b esp32c6_devkitc -t menuconfig
Sparas till ./build/zephyr/.config som kommer tas bort vid nästa bygge.
För att göra persistent, kolla diff mellan ./build/zephyr/.config.old
# diff build/zephyr/.config.old build/zephyr/.config 574a575,576 > # CONFIG_STACK_CANARIES is not set > CONFIG_STACK_POINTER_RANDOM=0 1136c1138 < # CONFIG_TEST_RANDOM_GENERATOR is not set --- > CONFIG_TEST_RANDOM_GENERATOR=y 1137a1140,1141 > CONFIG_TIMER_RANDOM_GENERATOR=y > CONFIG_TEST_CSPRNG_GENERATOR=y
Lägg sedan detta i antingen appens prj.conf eller ännu bättre i en board-specifik config
# File: boards/esp32s3_devkitc.conf # CONFIG_STACK_CANARIES is not set CONFIG_STACK_POINTER_RANDOM=0 CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_TIMER_RANDOM_GENERATOR=y CONFIG_TEST_CSPRNG_GENERATOR=y # CONFIG_SAY_HELLO=y
Och lägg med denna till bygget med -DEXTRA_CONF_FILE=boards/esp32s3_devkitc.conf
west build -p always -b esp32c6_devkitc -- -DEXTRA_CONF_FILE=boards/esp32s3_devkitc.conf
Devicetree
Words
- DTS – Device Tree Source
- DTC – Device Tree Compiler
- .dtsi – Device Tree Source Include file
Property types
| string | status = "disabled"; |
| int | current-speed = <115200>; |
| boolean | hw-flow-control; |
| array 32bit | offsets = <0x100 0x200 0x300>; |
| uint8-array | local-mac-address = [de ad be ef 12 34]; |
| string-array | dma-names = "tx", "rx"; |
| phandle | interrupt-parent = <&gic>; |
| phandles | pinctrl-0 = <&usart2_tx_pd5 &usart2_rx_pd6>; |
| phandle-array | dmas = <&dma0 2>, <&dma0 3>; |
| path | zephyr,bt-c2h-uart = &uart0; or foo = "/path/to/some/node"; |
Structure
In the boards folder for esp32s3_devkitc there is a DTS file for the appcpu, /opt/toolchains/zephyr/boards/espressif/esp32s3_devkitc/esp32s3_devkitc_appcpu.dts.
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
/dts-v1/;
#include <espressif/esp32s3/esp32s3_appcpu.dtsi>
#include <espressif/partitions_0x0_amp.dtsi>
/ {
model = "Espressif ESP32S3-DevkitC APPCPU";
compatible = "espressif,esp32s3";
chosen {
zephyr,sram = &sram0;
zephyr,ipc_shm = &shm0;
zephyr,ipc = &ipm0;
};
};
&trng0 {
status = "okay";
};
&ipm0 {
status = "okay";
};
This #include <espressif/esp32s3/esp32s3_appcpu.dtsi> includes a devicetree source include-file which in turn includes #include "esp32s3_common.dtsi".
Int the file /opt/toolchains/zephyr/dts/xtensa/espressif/esp32s3/esp32s3_common.dtsi there is a part defining the alias gpio0 for the path /soc/gpio/gpio@60004000.
gpio0: gpio@60004000 {
compatible = "espressif,esp32-gpio";
gpio-controller;
#gpio-cells = <2>;
reg = <0x60004000 0x800>;
interrupts = <GPIO_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
interrupt-parent = <&intc>;
/* Maximum available pins (per port)
* Actual occupied pins are specified
* on part number dtsi level, using
* the `gpio-reserved-ranges` property.
*/
ngpios = <32>; /* 0..31 */
};
The compatible = "espressif,esp32-gpio"; tells Zephyr to look for a bindings file containing the similar line (file name doesn't really matter, but is by convention the same).
Binding file can be found in /opt/toolchains/zephyr/dts/bindings/gpio/espressif,esp32-gpio.yaml
# Copyright (c) 2019, Yannis Damigos
# SPDX-License-Identifier: Apache-2.0
description: ESP32 GPIO controller
compatible: "espressif,esp32-gpio"
include: [gpio-controller.yaml, base.yaml]
properties:
reg:
required: true
"#gpio-cells":
const: 2
gpio-cells:
- pin
- flags
Lables, names, property names
- Names kan inte ha understreck, men kan ha bindestreck.
- Lables kan inte ha bindestreck men kan ha understreck.
- Names kan ha brädhögar och snabel-a i namnet, ingen magi.
- Property names kan inte ha understreck, men kan ha bindestreck
- I C-kod kommer bindestreck i aliases att automatiskt översättas till understreck
/chosen och /aliases
Dessa är två speciella noder i device-trädet som DTC behandlar speciellt. Dessa går att fylla på för att ställa in vissa saker eller introducera alias.
/ {
chosen {
zephyr,console = &uart0;
};
aliases {
my-uart = &uart0;
};
soc {
uart0: serial@12340000 {
...
};
};
};
