-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Description
Describe the bug
Hello,
When building an app that uses the uart and initialize it at runtime, I get a blocking call to uart_configure when PM is enabled.
For example, the following compilation command:
west build -p -b apollo3_evb -d build/app -s zephyr/samples/drivers/uart/native_tty/ -- -DCONFIG_BOOTLOADER_MCUBOOT=y -DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE=\"bootloader/mcuboot/root-rsa-2048.pem\" -DCONFIG_PM_DEVICE=y -DCONFIG_PM_DEVICE_SYSTEM_MANAGED=y -DCONFIG_PM_DEVICE_RUNTIME=y -DDTC_OVERLAY_FILE="$(pwd)/zephyr/samples/drivers/uart/native_tty/boards/native_sim.overlay"
with some modifications of the native_sim to remove the uart2 in the code and the overlay... and adding label = "uart0";
to the uart0 node.
When changing the sample app to not use DEVICE_DT_GET(DT_NODELABEL(uart0))
but device_get_binding("uart0");
called from main, uart is blocked waiting for the PM flag.
If I call pm_device_runtime_disable(uart0);
before using the uart, it works.
If I use DEVICE_DT_GET(DT_NODELABEL(uart0))
instead of device_get_binding("uart0");
, it works....
Why? What does the MACRO do that the device_get_binding does not?
I have not suc issue with other boards.
Thanks!
Attached a quick patch with my modifications to the native_tty code.
Regression
- This is a regression.
Steps to reproduce
Apply the following patch ( I cannot attach the file for some reason, so I put it here:)
diff --git a/samples/drivers/uart/native_tty/boards/native_sim.overlay b/samples/drivers/uart/native_tty/boards/native_sim.overlay
index 24f1bd95705..4a7d1b2218d 100644
--- a/samples/drivers/uart/native_tty/boards/native_sim.overlay
+++ b/samples/drivers/uart/native_tty/boards/native_sim.overlay
@@ -1,15 +1,9 @@
-/ {
- uart0: uart {
- status = "okay";
- compatible = "zephyr,native-tty-uart";
- current-speed = <115200>;
- serial-port = "/dev/ttyUSB0";
- };
- uart2: uart2 {
+ &uart0 {
status = "okay";
- compatible = "zephyr,native-tty-uart";
current-speed = <115200>;
- serial-port = "/dev/ttyUSB1";
+ label = "uart0";
+ zephyr,pm-device-runtime-auto;
};
-};
+
+
diff --git a/samples/drivers/uart/native_tty/src/main.c b/samples/drivers/uart/native_tty/src/main.c
index 1714328e0dc..21900200aed 100644
--- a/samples/drivers/uart/native_tty/src/main.c
+++ b/samples/drivers/uart/native_tty/src/main.c
@@ -14,10 +14,10 @@
#include <string.h>
const struct device *uart0 = DEVICE_DT_GET(DT_NODELABEL(uart0));
-const struct device *uart2 = DEVICE_DT_GET(DT_NODELABEL(uart2));
+//const struct device *uart2 = DEVICE_DT_GET(DT_NODELABEL(uart2));
struct uart_config uart_cfg = {
- .baudrate = 9600,
+ .baudrate = 115200,
.parity = UART_CFG_PARITY_NONE,
.stop_bits = UART_CFG_STOP_BITS_1,
.flow_ctrl = UART_CFG_FLOW_CTRL_NONE,
@@ -55,35 +55,39 @@ int main(void)
char recv_buf[64];
int i = 10;
+ uart0 = device_get_binding("uart0");
+ //pm_device_runtime_disable(uart0);
+
+ printk("uart0 dev: %p\n", uart0);
while (i--) {
snprintf(send_buf, 64, "Hello from device %s, num %d", uart0->name, i);
send_str(uart0, send_buf);
/* Wait some time for the messages to arrive to the second uart. */
k_sleep(K_MSEC(100));
- recv_str(uart2, recv_buf);
+ /*recv_str(uart2, recv_buf);
- k_sleep(K_MSEC(1000));
+ k_sleep(K_MSEC(1000));*/
}
- uart_cfg.baudrate = 9600;
+ uart_cfg.baudrate = 115200;
printk("\nChanging baudrate of both uart devices to %d!\n\n", uart_cfg.baudrate);
rc = uart_configure(uart0, &uart_cfg);
if (rc) {
printk("Could not configure device %s", uart0->name);
}
- rc = uart_configure(uart2, &uart_cfg);
+ /*rc = uart_configure(uart2, &uart_cfg);
if (rc) {
printk("Could not configure device %s", uart2->name);
- }
+ }*/
i = 10;
while (i--) {
snprintf(send_buf, 64, "Hello from device %s, num %d", uart0->name, i);
send_str(uart0, send_buf);
/* Wait some time for the messages to arrive to the second uart. */
- k_sleep(K_MSEC(100));
- recv_str(uart2, recv_buf);
+ /*k_sleep(K_MSEC(100));
+ recv_str(uart2, recv_buf);*/
k_sleep(K_MSEC(1000));
}
Build the sample app with the following flags:
west build -p -b apollo3_evb -d build/app -s zephyr/samples/drivers/uart/native_tty/ -- -DCONFIG_BOOTLOADER_MCUBOOT=y -DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE=\"bootloader/mcuboot/root-rsa-2048.pem\" -DCONFIG_PM_DEVICE=y -DCONFIG_PM_DEVICE_SYSTEM_MANAGED=y -DCONFIG_PM_DEVICE_RUNTIME=y -DDTC_OVERLAY_FILE="$(pwd)/zephyr/samples/drivers/uart/native_tty/boards/native_sim.overlay"
You should see multiple line in the uart:
uart0 dev: 0x1de98
Hello from device uart0, num 9Device uart0 sent: "Hello from device uart0, num 9"
Hello from device uart0, num 8Device uart0 sent: "Hello from device uart0, num 8"
Hello from device uart0, num 7Device uart0 sent: "Hello from device uart0, num 7"
Hello from device uart0, num 6Device uart0 sent: "Hello from device uart0, num 6"
Hello from device uart0, num 5Device uart0 sent: "Hello from device uart0, num 5"
Hello from device uart0, num 4Device uart0 sent: "Hello from device uart0, num 4"
Hello from device uart0, num 3Device uart0 sent: "Hello from device uart0, num 3"
Hello from device uart0, num 2Device uart0 sent: "Hello from device uart0, num 2"
Hello from device uart0, num 1Device uart0 sent: "Hello from device uart0, num 1"
Hello from device uart0, num 0Device uart0 sent: "Hello from device uart0, num 0"
Changing baudrate ofHello from device uart0, num 9Device uart0 sent: "Hello from device uart0, num 9"
Hello from device uart0, num 8Device uart0 sent: "Hello from device uart0, num 8"
Hello from device uart0, num 7Device uart0 sent: "Hello from device uart0, num 7"
Hello from device uart0, num 6Device uart0 sent: "Hello from device uart0, num 6"
Hello from device uart0, num 5Device uart0 sent: "Hello from device uart0, num 5"
Hello from device uart0, num 4Device uart0 sent: "Hello from device uart0, num 4"
Hello from device uart0, num 3Device uart0 sent: "Hello from device uart0, num 3"
Hello from device uart0, num 2Device uart0 sent: "Hello from device uart0, num 2"
Hello from device uart0, num 1Device uart0 sent: "Hello from device uart0, num 1"
Hello from device uart0, num 0Device uart0 sent: "Hello from device uart0, num 0"
Relevant log output
Impact
Annoyance – Minor irritation; no significant impact on usability or functionality.
Environment
No response
Additional Context
No response