[][src]Crate itm_logger

An implementation of the log facade that sends logging information over ITM stim port 0

Calls to logging macros optimize down to nothing if logging feature is not enabled.

Usage

use itm_logger::{
    logger_init,
    update_tpiu_baudrate,
    log,
    info,
    error,
    Level,
};

logger_init();
// if you change the CPU clock during boot up
let sysclk: Hertz = clocks.sysclk().into();
update_tpiu_baudrate(sysclk.0, ITM_BAUD_RATE).expect("Failed to reset TPIU baudrate");

perform-enabled-checks feature

Not enabled by default

Enabling this feature causes the logger to attempt to check if ITM is enabled before writing to it.

This should work on all cortex-m except M0. See is_debugger_attached documentation for more information.

Checks performed are:

  • Debug is enabled (DCB::DHCSR::DEBUGEN)
  • ITM is enabled (ITM::TCR::ITMENA)
  • Stim port we're using is enabled (ITM::TER[PORT])

Macros

debug

Re-export of log::debug if logging feature is enabled, stub if not Logs a message at the debug level.

error

Re-export of log::error if logging feature is enabled, stub if not Logs a message at the error level.

info

Re-export of log::info if logging feature is enabled, stub if not Logs a message at the info level.

log

The standard logging macro.

stub

A macro that accepts logging syntax but does no logging. It let _ = each of the parameters to avoid unused expression warnings when logging is disabled.

trace

Re-export of log::trace if logging feature is enabled, stub if not Logs a message at the trace level.

warn

Re-export of log::warn if logging feature is enabled, stub if not Logs a message at the warn level.

Enums

Level

An enum representing the available verbosity levels of the logger.

Functions

disable_logger

Globally disable all logging

enable_logger

Globally enable logging, level filtering is still performed

init_with_level

Initialise the logger and set the log level to the provided log_level

logger_init

Wrapper around init that panics if an error occurs

update_tpiu_baudrate

Updates the tpiu prescaler to output the desired baud rate trace_clk_freq: The frequency of TRACECLKIN in HZ, this is HCLK on most STM32 devices but is implementation specific. Check the ref manual for TRACECLKIN baud: The baud rate to set on SWO Returns an error if baud > trace_clk_freq or if trace_clk_freq % baud != 0