Setting up Zephyr Environment
Detailed description about Zephyr environment can be found here. Since most of the prerequisites are common to other development, chances are you already have most of them installed on your computer. Ubuntu and its derivative users may need to uninstall outdated device-tree-compiler package and install new one by building from the sourceRunning a Sample Code
Grab one of the board listed as supported, clone the Zephyr source tree, go to one of the sample code directory and run:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source (Zephyr_Root)/zephyr-env.sh | |
mkdir build && cd build | |
cmake -GNiinja DBOARD=(your_board) | |
ninja | |
ninja flash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set (CMAKE_GENERATOR "Ninja" CACHE INTERNAL "" FORCE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.8.2) | |
set(BOARD disco_l475_iot1) | |
include($(ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) |
Blinky
We are going to use ST Disco L475 IoT01 board in this example. To control the GPIO, you need to have proper Kconfig settings. This is usually done by adding following line to the prj.conf file:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CONFIG_GPIO=y |
(SDK_ROOT)/boards/arm/disco_l475_iot1/disco_l475_iot1_defconfig
main.c would be
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <zephyr.h> | |
#include <misc/printk.h> | |
#include <gpio.h> | |
#define LED_PORT DT_GPIO_STM32_GPIOC_LABEL | |
#define LED_PIN 9 | |
void main(void) | |
{ | |
int cnt = 0; | |
struct device *dev; | |
dev = device_get_binding(LED_PORT); | |
gpio_pin_configure(dev, LED_PIN, GPIO_DIR_OUT); | |
while (1) | |
{ | |
gpio_pin_write(dev, LED_PIN, cnt % 2); | |
cnt++; | |
k_sleep(500); | |
} | |
} |
(SDK_ROOT)/soc/arm/st_stm32/stm32l4/dts_fixup.h
Comments
Post a Comment