Cannot initialize multiple stdio UART driver instances #1025

Open
opened 2022-09-13 15:05:43 -05:00 by alastairpatrick · 4 comments
alastairpatrick commented 2022-09-13 15:05:43 -05:00 (Migrated from github.com)

The API does not prevent an attempt to initialize multiple UART stdio driver instances. I can't find any documentation saying this isn't allowed. It would also be possible to implement. For example:

int main() {
  stdio_uart_init_full(uart0, 115200, 0, 1);
  stdio_uart_init_full(uart1, 115200, 6, 7);

  printf("Hello world!\r\n");

  for (;;);
}

The expectation here might be that the greeting is output to both UARTs.

This could be fixed by changing the documentation and maybe adding a runtime assertion or by actually making it work.

If it's going to work, issue #811 is impacted because the signature of stdio_uart_deinit_full() should change to identify which UART driver instance is uninitialized:

void stdio_uart_deinit_full(uart_inst_t* instance, int tx_pin, int rx_pin);

Somewhat more involved, it would be useful if something like this worked:

  stdio_uart_init_full(uart0, 115200, 0, 1);
  stdio_uart_init_full(uart1, 115200, 6, 7);

  fprintf(uart0_handle, "Hello from uart0!\r\n");

  fprintf(uart1_handle, "Hello from uart1!\r\n");
The API does not prevent an attempt to initialize multiple UART stdio driver instances. I can't find any documentation saying this isn't allowed. It would also be possible to implement. For example: ```c int main() { stdio_uart_init_full(uart0, 115200, 0, 1); stdio_uart_init_full(uart1, 115200, 6, 7); printf("Hello world!\r\n"); for (;;); } ```` The expectation here might be that the greeting is output to both UARTs. This could be fixed by changing the documentation and maybe adding a runtime assertion or by actually making it work. If it's going to work, issue #811 is impacted because the signature of stdio_uart_deinit_full() should change to identify which UART driver instance is uninitialized: ```c void stdio_uart_deinit_full(uart_inst_t* instance, int tx_pin, int rx_pin); ``` Somewhat more involved, it would be useful if something like this worked: ```c stdio_uart_init_full(uart0, 115200, 0, 1); stdio_uart_init_full(uart1, 115200, 6, 7); fprintf(uart0_handle, "Hello from uart0!\r\n"); fprintf(uart1_handle, "Hello from uart1!\r\n"); ```
kilograham commented 2023-05-26 10:35:53 -05:00 (Migrated from github.com)

Having uart0_handle and uart1_handle is quite a nice idea

Having `uart0_handle` and `uart1_handle` is quite a nice idea
ekholm commented 2024-09-18 05:39:57 -05:00 (Migrated from github.com)

May I suggest to use the more standard handles, stdout and stderr, stdin.
And in startup code application can initialize which uart(or usb) is what pipe

May I suggest to use the more standard handles, stdout and stderr, stdin. And in startup code application can initialize which uart(or usb) is what pipe
kilograham commented 2024-09-18 12:48:09 -05:00 (Migrated from github.com)

Somewhat more involved, it would be useful if something like this worked:

stdio_uart_init_full(uart1, 115200, 6, 7);

fprintf(uart0_handle, "Hello from uart0!\r\n");

fprintf(uart1_handle, "Hello from uart1!\r\n");

See #1715 which would add support for more handles

> Somewhat more involved, it would be useful if something like this worked: > ``` stdio_uart_init_full(uart0, 115200, 0, 1); > stdio_uart_init_full(uart1, 115200, 6, 7); > > fprintf(uart0_handle, "Hello from uart0!\r\n"); > > fprintf(uart1_handle, "Hello from uart1!\r\n"); >``` See #1715 which would add support for more handles
kilograham commented 2024-09-18 12:49:20 -05:00 (Migrated from github.com)

May I suggest to use the more standard handles, stdout and stderr, stdin. And in startup code application can initialize which uart(or usb) is what pipe

I think @alastairpatrick 's point was that the uartn_ handles could be used in addition to stdout etc. for finer grained control

> May I suggest to use the more standard handles, stdout and stderr, stdin. And in startup code application can initialize which uart(or usb) is what pipe I think @alastairpatrick 's point was that the `uartn_` handles could be used in addition to `stdout` etc. for finer grained control
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#1025
No description provided.