Skip to content

Commit 293f573

Browse files
committed
samples: boards: rpi_pico: Added PIO shell uart example
Simple example showing how to use the PIO based uart as a console / log backend. Signed-off-by: TOKITA Hiroshi <[email protected]> Signed-off-by: Yonatan Schachter <[email protected]> Signed-off-by: Ionut Catalin Pavel <[email protected]>
1 parent f1bfcf0 commit 293f573

File tree

6 files changed

+66
-74
lines changed

6 files changed

+66
-74
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# SPDX-License-Identifier: Apache-2.0
2-
3-
cmake_minimum_required(VERSION 3.20.0)
1+
cmake_minimum_required(VERSION 3.15.0)
42
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5-
project(uart_pio)
3+
project(pio_shell_uart)
64

75
target_sources(app PRIVATE src/main.c)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2023, Ionut Pavel <[email protected]>
3+
* Copyright (c) 2023 Yonatan Schachter
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#include <zephyr/dt-bindings/pinctrl/rpi-pico-rp2040-pinctrl.h>
9+
10+
&pinctrl {
11+
pio0_uart0_default: pio0_uart0_default {
12+
tx_gpio {
13+
pinmux = <PIO0_P0>;
14+
};
15+
16+
rx_gpio {
17+
pinmux = <PIO0_P1>;
18+
input-enable;
19+
bias-pull-up;
20+
};
21+
};
22+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "app-pinctrl.dtsi"
2+
3+
/ {
4+
chosen {
5+
zephyr,console = &pio0_uart0;
6+
zephyr,shell-uart = &pio0_uart0;
7+
};
8+
};
9+
10+
&uart0 {
11+
status = "disabled";
12+
};
13+
14+
&pio0 {
15+
status = "okay";
16+
17+
pio0_uart0: pio0_uart0 {
18+
compatible = "raspberrypi,pico-uart-pio";
19+
20+
status = "okay";
21+
22+
pio,interrupts = <0>;
23+
pio,interrupt-names = "shared";
24+
25+
pinctrl-0 = <&pio0_uart0_default>;
26+
pinctrl-names = "default";
27+
28+
current-speed = <115200>;
29+
};
30+
};

samples/boards/rpi_pico/uart_pio/boards/rpi_pico.overlay

-45
This file was deleted.
+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
# nothing here
1+
CONFIG_LOG=y
2+
CONFIG_SHELL=y
3+
CONFIG_SERIAL=y
4+
CONFIG_UART_INTERRUPT_DRIVEN=y
5+
CONFIG_UART_CONSOLE=y
+7-24
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,19 @@
11
/*
2+
* Copyright (c) 2023 Ionut Pavel <[email protected]>
23
* Copyright (c) 2023 Yonatan Schachter
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
67

78
#include <zephyr/kernel.h>
8-
#include <zephyr/device.h>
9-
#include <zephyr/drivers/uart.h>
109

11-
int main(void)
12-
{
13-
char data;
14-
const struct device *uart0 = DEVICE_DT_GET(DT_NODELABEL(pio1_uart0));
15-
const struct device *uart1 = DEVICE_DT_GET(DT_NODELABEL(pio1_uart1));
16-
17-
if (!device_is_ready(uart0)) {
18-
return 0;
19-
}
20-
21-
if (!device_is_ready(uart1)) {
22-
return 0;
23-
}
10+
#include <zephyr/logging/log.h>
11+
LOG_MODULE_REGISTER(main);
2412

13+
void main(void)
14+
{
2515
while (1) {
26-
if (!uart_poll_in(uart0, &data)) {
27-
uart_poll_out(uart0, data);
28-
}
29-
30-
if (!uart_poll_in(uart1, &data)) {
31-
uart_poll_out(uart1, data);
32-
}
16+
k_msleep(1000);
17+
LOG_INF("One second passed...");
3318
}
34-
35-
return 0;
3619
}

0 commit comments

Comments
 (0)