zephyr
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| zephyr [2025/04/20 08:36] – [Devicetree] utedass | zephyr [2025/12/03 21:35] (current) – [Länkar] utedass | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| ===== Länkar ===== | ===== Länkar ===== | ||
| + | * [[https:// | ||
| * [[https:// | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| + | * [[https:// | ||
| + | |||
| + | * [[https:// | ||
| + | |||
| + | == Real world examples == | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| == Shawn Hymel / Digikey == | == Shawn Hymel / Digikey == | ||
| Line 40: | Line 53: | ||
| < | < | ||
| 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 | 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 | ||
| + | </ | ||
| + | |||
| + | ===== Platser ===== | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | ===== CMake ===== | ||
| + | === CMakeList.txt in project === | ||
| + | <code cmake> | ||
| + | cmake_minimum_required(VERSION 3.20.0) | ||
| + | |||
| + | # Optional for your own extra KConfig modules | ||
| + | set(ZEPHYR_EXTRA_MODULES " | ||
| + | |||
| + | # Mandatory thing | ||
| + | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
| + | |||
| + | # Name your project | ||
| + | project(random) | ||
| + | |||
| + | # Adds your main entry point to the Zephyr-created " | ||
| + | target_sources(app PRIVATE src/main.c) | ||
| + | |||
| + | </ | ||
| + | |||
| + | === CMakeLists.txt === | ||
| + | |||
| + | CMakeLists file for your own modules | ||
| + | <code cmake> | ||
| + | # Check if SAY_HELLO is set in Kconfig | ||
| + | if(CONFIG_SAY_HELLO) | ||
| + | |||
| + | # Add your include directory | ||
| + | zephyr_include_directories(.) | ||
| + | |||
| + | # Add the source file you want to compile | ||
| + | zephyr_library_sources(say_hello.c) | ||
| + | |||
| + | endif() | ||
| </ | </ | ||
| Line 50: | Line 104: | ||
| </ | </ | ||
| - | Sparas till ./ | + | Sparas till '' |
| + | |||
| + | Generates an include file in '' | ||
| För att göra persistent, kolla diff mellan ./ | För att göra persistent, kolla diff mellan ./ | ||
| Line 86: | Line 142: | ||
| </ | </ | ||
| + | ==== Egna moduler ==== | ||
| + | För att lägga till egna moduler som går att aktivera i menuconfig, lägg in en fil som heter exempelvis KConfig i modulens mapp. | ||
| + | |||
| + | < | ||
| + | # Create a new option in menuconfig | ||
| + | config SAY_HELLO | ||
| + | bool "Basic print test to console" | ||
| + | default n # Set the library to be disabled by default | ||
| + | depends on PRINTK | ||
| + | help | ||
| + | Adds say_hello() function to print a basic message to the console. | ||
| + | </ | ||
| + | |||
| + | Lägg även till en mapp som heter exakt '' | ||
| + | |||
| + | <code yaml> | ||
| + | name: say_hello | ||
| + | build: | ||
| + | cmake: . | ||
| + | kconfig: Kconfig | ||
| + | </ | ||
| ===== Devicetree ===== | ===== Devicetree ===== | ||
| Line 91: | Line 168: | ||
| * [[https:// | * [[https:// | ||
| * [[https:// | * [[https:// | ||
| + | |||
| + | The final devicetree will end up under '' | ||
| + | |||
| + | There is an include file generated from this in '' | ||
| === Words === | === Words === | ||
| Line 113: | Line 194: | ||
| [[https:// | [[https:// | ||
| - | From file ''/ | + | In the boards folder for esp32s3_devkitc there is a DTS file for the appcpu, ''/ |
| + | |||
| + | < | ||
| + | /* | ||
| + | * Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. | ||
| + | * | ||
| + | * SPDX-License-Identifier: | ||
| + | */ | ||
| + | /dts-v1/; | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | / { | ||
| + | model = " | ||
| + | compatible = " | ||
| + | |||
| + | chosen { | ||
| + | zephyr, | ||
| + | zephyr, | ||
| + | zephyr, | ||
| + | }; | ||
| + | }; | ||
| + | |||
| + | &trng0 { | ||
| + | status = " | ||
| + | }; | ||
| + | |||
| + | &ipm0 { | ||
| + | status = " | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | This ''# | ||
| + | |||
| + | Int the file ''/ | ||
| < | < | ||
| gpio0: gpio@60004000 { | gpio0: gpio@60004000 { | ||
| Line 155: | Line 271: | ||
| - flags | - flags | ||
| </ | </ | ||
| + | |||
| + | Also at the location for the board files is the ''/ | ||
| + | |||
| + | < | ||
| + | /* | ||
| + | * Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. | ||
| + | * | ||
| + | * SPDX-License-Identifier: | ||
| + | */ | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | & | ||
| + | uart0_default: | ||
| + | group1 { | ||
| + | pinmux = < | ||
| + | output-high; | ||
| + | }; | ||
| + | group2 { | ||
| + | pinmux = < | ||
| + | bias-pull-up; | ||
| + | }; | ||
| + | }; | ||
| + | |||
| + | i2c0_default: | ||
| + | group1 { | ||
| + | pinmux = < | ||
| + | < | ||
| + | bias-pull-up; | ||
| + | drive-open-drain; | ||
| + | output-high; | ||
| + | }; | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | The line ''# | ||
| + | |||
| + | < | ||
| + | #define UART0_TX_GPIO43 ESP32_PINMUX(43, | ||
| + | </ | ||
| + | |||
| + | All of the files in ''/ | ||
| === Lables, names, property names === | === Lables, names, property names === | ||
| Line 187: | Line 347: | ||
| </ | </ | ||
| + | ==== Overlay files ==== | ||
| + | |||
| + | == Example == | ||
| + | '' | ||
| + | < | ||
| + | / { | ||
| + | aliases { | ||
| + | my-led = &led0; | ||
| + | }; | ||
| + | |||
| + | leds { | ||
| + | compatible = " | ||
| + | led0: d5 { | ||
| + | gpios = <& | ||
| + | }; | ||
| + | }; | ||
| + | }; | ||
| + | </ | ||
| + | ===== C-kod ===== | ||
| + | == Exempel blink == | ||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | // Settings | ||
| + | static const int32_t sleep_time_ms = 1000; | ||
| + | static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(my_led), | ||
| + | |||
| + | int main(void) | ||
| + | { | ||
| + | int ret; | ||
| + | int state = 0; | ||
| + | |||
| + | // Make sure that the GPIO was initialized | ||
| + | if (!gpio_is_ready_dt(& | ||
| + | { | ||
| + | return 0; | ||
| + | } | ||
| + | |||
| + | // Set the GPIO as output | ||
| + | ret = gpio_pin_configure_dt(& | ||
| + | if (ret < 0) | ||
| + | { | ||
| + | return 0; | ||
| + | } | ||
| + | |||
| + | // Do forever | ||
| + | while (1) | ||
| + | { | ||
| + | |||
| + | // Change the state of the pin and print | ||
| + | state = !state; | ||
| + | printk(" | ||
| + | |||
| + | // Set pin state | ||
| + | ret = gpio_pin_set_dt(& | ||
| + | if (ret < 0) | ||
| + | { | ||
| + | return 0; | ||
| + | } | ||
| + | |||
| + | // Sleep | ||
| + | k_msleep(sleep_time_ms); | ||
| + | } | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
zephyr.1745138174.txt.gz · Last modified: 2025/04/20 08:36 by utedass
