User Tools

Site Tools


zephyr

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
zephyr [2025/04/20 10:48] – [Devicetree] utedasszephyr [2025/12/03 21:35] (current) – [Länkar] utedass
Line 4: Line 4:
 ===== Länkar ===== ===== Länkar =====
  
 +  * [[https://github.com/Utedass/zephyr-workspace]] -- My own devcontainer setup for Zephyr development
   * [[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   * [[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
 +  * [[https://www.youtube.com/watch?v=tAH5fy0rSo4|Youtube Linux Foundation]] -- Zephyr Project: RTOS Start-up and Initialization Flow
 +
 +  * [[https://interrupt.memfault.com/blog/building-drivers-on-zephyr]]
 +
 +  * [[https://community.circuitdojo.com/d/146-zephyr-driver-development-use-of-i2c-and-spi-apis]]
 +
 +== Real world examples == 
 +  * [[https://github.com/zephyrproject-rtos/awesome-zephyr-rtos/tree/main]] -- Awezome Zephyr related list
 +  * [[https://github.com/xycloo/zephyr-examples/tree/master]] -- Rust examples
 +  * [[https://github.com/zmkfirmware/zmk/tree/main]] -- Zephyr Mechanical Keyboard
 +  * [[https://github.com/jakkra/ZSWatch/tree/main]] -- Open Source Smart Watch
 +
  
 == Shawn Hymel / Digikey == == Shawn Hymel / Digikey ==
Line 40: Line 53:
 <code> <code>
 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
 +</code>
 +
 +===== Platser =====
 +| ''zephyr/dts/<arch>/<mfr>/<soc>/'' | .dtsi filer för olika chip |
 +| ''zephyr/dts/bindings/<feature>/<compatible>.yaml'' | .yaml binding-filer för olika chips drivrutiner |
 +| ''zephyr/boards/<mfr>/<board>/'' | .dts, Kconfig och default configs för boards |
 +| ''zephyr/soc/<mfr>/<soc>/soc.h'' | Startup-kod, HAL-includes etc för specifikt chip |
 +| ''zephyr/arch/<arch>/core/'' | Assembler-startup etc för specifik arkitektur |
 +===== 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 "${CMAKE_SOURCE_DIR}/../../modules/say_hello")
 +
 +# Mandatory thing
 +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
 +
 +# Name your project
 +project(random)
 +
 +# Adds your main entry point to the Zephyr-created "app" lib
 +target_sources(app PRIVATE src/main.c)
 +
 +</code>
 +
 +=== 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()
 </code> </code>
  
Line 50: Line 104:
 </code> </code>
  
-Sparas till ./build/zephyr/.config som kommer tas bort vid nästa bygge.+Sparas till ''./build/zephyr/.config'' som kommer tas bort vid nästa bygge. 
 + 
 +Generates an include file in ''build/zephyr/include/generated/zephyr/autoconf.h''
  
 För att göra persistent, kolla diff mellan ./build/zephyr/.config.old För att göra persistent, kolla diff mellan ./build/zephyr/.config.old
Line 86: Line 142:
 </code> </code>
  
 +==== 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. 
 +
 +<code>
 +# 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   # Make it dependent on PRINTK
 +    help
 +        Adds say_hello() function to print a basic message to the console.
 +</code>
 +
 +Lägg även till en mapp som heter exakt ''zephyr'' i modulens mapp. Lägg in en fil som heter exakt  ''module.yaml'' med likande innehåll. kconfig: pekar ut KConfig-filen ovan.
 +
 +<code yaml>
 +name: say_hello
 +build:
 +  cmake: .
 +  kconfig: Kconfig
 +</code>
 ===== Devicetree ===== ===== Devicetree =====
  
Line 91: Line 168:
   * [[https://docs.zephyrproject.org/3.7.0/build/dts/index.html|Zephyr DTS page]]   * [[https://docs.zephyrproject.org/3.7.0/build/dts/index.html|Zephyr DTS page]]
   * [[https://docs.zephyrproject.org/3.7.0/build/dts/bindings-syntax.html|Zephyr DTS bindings]]   * [[https://docs.zephyrproject.org/3.7.0/build/dts/bindings-syntax.html|Zephyr DTS bindings]]
 +
 +The final devicetree will end up under ''build/zephyr/zephyr.dts''.
 +
 +There is an include file generated from this in ''build/zephyr/include/generated/zephyr/devicetree_generated.h''
  
 === Words === === Words ===
Line 266: Line 347:
 </code> </code>
  
 +==== Overlay files ====
 +
 +== Example ==
 +''boards/esp32s3_devkitc.overlay''
 +<code>
 +/ {
 +    aliases {
 +        my-led = &led0;
 +    };
 +
 +    leds {
 +        compatible = "gpio-leds";
 +        led0: d5 {
 +            gpios = <&gpio0 5 GPIO_ACTIVE_HIGH>;
 +        };
 +    };
 +};
 +</code>
 +===== C-kod =====
 +== Exempel blink ==
 +<code c>
 +#include <stdio.h>
 +#include <zephyr/kernel.h>
 +#include <zephyr/drivers/gpio.h>
 +
 +// Settings
 +static const int32_t sleep_time_ms = 1000;
 +static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(my_led), gpios);
 +
 +int main(void)
 +{
 + int ret;
 + int state = 0;
 +
 + // Make sure that the GPIO was initialized
 + if (!gpio_is_ready_dt(&led))
 + {
 + return 0;
 + }
 +
 + // Set the GPIO as output
 + ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT);
 + if (ret < 0)
 + {
 + return 0;
 + }
 +
 + // Do forever
 + while (1)
 + {
 +
 + // Change the state of the pin and print
 + state = !state;
 + printk("LED state: %d\r\n", state);
 +
 + // Set pin state
 + ret = gpio_pin_set_dt(&led, state);
 + if (ret < 0)
 + {
 + return 0;
 + }
 +
 + // Sleep
 + k_msleep(sleep_time_ms);
 + }
 +
 + return 0;
 +}
 +</code>
zephyr.1745146118.txt.gz · Last modified: 2025/04/20 10:48 by utedass

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki