Skip to content

makefiles: filter stdio_default with STDIO_MODULES#22424

Open
basilfx wants to merge 8 commits into
RIOT-OS:masterfrom
basilfx:feature/fix_stdio_available
Open

makefiles: filter stdio_default with STDIO_MODULES#22424
basilfx wants to merge 8 commits into
RIOT-OS:masterfrom
basilfx:feature/fix_stdio_available

Conversation

@basilfx

@basilfx basilfx commented Jun 29, 2026

Copy link
Copy Markdown
Member

Contribution description

Filtering only on stdio_% is too greedy, and will match several pseudomodules such as stdio_available or stdio_nimble_debug. By moving the list of backends to a single source, the inclusion of stdio_default can be filtered correctly.

Noticed this while adding a new pseudomodule to the stdio module.

Testing procedure

Verify that USEMODULE=stdio_available make -C examples/basic/hello-world is not working (it does not print 'Hello World!' ).

Then apply this patch, and verify that it does work.

Verified this to work on native (defaults to stdio_native), sltb001a (defaults to stdio_uart) and pro-micro-nrf52840 (defaults to stdio_cdc_acm).

Issues/PRs references

None

Declaration of AI-Tools / LLMs usage:

AI-Tools / LLMs that were used are:

  • Claude Opus 4.8 to identify the root cause and potential fix, which I then performed myself.

Filtering only on `stdio_%` is too greedy, and will match several
pseudomodules such as `stdio_available`. By moving the list of
backends to a single source, the includsion of `stdio_default` can be
filtered correctly.
@basilfx basilfx added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jun 29, 2026
@github-actions github-actions Bot added the Area: build system Area: Build system label Jun 29, 2026
@crasbe crasbe requested a review from Teufelchen1 June 29, 2026 08:48
@riot-ci

riot-ci commented Jun 29, 2026

Copy link
Copy Markdown

Murdock results

✔️ PASSED

d525e15 sys/stdio: document available backends

Success Failures Total Runtime
167616 0 167616 02h:26m:52s

Artifacts

@crasbe crasbe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I have tested this with tests/minimal when commenting out stdio_null in tests/minimal/Makefile on native.

It is very possible that some corner cases rely on the current order of resolution, but this would be the cleaner approach IMO.

Comment thread makefiles/stdio_backends.inc.mk Outdated
Comment thread makefiles/stdio.inc.mk Outdated
Comment thread makefiles/stdio.inc.mk Outdated
Comment thread makefiles/stdio.inc.mk
Comment thread Makefile.dep Outdated
Comment thread makefiles/stdio.inc.mk Outdated
@crasbe

crasbe commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

It is very possible that some corner cases rely on the current order of resolution, but this would be the cleaner approach IMO.

Yes, there is no mechanism to select stdio_uart if stdio_default has been selected. Thec ompilation for nrf52840dk would therefore fail.

@crasbe

crasbe commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

It is very possible that some corner cases rely on the current order of resolution, but this would be the cleaner approach IMO.

Yes, there is no mechanism to select stdio_uart if stdio_default has been selected. Thec ompilation for nrf52840dk would therefore fail.

I wonder what the mechanism should be then, because currently stdio_default seems to always be selected if the application Makefile didn't explicitly select a different STDIO:

This is on master with $(info Selected STDIOs: $(filter stdio_%,$(USEMODULE))) added to the end of makefiles/stdio.inc.mk:

cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ BOARD=nrf52840dk make -C tests/sys/shell all -j
make: Entering directory '/home/cbuec/RIOTstuff/riot-vanillaice/RIOT/tests/sys/shell'
Selected STDIOs: stdio_default stdio_uart
Selected STDIOs: stdio_default stdio_uart stdio_uart_rx stdio_uart stdio_available
Selected STDIOs: stdio_available stdio_default stdio_uart stdio_uart_rx stdio_uart_rx stdio_uart stdio_available
...

With the unmodified tests/minimal on master, this is the output:

cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ BOARD=nrf52840dk make -C tests/minimal/ all -j
make: Entering directory '/home/cbuec/RIOTstuff/riot-vanillaice/RIOT/tests/minimal'
Selected STDIOs: stdio_null
Selected STDIOs: stdio_null
Selected STDIOs: stdio_null
...

When commenting out stdio_null in the tests/minimal/Makefile, we get this:

cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ BOARD=nrf52840dk make -C tests/minimal/ all -j
make: Entering directory '/home/cbuec/RIOTstuff/riot-vanillaice/RIOT/tests/minimal'
Selected STDIOs: stdio_default stdio_uart
Selected STDIOs: stdio_default stdio_uart
Selected STDIOs: stdio_default stdio_uart

=> always stdio_default and stdio_uart selected.

For native it does not select the UART, because stdio_native is selected in the CPU Makefiles of native, which are evaluated before the sys/Makefile.dep which includes makefiles/stdio.inc.mk:

cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ BOARD=native make -C tests/minimal/ all -j
make: Entering directory '/home/cbuec/RIOTstuff/riot-vanillaice/RIOT/tests/minimal'
using BOARD="native64" as "native" on a 64-bit system
Selected STDIOs: stdio_default stdio_native
Selected STDIOs: stdio_default stdio_native stdio_native
Selected STDIOs: stdio_default stdio_native stdio_native

Comment thread makefiles/stdio.inc.mk
@basilfx

basilfx commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

I have now moved the default stdio backend selection to stdio.inc.mk and removed the stdio_backends.inc.mk.

Tested this again on the sltb001a, pro-micro-nrf52840 and native. All seem to work correctly.

When squashing, I'll have to update the original commit message, since the description is not accurate anymore.

Comment thread makefiles/stdio.inc.mk Outdated
@crasbe crasbe added CI: full build disable CI build filter CI: no fast fail don't abort PR build after first error labels Jun 30, 2026
@crasbe

crasbe commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

So the issue with the failing boards is that there is no mechanism to add the periph_uart as a required feature when periph_lpuart is used. And in this case periph_lpuart is selected first because FEATURES_REQUIRED_ANY has the option to choose either periph_uart or periph_lpuart.

However, the nucleo-g474re and the other failing boards will select periph_lpuart when stdio_uart is present:

ifneq (,$(filter stdio_uart,$(USEMODULE)))
FEATURES_REQUIRED += periph_lpuart
endif

I haven't quite followed the mechanism why it worked before.

This is the difference between info-build on master vs this PR:
image

But I found a fix:

diff --git a/cpu/stm32/Makefile.dep b/cpu/stm32/Makefile.dep
index 188875ea8c..4ef714620b 100644
--- a/cpu/stm32/Makefile.dep
+++ b/cpu/stm32/Makefile.dep
@@ -29,6 +29,10 @@ ifneq (,$(filter periph_usbdev,$(FEATURES_USED)))
   endif
 endif

+# always require periph_uart when using periph_lpuart because they share code internally
+ifneq (,$(filter periph_lpuart,$(FEATURES_USED)))
+  FEATURES_REQUIRED += periph_uart
+endif
+
 ifneq (,$(filter periph_uart_nonblocking,$(USEMODULE)))
   USEMODULE += tsrb
 endif

With this change, the periph_uart is always added when periph_lpuart is used.

Without this dependency, no stdio module will be selected. Because
they depend on each other internally, it makes sense to add this
dependency.
@github-actions github-actions Bot added Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: cpu Area: CPU/MCU ports labels Jun 30, 2026
@basilfx

basilfx commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

That seems to have done the trick!

Time for and squash and a final test?

@AnnsAnns

AnnsAnns commented Jul 1, 2026

Copy link
Copy Markdown
Member

I feel like this should be documented somewhere but I am also not too sure where exactly

@crasbe

crasbe commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

I feel like this should be documented somewhere but I am also not too sure where exactly

image

https://github.com/RIOT-OS/RIOT/blob/master/sys/stdio/doc.md

Here?

@basilfx

basilfx commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

Here?

Let me propose something, on it.

@basilfx basilfx requested a review from jia200x as a code owner July 2, 2026 19:20
@github-actions github-actions Bot added Area: doc Area: Documentation Area: sys Area: System labels Jul 2, 2026
@basilfx

basilfx commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

With a bit of help from Claude, I have come up with something for the documentation.

@crasbe crasbe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The static test has some complaints about trailing whitespaces.

Comment thread sys/stdio/doc.md
| Module | Description |
|:----------------------- |:-------------------------------------------------------- |
| `stdio_cdc_acm` | USB CDC ACM STDIO, see @ref usbus_cdc_acm_stdio |
| `stdio_ethos` | Ethernet-over-serial STDIO (legacy, see `ethos`) |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today I learned we have an "Ethernet over Serial" module. That's quite awesome, if it was more documented :(

But that is unrelated to your PR

Comment thread sys/stdio/doc.md
| `stdio_tinyusb_cdc_acm` | USB CDC ACM STDIO on top of the tinyUSB stack |
| `stdio_uart` | UART STDIO, see @ref sys_stdio_uart |
| `stdio_udp` | UDP STDIO |
| `stdio_usb_serial_jtag` | USB serial/JTAG STDIO (e.g. on some ESP32 variants) |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `stdio_usb_serial_jtag` | USB serial/JTAG STDIO (e.g. on some ESP32 variants) |
| `stdio_usb_serial_jtag` | USB Serial/JTAG STDIO (e.g. on some ESP32 variants) |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: build system Area: Build system Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: sys Area: System CI: full build disable CI build filter CI: no fast fail don't abort PR build after first error CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants