1 // Copyright 2024 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14
15 #include "pw_status/try.h"
16 #include "pw_stream_uart_mcuxpresso/dma_stream.h"
17 #include "pw_unit_test/framework.h"
18
19 namespace examples {
20
UartDmaStreamExample()21 pw::Status UartDmaStreamExample() {
22 // DOCSTAG: [pw_stream_uart_mcuxpresso-UartDmaStreamExample]
23 constexpr uint32_t kFlexcomm = 0;
24 const auto kUartBase = USART0;
25 constexpr uint32_t kBaudRate = 115200;
26 std::array<std::byte, 65536> ring_buffer = {};
27 constexpr uint32_t kUartRxDmaCh = 0;
28 constexpr uint32_t kUartTxDmaCh = 1;
29
30 const pw::stream::UartDmaStreamMcuxpresso::Config kConfig = {
31 .usart_base = kUartBase,
32 .baud_rate = kBaudRate,
33 .parity = kUSART_ParityDisabled,
34 .stop_bits = kUSART_OneStopBit,
35 .dma_base = DMA0,
36 .rx_dma_ch = kUartRxDmaCh,
37 .tx_dma_ch = kUartTxDmaCh,
38 .rx_input_mux_dmac_ch_request_en =
39 kINPUTMUX_Flexcomm0RxToDmac0Ch0RequestEna,
40 .tx_input_mux_dmac_ch_request_en =
41 kINPUTMUX_Flexcomm0TxToDmac0Ch1RequestEna,
42 .buffer = pw::ByteSpan(ring_buffer)};
43
44 auto stream = pw::stream::UartDmaStreamMcuxpresso{kConfig};
45
46 PW_TRY(stream.Init(CLOCK_GetFlexcommClkFreq(kFlexcomm)));
47
48 // DOCSTAG: [pw_stream_uart_mcuxpresso-UartDmaStreamExample]
49
50 // Do something else
51
52 return pw::OkStatus();
53 }
54
TEST(DmaStream,Example)55 TEST(DmaStream, Example) {
56 pw::Status status = UartDmaStreamExample();
57 EXPECT_EQ(status.code(), PW_STATUS_OK);
58 }
59 } // namespace examples
60