pw_uart_mcuxpresso#
pw_uart_mcuxpresso
implements the pw_uart
interface for reading
and writing to a UART using the NXP MCUXpresso SDK.
The only implementation currently provided is DmaUartMcuxpresso
, which
uses DMA transfers to read and write to the UART, minimizing CPU utilization.
Note
For a simpler UART interface, see pw_stream_uart_mcuxpresso
.
Setup#
This module requires a little setup:
Use
pw_build_mcuxpresso
to create apw_source_set
for an MCUXpresso SDK.Include the debug console component in this SDK definition.
Specify the
pw_third_party_mcuxpresso_SDK
GN global variable to specify the name of this source set.Use a target that calls
pw_sys_io_mcuxpresso_Init
inpw_boot_PreMainInit
or similar.
The name of the SDK source set must be set in the “pw_third_party_mcuxpresso_SDK” GN arg
Usage#
DmaUartMcuxpresso
example:
1 constexpr uint32_t kFlexcomm = 0;
2 const auto kUartBase = USART0;
3 constexpr uint32_t kBaudRate = 115200;
4 constexpr uint32_t kUartInstance = 5;
5 std::array<std::byte, 65536> ring_buffer = {};
6 constexpr uint32_t kUartRxDmaCh = 0;
7 constexpr uint32_t kUartTxDmaCh = 1;
8
9 uint32_t flexcomm_clock_freq = CLOCK_GetFlexcommClkFreq(kUartInstance);
10
11 const pw::uart::DmaUartMcuxpresso::Config kConfig = {
12 .usart_base = kUartBase,
13 .baud_rate = kBaudRate,
14 .parity = kUSART_ParityDisabled,
15 .stop_bits = kUSART_OneStopBit,
16 .dma_base = DMA0,
17 .rx_dma_ch = kUartRxDmaCh,
18 .tx_dma_ch = kUartTxDmaCh,
19 .rx_input_mux_dmac_ch_request_en =
20 kINPUTMUX_Flexcomm0RxToDmac0Ch0RequestEna,
21 .tx_input_mux_dmac_ch_request_en =
22 kINPUTMUX_Flexcomm0TxToDmac0Ch1RequestEna,
23 .buffer = pw::ByteSpan(ring_buffer),
24 .srcclk = flexcomm_clock_freq,
25 };
26
27 auto uart = pw::uart::DmaUartMcuxpresso{kConfig};
28
29 PW_TRY(uart.Enable());