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:

  1. Use pw_build_mcuxpresso to create a pw_source_set for an MCUXpresso SDK.

  2. Include the debug console component in this SDK definition.

  3. Specify the pw_third_party_mcuxpresso_SDK GN global variable to specify the name of this source set.

  4. Use a target that calls pw_sys_io_mcuxpresso_Init in pw_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  const auto kUartBase = USART0;
 2  constexpr uint32_t kBaudRate = 115200;
 3  constexpr bool kFlowControl = true;
 4  std::array<std::byte, 65536> ring_buffer = {};
 5  constexpr uint32_t kUartRxDmaCh = 0;
 6  constexpr uint32_t kUartTxDmaCh = 1;
 7  static pw::dma::McuxpressoDmaController dma(DMA0_BASE);
 8  static pw::dma::McuxpressoDmaChannel rx_dma_ch = dma.GetChannel(kUartRxDmaCh);
 9  static pw::dma::McuxpressoDmaChannel tx_dma_ch = dma.GetChannel(kUartTxDmaCh);
10
11  const pw::uart::DmaUartMcuxpresso::Config kConfig = {
12      .usart_base = kUartBase,
13      .baud_rate = kBaudRate,
14      .flow_control = kFlowControl,
15      .parity = kUSART_ParityDisabled,
16      .stop_bits = kUSART_OneStopBit,
17      .rx_dma_ch = rx_dma_ch,
18      .tx_dma_ch = tx_dma_ch,
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  };
25
26  auto uart = pw::uart::DmaUartMcuxpresso{kConfig};
27
28  PW_TRY(uart.Enable());