-
Notifications
You must be signed in to change notification settings - Fork 2k
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
sys: make uart_stdio RX optional (attempt #2) #11310
Conversation
If I understand this correctly, it is currently impossible to have UART RX compiled in and be able to go to low power mode, right? So if the user wants to use the RX functionality, he has no way to disable it at runtime to be able to go to sleep. I'd rather not force the user into choosing either RX or low power. It is better to provide a run-time toggle for the RX function, or to bypass the low power block. From #7947 I get that this is only a problem on chips that don't have a low power capable UART. In those chips, bypassing the mode blockage would mean that there is no input until the MCU wakes up again. In #7947 (comment) you describe a possible solution which I believe is a good one. Also, I'm trying to find where in the RIOT code is the lpm block, but I cannot. Which CPUs have this limitation? |
Nope. On stm32, if an RX callback is configured and uart is initialized (and not powered off through uart_poweroff()), LPM is blocked such that RX still works. |
Thanks @vincent-d for taking over! |
Makefile.dep
Outdated
@@ -396,8 +396,20 @@ ifneq (,$(filter stdio_rtt,$(USEMODULE))) | |||
USEMODULE += xtimer | |||
endif | |||
|
|||
ifneq (,$(filter stdio_uart,$(USEMODULE))) | |||
ifneq (,$(filter shell,$(USEMODULE))) | |||
USEMODULE += stdio_uart_rx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this'll not work with stdio_rtt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe depend on an intermediate module like "stdio_input" and make that depend on stdio_uart_rx if stdio_uart is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just checked for stdio_uart
being used, is it good enough?
Makefile.dep
Outdated
USEMODULE += stdio_uart_rx | ||
endif | ||
|
||
ifneq (,$(filter rtt_stdio,$(USEMODULE))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this is unrelated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rebase mess I guess ;)
I'm not familiar with STM32, but googling around seems to indicate that it has the ability to be woken up from the UART. If that is the case then it is something that should be addressed by the periph implementation.
Ok, but what happens if the block is ignored and the device sleeps? Does anything break? Will the RX work after it wakes up again? If it is OK for a certain application to not have RX, then it does not matter if the answer is yer or no, and ignoring the blockage is enough to fix the issue (or, rather, work around the lack of low power uart in stm32). If the answer is "yes" (meaning after wake up the RX is still working) then ignoring the blockage, in combination with something like what @vincent-d proposes in #7947 (comment) is good too. In both cases, removing RX is a bit of an extreme measure. |
This usually loses the first byte, which may or may not be acceptable.
On stm32 (and most platforms I know), yes, unless the MCU sleeps too deep. On stm32, there's e.g., the standby mode, which would lose IO configuration and all RAM contents.
There's many ways to tackle this issue. As of now, if uart is initialized and powered with an RX callback, RX works, but blocks LPM. As long as we don't have a way to specify that losing bytes is acceptable, it should be that way. "certain applications" should not initialize uart with RX enabled (e.g., they should not pass an rx callback). This PR tackles the issue by making stdio RX optional, by not configuring it trough an RX callback. More elaborate alternatives would make stdio RX sleep controllable. Maybe make it only active when someone is waiting in a read() call comes to mind. |
@kaspar030 @jcarrano, I think this is in good shape and already provide an enhancement regarding power management, without the shell. I'm +1 for merging it. What's your opinion (e.g. do you ACK) ? |
Just gave it a last look. Unfortunately I just realized that as is I think it would break ethos if used with the same uart as stdio (e.g., on the border router or our suit examples). |
Please squash! |
386c187
to
002057f
Compare
Squashed |
cb = (uart_rx_cb_t) isrpipe_write_one; | ||
arg = &stdio_uart_isrpipe; | ||
#else | ||
#ifdef USE_ETHOS_FOR_STDIO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we could make stdio_uart_rx a dependency of ethos in the build system instead of preprocessor macros ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about this... @kaspar030 any opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, ethos itself doesn't need stdio_uart_rx.
stdio-over-ethos should probably be a pseudomodule...
I guess as is this is fine for now.
@kaspar030, can you give a final review and eventually ACK this one ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK.
Thanks @kaspar030 :) |
…_rx_optional" This change was breaking (dependencies for) ethos, shell, etc, as well as an unknown number of external apps (API change.) See RIOT-OS#11525 for more details. Fixes RIOT-OS#11525.
…ional" This change was breaking (dependencies for) ethos, shell, etc, as well as an unknown number of external apps (API change.) See RIOT-OS#11525 for more details. Fixes RIOT-OS#11525.
…ional" This change was breaking (dependencies for) ethos, and other serial users, as well as an unknown number of external apps (API change.). See RIOT-OS#11525 for more details. Fixes RIOT-OS#11525.
Is that due to taking too long to wake up and clear the receive buffer or is it actually a documented hardware limitation? I don't think I've ever had to tolerate that problem on any platform, but it's possible I've avoided it by shortening the wakeup sequence. I recall some time ago moving the main oscillator startup to a later point and making it conditional, but I don't remember if that was for the uart or just to avoid wasting power for xtimer overflow wakeups which come very frequently on EFM32. |
Contribution description
This is a rebase of #7974 that fixes conflicts. This allows to not block the low power mode if the shell is not used.
Issues/PRs references
#7974