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

[board] Default putchar_ to use the board logger #1069

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions examples/stm32f469_discovery/printf/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@

#include <modm/board.hpp>

extern "C"
void putchar_(char c)
{
// Redirect the printf output to UART.
Board::stlink::Uart::write(c);
// or IOStream if the board already has a logger
// MODM_LOG_INFO << c;
}

// ----------------------------------------------------------------------------
int
main()
{
Expand Down
11 changes: 9 additions & 2 deletions src/modm/board/board.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
%% if with_assert
#include <modm/architecture/interface/assert.hpp>
%% endif

%#
%% if with_logger
Board::LoggerDevice loggerDevice;

Expand All @@ -23,8 +23,15 @@ modm::log::Logger modm::log::debug(loggerDevice);
modm::log::Logger modm::log::info(loggerDevice);
modm::log::Logger modm::log::warning(loggerDevice);
modm::log::Logger modm::log::error(loggerDevice);
%% endif

// Default all calls to printf to the UART
modm_extern_c void
putchar_(char c)
{
loggerDevice.write(c);
}
%% endif
%#
%% if with_assert
modm_extern_c void
modm_abandon(const modm::AssertionInfo &info)
Expand Down
3 changes: 2 additions & 1 deletion src/modm/board/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ The BSPs all use a common interface within a top-level `namespace Board`:
`modm::platform::Gpio{port}{pin}`.

If the board supports a dedicated serial logging output the BSP redirects the
`modm:debug` module debug stream `MODM_LOG_INFO` etc.
`modm:debug` module debug stream `MODM_LOG_INFO` as well as the output of the
standalone `printf` function.

Please note that YOU must explicitly call the `Board` functions to initialize
your hardware, just including the board module is not enough.
Expand Down
Loading