Skip to content

Commit

Permalink
[board] Default putchar_ to use the board logger
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Sep 10, 2023
1 parent 32adefe commit 93af956
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
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

0 comments on commit 93af956

Please sign in to comment.