Skip to content

Commit 43d214b

Browse files
jfischer-nocfriedt
authored andcommitted
samples: sensortile_box: get chosen console device from devicetree
Add app.overlay which contains chosen node Rework sample to get CDC ACM UART device from devicetree. Signed-off-by: Johann Fischer <[email protected]>
1 parent f460848 commit 43d214b

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
chosen {
9+
zephyr,console = &cdc_acm_uart0;
10+
};
11+
};
12+
13+
&zephyr_udc0 {
14+
cdc_acm_uart0: cdc_acm_uart0 {
15+
compatible = "zephyr,cdc-acm-uart";
16+
label = "CDC_ACM_0";
17+
};
18+
};

samples/boards/sensortile_box/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ CONFIG_USB_DEVICE_PRODUCT="Zephyr CDC SensorTile.box"
3232
CONFIG_USB_UART_CONSOLE=y
3333
CONFIG_UART_INTERRUPT_DRIVEN=y
3434
CONFIG_UART_LINE_CTRL=y
35-
CONFIG_UART_CONSOLE_ON_DEV_NAME="CDC_ACM_0"
3635
CONFIG_CBPRINTF_FP_SUPPORT=y

samples/boards/sensortile_box/src/main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,13 @@ static void iis3dhhc_config(const struct device *iis3dhhc)
250250
void main(void)
251251
{
252252
static const struct device *led0, *led1;
253-
const struct device *dev = device_get_binding(
254-
CONFIG_UART_CONSOLE_ON_DEV_NAME);
253+
const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
255254
int i, on = 1;
256255
int cnt = 1;
257256
uint32_t dtr = 0;
258257

259258
/* Application must enable USB by itself */
260-
if (usb_enable(NULL)) {
259+
if (!device_is_ready(dev) || usb_enable(NULL)) {
261260
return;
262261
}
263262

0 commit comments

Comments
 (0)