Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot initialize multiple stdio UART driver instances #1025

Open
alastairpatrick opened this issue Sep 13, 2022 · 4 comments
Open

Cannot initialize multiple stdio UART driver instances #1025

alastairpatrick opened this issue Sep 13, 2022 · 4 comments
Milestone

Comments

@alastairpatrick
Copy link
Contributor

alastairpatrick commented Sep 13, 2022

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");
@kilograham kilograham added this to the 1.7.0 milestone May 26, 2023
@kilograham
Copy link
Contributor

Having uart0_handle and uart1_handle is quite a nice idea

@ekholm
Copy link

ekholm commented Sep 18, 2024

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
Copy link
Contributor

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

@kilograham
Copy link
Contributor

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants