Skip to content

Commit d1c935e

Browse files
gmarullnashif
authored andcommitted
app: initial application skeleton
initial application skeleton demonstrating: - custom boards - custom DT bindings - Out-of-tree drivers Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent 36602d0 commit d1c935e

31 files changed

+558
-2
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# editors
2+
.vscode
3+
*.swp
4+
*~
5+
6+
# python
7+
.venv
8+
9+
# build
10+
/build*

CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# This CMake file is picked by the Zephyr build system because it is defined
5+
# as the module CMake entry point (see zephyr/module.yml).
6+
7+
add_subdirectory(drivers)

Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# This Kconfig file is picked by the Zephyr build system because it is defined
5+
# as the module Kconfig entry point (see zephyr/module.yml). You can browse
6+
# module options by going to Zephyr -> Modules in Kconfig.
7+
8+
rsource "drivers/Kconfig"

README.md

+58-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,58 @@
1-
# example-application
2-
Example out-of-tree application that is also a module
1+
# Zephyr Example Application
2+
3+
This repository contains a Zephyr example application. The main purpose of this
4+
repository is to serve as a reference on how to structure Zephyr based
5+
applications. Some of the features demonstrated in this example are:
6+
7+
- Basic application skeleton
8+
- [Custom boards][board_porting]
9+
- Custom [devicetree bindings][bindings]
10+
- Out-of-tree [drivers][drivers]
11+
- Documentation using Doxygen and Sphinx
12+
- Example CI configuration (using Github Actions)
13+
14+
[board_porting]: https://docs.zephyrproject.org/latest/guides/porting/board_porting.html
15+
[bindings]: https://docs.zephyrproject.org/latest/guides/dts/bindings.html
16+
[drivers]: https://docs.zephyrproject.org/latest/reference/drivers/index.html
17+
18+
## Getting Started
19+
20+
Before getting started, make sure you have a proper Zephyr development
21+
environment. You can follow the official
22+
[Zephyr Getting Started Guide](https://docs.zephyrproject.org/latest/getting_started/index.html).
23+
24+
### Initialization
25+
26+
The first step is to initialize the workspace folder (``my-workspace``) where
27+
the ``example-application`` and all Zephyr modules will be cloned. You can do
28+
that by running:
29+
30+
```shell
31+
# initialize my-workspace for the example-application (main branch)
32+
west init -m https://github.com/zephyrproject-rtos/example-application --mr main my-workspace
33+
# update Zephyr modules
34+
cd my-workspace
35+
west update
36+
```
37+
38+
### Build & Run
39+
40+
The application can be built by running:
41+
42+
```shell
43+
west build -b $BOARD -s app
44+
```
45+
46+
where `$BOARD` is the target board. A sample debug configuration is also
47+
provided. You can apply it by running:
48+
49+
```shell
50+
west build -b $BOARD -s app -- -DOVERLAY_CONFIG=debug.conf
51+
```
52+
53+
Note that you may also use it together with `rtt.conf` if using Segger RTT. Once
54+
you have built the application you can flash it by running:
55+
56+
```shell
57+
west flash
58+
```

app/CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#-------------------------------------------------------------------------------
2+
# Zephyr Example Application
3+
#
4+
# Copyright (c) 2021 Nordic Semiconductor ASA
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
cmake_minimum_required(VERSION 3.13.1)
8+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
9+
10+
project(app LANGUAGES C VERSION 1.0.0)
11+
12+
configure_file(app_version.h.in ${CMAKE_BINARY_DIR}/app/include/app_version.h)
13+
target_include_directories(app PRIVATE ${CMAKE_BINARY_DIR}/app/include src)
14+
15+
target_sources(app PRIVATE src/main.c src/foo.c)

app/Kconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# This file is the application Kconfig entry point. All application Kconfig
5+
# options can be defined here or included via other application Kconfig files.
6+
# You can browse these options using the west targets menuconfig (terminal) or
7+
# guiconfig (GUI).
8+
9+
menu "Zephyr"
10+
source "Kconfig.zephyr"
11+
endmenu
12+
13+
module = APP
14+
module-str = APP
15+
source "subsys/logging/Kconfig.template.log_config"

app/app_version.h.in

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @file app_version.h
3+
*
4+
* Application version information.
5+
*
6+
* Copyright (c) 2021 Nordic Semiconductor ASA
7+
* SPDX-License-Identifier: Apache-2.0
8+
*/
9+
10+
#ifndef APP_VERSION_H_
11+
#define APP_VERSION_H_
12+
13+
/** Application major version. */
14+
#define APP_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}
15+
/** Application minor version. */
16+
#define APP_VERSION_MINOR ${PROJECT_VERSION_MINOR}
17+
/** Application patch version. */
18+
#define APP_VERSION_PATCH ${PROJECT_VERSION_PATCH}
19+
20+
/** Application version. */
21+
#define APP_VERSION \
22+
((APP_VERSION_MAJOR << 16) + \
23+
(APP_VERSION_MINOR << 8) + \
24+
APP_VERSION_PATCH)
25+
26+
/** Application version (string). */
27+
#define APP_VERSION_STR "${PROJECT_VERSION}"
28+
29+
#endif /* APP_VERSION_H_ */

app/debug.conf

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# This is a Kconfig fragment which can be used to enable debug-related options
5+
# in the application. See the README for more details.
6+
7+
# compiler
8+
CONFIG_DEBUG_OPTIMIZATIONS=y
9+
10+
# console
11+
CONFIG_CONSOLE=y
12+
13+
# UART console
14+
CONFIG_SERIAL=y
15+
CONFIG_UART_CONSOLE=y
16+
17+
# logging
18+
CONFIG_LOG=y
19+
CONFIG_APP_LOG_LEVEL_DBG=y

app/prj.conf

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# This file contains selected Kconfig options for the application.
5+
6+
CONFIG_SENSOR=y
7+
CONFIG_EXAMPLESENSOR=y

app/rtt.conf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# This is a Kconfig fragment which can be used to enable Segger RTT options.
5+
# It should be used in conjunction with debug.conf.
6+
7+
# segger RTT console
8+
CONFIG_USE_SEGGER_RTT=y
9+
CONFIG_RTT_CONSOLE=y

app/src/foo.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "foo.h"
7+
8+
int app_foo_bar(void)
9+
{
10+
return 0;
11+
}

app/src/foo.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @file foo.h
3+
*
4+
* Foo API.
5+
*
6+
* Copyright (c) 2021 Nordic Semiconductor ASA
7+
* SPDX-License-Identifier: Apache-2.0
8+
*/
9+
10+
#ifndef _FOO_H_
11+
#define _FOO_H_
12+
13+
/**
14+
* @defgroup app_foo Foo API
15+
*
16+
* A detailed description of the foo API.
17+
*
18+
* @{
19+
*/
20+
21+
/**
22+
* @brief An example foo API call.
23+
*
24+
* @return 0 on success, negative errno otherwise.
25+
*/
26+
int app_foo_bar(void);
27+
28+
/** @} */
29+
30+
#endif /* _FOO_H_ */

app/src/main.c

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr.h>
7+
#include <drivers/sensor.h>
8+
9+
#include "app_version.h"
10+
#include "foo.h"
11+
12+
#include <logging/log.h>
13+
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
14+
15+
void main(void)
16+
{
17+
int ret;
18+
const struct device *sensor;
19+
20+
printk("Zephyr Example Application %s\n", APP_VERSION_STR);
21+
22+
ret = app_foo_bar();
23+
if (ret < 0) {
24+
LOG_ERR("app_foo_bar failed (%d)", ret);
25+
return;
26+
}
27+
28+
sensor = DEVICE_DT_GET(DT_NODELABEL(examplesensor0));
29+
if (!device_is_ready(sensor)) {
30+
LOG_ERR("Sensor not ready");
31+
return;
32+
}
33+
34+
while (1) {
35+
struct sensor_value val;
36+
37+
ret = sensor_sample_fetch(sensor);
38+
if (ret < 0) {
39+
LOG_ERR("Could not fetch sample (%d)", ret);
40+
return;
41+
}
42+
43+
ret = sensor_channel_get(sensor, SENSOR_CHAN_PROX, &val);
44+
if (ret < 0) {
45+
LOG_ERR("Could not get sample (%d)", ret);
46+
return;
47+
}
48+
49+
printk("Sensor value: %d\n", val.val1);
50+
51+
k_sleep(K_MSEC(1000));
52+
}
53+
}
54+

boards/arm/custom_plank/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config BOARD_ENABLE_DCDC
5+
bool "Enable DCDC mode"
6+
select SOC_DCDC_NRF52X
7+
default y
8+
depends on BOARD_CUSTOM_PLANK

boards/arm/custom_plank/Kconfig.board

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config BOARD_CUSTOM_PLANK
5+
bool "Custom Plank Board"
6+
depends on SOC_NRF52840_QIAA
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if BOARD_CUSTOM_PLANK
5+
6+
config BOARD
7+
default "custom_plank"
8+
9+
endif # BOARD_CUSTOM_PLANK

boards/arm/custom_plank/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Custom Plank Board
2+
3+
`custom_plank` board is used to demonstrate how to create custom boards. It is
4+
in fact a simplified version of the nRF52840-DK board, so the
5+
`example-application` can be run on that development kit when using
6+
`custom_plank`.

boards/arm/custom_plank/board.cmake

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
board_runner_args(jlink "--device=nrf52" "--speed=4000")
5+
board_runner_args(pyocd "--target=nrf52840" "--frequency=4000000")
6+
7+
set(OPENOCD_NRF5_SUBFAMILY "nrf52")
8+
9+
include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake)
10+
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
11+
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
12+
include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake)
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/dts-v1/;
7+
#include <nordic/nrf52840_qiaa.dtsi>
8+
9+
/ {
10+
model = "Custom Plank Board";
11+
compatible = "vendor,custom-plank";
12+
13+
chosen {
14+
zephyr,console = &uart0;
15+
zephyr,sram = &sram0;
16+
zephyr,flash = &flash0;
17+
};
18+
19+
examplesensor0: examplesensor_0 {
20+
compatible = "zephyr,examplesensor";
21+
label = "EXAMPLESENSOR_0";
22+
input-gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
23+
};
24+
};
25+
26+
&gpio0 {
27+
status = "okay";
28+
};
29+
30+
&uart0 {
31+
compatible = "nordic,nrf-uarte";
32+
status = "okay";
33+
34+
current-speed = <115200>;
35+
tx-pin = <6>;
36+
rx-pin = <8>;
37+
rts-pin = <5>;
38+
cts-pin = <7>;
39+
};
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
identifier: custom_plank
5+
name: Custom-Plank
6+
type: mcu
7+
arch: arm
8+
ram: 256
9+
flash: 1024
10+
toolchain:
11+
- zephyr
12+
- gnuarmemb
13+
- xtools
14+
supported:
15+
- gpio

0 commit comments

Comments
 (0)