pw_stream_uart_mcuxpresso#
Stable
pw_stream_uart_mcuxpresso implements the pw_stream interface for reading
and writing to a UART using the NXP MCUXpresso SDK. UartStreamMcuxpresso
version uses the CPU to read and write to the UART, while DmaUartMcuxpresso
in pw_uart_mcuxpresso uses DMA transfers to read and write to the
UART minimizing the CPU utilization.
InterruptSafeUartWriterMcuxpresso implements an interrupt safe
write-only stream to UART. Intended for use in fault handlers. It can be
constructed constinit for use in pre-static constructor environments as well.
Note
This module is moving to pw_uart_mcuxpresso.
Setup#
This module requires a little setup:
Use
pw_build_mcuxpressoto create apw_source_setfor an MCUXpresso SDK.Include the debug console component in this SDK definition.
Specify the
pw_third_party_mcuxpresso_SDKGN global variable to specify the name of this source set.Use a target that calls
pw_sys_io_mcuxpresso_Initinpw_boot_PreMainInitor similar.
The name of the SDK source set must be set in the “pw_third_party_mcuxpresso_SDK” GN arg
Usage#
UartStreamMcuxpresso example:
1 constexpr uint32_t kFlexcomm = 0;
2 constexpr uint32_t kBaudRate = 115200;
3 std::array<std::byte, 20> kBuffer = {};
4
5 auto stream = pw::stream::UartStreamMcuxpresso{
6 USART0, kBaudRate, kUSART_ParityDisabled, kUSART_OneStopBit, kBuffer};
7
8 PW_TRY(stream.Init(CLOCK_GetFlexcommClkFreq(kFlexcomm)));
9
10 std::array<std::byte, 10> to_write = {};
11 PW_TRY(stream.Write(to_write));
InterruptSafeUartWriterMcuxpresso example:
1 constexpr uint32_t kBaudRate = 115200;
2 static pw::stream::InterruptSafeUartWriterMcuxpresso crash_safe_uart(
3 USART0_BASE, kCLOCK_Flexcomm0Clk, kBaudRate);
4
5 PW_TRY(crash_safe_uart.Enable());