diff --git a/examples/black_pill_f401/uart_freertos/main.cpp b/examples/black_pill_f401/uart_freertos/main.cpp new file mode 100644 index 0000000000..8be0e2047c --- /dev/null +++ b/examples/black_pill_f401/uart_freertos/main.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2016, Sascha Schade + * Copyright (c) 2017, Niklas Hauser + * Copyright (c) 2019, Raphael Lehmann + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +// ---------------------------------------------------------------------------- + +#include +#include +#include + +/* + * A single FreeRTOS task which reads symbols from Usart1 + * and sends them back, toggling the LED for every symbol + */ + +using namespace Board; +using namespace modm::platform; + +using Uart = BufferedUart>; +using FreeRtosUart = BufferedUart, UartTxBufferFreeRtos<4>>; + +void +taskMain(void *) +{ + // Let's test the old driver first: + Uart::connect(); + Uart::initialize(); + Uart::writeBlocking( (uint8_t *)"Old UART\r\n", 10 ); + + while( (USART1->SR & USART_SR_TC) == 0 ); // Making sure the transmission has finished. + // Maybe this should be exposed via UsartHal? + + // The old UART driver and the new one can coexist, and you + // can even switch between them at runtime: + FreeRtosUart::connect(); + FreeRtosUart::initialize(); + Led::set(); + + FreeRtosUart::writeBlocking( (uint8_t *)"FreeRTOS UART\r\n", 15 ); + + uint8_t chr; + while (true) + { + FreeRtosUart::read( chr ); + FreeRtosUart::write( chr ); + Led::toggle(); + } +} + +constexpr int stack_size = 200; +StackType_t stack[stack_size]; +StaticTask_t taskBuffer; + +int +main() +{ + Board::initialize(); + + TaskHandle_t h_mainTask = xTaskCreateStatic(taskMain, "Main", stack_size, NULL, 2, stack, &taskBuffer); + configASSERT( h_mainTask != NULL ); + vTaskStartScheduler(); + return 0; +} diff --git a/examples/black_pill_f401/uart_freertos/project.xml b/examples/black_pill_f401/uart_freertos/project.xml new file mode 100644 index 0000000000..e25bf91dbe --- /dev/null +++ b/examples/black_pill_f401/uart_freertos/project.xml @@ -0,0 +1,12 @@ + + modm:black-pill-f401 + + + + + modm:build:make + modm:build:scons + modm:platform:uart:1 + modm:freertos + + diff --git a/examples/blue_pill_f103/adns_9800/main.cpp b/examples/blue_pill_f103/adns_9800/main.cpp index 91a7ef4530..4ba52d34fe 100644 --- a/examples/blue_pill_f103/adns_9800/main.cpp +++ b/examples/blue_pill_f103/adns_9800/main.cpp @@ -26,6 +26,7 @@ #undef MODM_LOG_LEVEL #define MODM_LOG_LEVEL modm::log::DEBUG +using Usart2 = BufferedUart>; // Create an IODeviceWrapper around the Uart Peripheral we want to use modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; diff --git a/examples/blue_pill_f103/can/main.cpp b/examples/blue_pill_f103/can/main.cpp index 5475b2d3c7..969f46bc89 100644 --- a/examples/blue_pill_f103/can/main.cpp +++ b/examples/blue_pill_f103/can/main.cpp @@ -12,6 +12,8 @@ #include #include + +using Usart2 = BufferedUart>; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; modm::log::Logger modm::log::info(loggerDevice); diff --git a/examples/blue_pill_f103/encoder_input/main.cpp b/examples/blue_pill_f103/encoder_input/main.cpp index 51a1f7cc1c..e7c6b73b88 100644 --- a/examples/blue_pill_f103/encoder_input/main.cpp +++ b/examples/blue_pill_f103/encoder_input/main.cpp @@ -20,6 +20,7 @@ #define MODM_LOG_LEVEL modm::log::INFO // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart2 = BufferedUart>; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/blue_pill_f103/encoder_input_bitbang/main.cpp b/examples/blue_pill_f103/encoder_input_bitbang/main.cpp index 0b34722213..d72f800039 100644 --- a/examples/blue_pill_f103/encoder_input_bitbang/main.cpp +++ b/examples/blue_pill_f103/encoder_input_bitbang/main.cpp @@ -20,6 +20,7 @@ #define MODM_LOG_LEVEL modm::log::INFO // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart2 = BufferedUart>; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/blue_pill_f103/environment/main.cpp b/examples/blue_pill_f103/environment/main.cpp index fb445c4745..8050ba91e0 100644 --- a/examples/blue_pill_f103/environment/main.cpp +++ b/examples/blue_pill_f103/environment/main.cpp @@ -31,6 +31,7 @@ Bme280Thread bme280Thread; #define MODM_LOG_LEVEL modm::log::DEBUG // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart2 = BufferedUart>; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; modm::IOStream stream(loggerDevice); diff --git a/examples/blue_pill_f103/flash/main.cpp b/examples/blue_pill_f103/flash/main.cpp index 27a4ebac51..0349fc8f77 100644 --- a/examples/blue_pill_f103/flash/main.cpp +++ b/examples/blue_pill_f103/flash/main.cpp @@ -14,6 +14,7 @@ using namespace std::chrono_literals; +using Usart2 = BufferedUart>; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; modm::log::Logger modm::log::info(loggerDevice); diff --git a/examples/blue_pill_f103/logger/main.cpp b/examples/blue_pill_f103/logger/main.cpp index ab1492b79f..6fd55305b8 100644 --- a/examples/blue_pill_f103/logger/main.cpp +++ b/examples/blue_pill_f103/logger/main.cpp @@ -23,6 +23,7 @@ #define MODM_LOG_LEVEL modm::log::INFO // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart2 = BufferedUart>; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/blue_pill_f103/weight_scale_hx711/main.cpp b/examples/blue_pill_f103/weight_scale_hx711/main.cpp index afb225dcb0..51edafd9db 100644 --- a/examples/blue_pill_f103/weight_scale_hx711/main.cpp +++ b/examples/blue_pill_f103/weight_scale_hx711/main.cpp @@ -23,6 +23,7 @@ using namespace Board; #define MODM_LOG_LEVEL modm::log::DEBUG // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart1 = BufferedUart>; modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/generic/i2c_multiplex/main.cpp b/examples/generic/i2c_multiplex/main.cpp index 742007da9c..af93619dc3 100644 --- a/examples/generic/i2c_multiplex/main.cpp +++ b/examples/generic/i2c_multiplex/main.cpp @@ -22,6 +22,7 @@ using I2cMultiplexer = modm::I2cMultiplexer; #ifndef MODM_BOARD_HAS_LOGGER #include // Add logger manually +using Usart2 = BufferedUart, UartRxBuffer<2048>>; using LoggerUsart = Usart2; using LoggerUsartTx = modm::platform::GpioA2; using LoggerUsartRx = modm::platform::GpioA3; diff --git a/examples/generic/i2c_multiplex/project.xml b/examples/generic/i2c_multiplex/project.xml index 0c60153f4b..46757ef9db 100644 --- a/examples/generic/i2c_multiplex/project.xml +++ b/examples/generic/i2c_multiplex/project.xml @@ -4,8 +4,6 @@ - - diff --git a/examples/generic/ros/can_bridge/main.cpp b/examples/generic/ros/can_bridge/main.cpp index 419f2aaad3..c1e5c97f10 100644 --- a/examples/generic/ros/can_bridge/main.cpp +++ b/examples/generic/ros/can_bridge/main.cpp @@ -48,7 +48,7 @@ messageModmToRos(const modm::can::Message& source, can_msgs::Frame& destination) #undef MODM_LOG_LEVEL #define MODM_LOG_LEVEL modm::log::DISABLED -using RosSerialUart = Usart2; +using RosSerialUart = BufferedUart, UartRxBuffer<512>>; namespace ros { diff --git a/examples/generic/ros/can_bridge/project.xml b/examples/generic/ros/can_bridge/project.xml index 336bed37db..e464f15e35 100644 --- a/examples/generic/ros/can_bridge/project.xml +++ b/examples/generic/ros/can_bridge/project.xml @@ -3,8 +3,6 @@ - - modm:build:scons diff --git a/examples/generic/ros/environment/main.cpp b/examples/generic/ros/environment/main.cpp index 401bc83945..e27aea7187 100644 --- a/examples/generic/ros/environment/main.cpp +++ b/examples/generic/ros/environment/main.cpp @@ -36,7 +36,7 @@ // Define which UART is used for communication to and from ROS serial // When using the STlink Uart on Nucleo boards logging must be disabled. -using RosSerialUart = Board::stlink::Uart; +using RosSerialUart = BufferedUart, UartRxBuffer<512>>; namespace ros { diff --git a/examples/generic/ros/environment/project.xml b/examples/generic/ros/environment/project.xml index 67bb72a1d0..db5f8c94a8 100644 --- a/examples/generic/ros/environment/project.xml +++ b/examples/generic/ros/environment/project.xml @@ -2,8 +2,6 @@ modm:nucleo-l476rg - - modm:driver:bme280 diff --git a/examples/generic/ros/sub_pub/main.cpp b/examples/generic/ros/sub_pub/main.cpp index 6ef848a145..ba1a6f0766 100644 --- a/examples/generic/ros/sub_pub/main.cpp +++ b/examples/generic/ros/sub_pub/main.cpp @@ -29,7 +29,7 @@ // Define which UART is used for communication to and from ROS serial // When using the STlink Uart on Nucleo boards logging must be disabled. -using RosSerialUart = Board::stlink::Uart; +using RosSerialUart = BufferedUart, UartRxBuffer<512>>; namespace ampel { diff --git a/examples/generic/ros/sub_pub/project.xml b/examples/generic/ros/sub_pub/project.xml index b988021959..7df33568e9 100644 --- a/examples/generic/ros/sub_pub/project.xml +++ b/examples/generic/ros/sub_pub/project.xml @@ -2,8 +2,6 @@ modm:nucleo-l476rg - - modm:communication:ros diff --git a/examples/nucleo_g071rb/amnb/main.cpp b/examples/nucleo_g071rb/amnb/main.cpp index 347d9fabd5..4eab5b35a8 100644 --- a/examples/nucleo_g071rb/amnb/main.cpp +++ b/examples/nucleo_g071rb/amnb/main.cpp @@ -15,6 +15,9 @@ using namespace Board; using namespace std::chrono_literals; using namespace modm::amnb; +using Usart1 = BufferedUart>; +using Usart3 = BufferedUart>; +using Usart4 = BufferedUart; // ---------------------------------------------------------------------------- Listener listeners[] = diff --git a/examples/nucleo_g071rb/amnb/project.xml b/examples/nucleo_g071rb/amnb/project.xml index 3ac67b913d..158808e8a1 100644 --- a/examples/nucleo_g071rb/amnb/project.xml +++ b/examples/nucleo_g071rb/amnb/project.xml @@ -2,9 +2,6 @@ modm:nucleo-g071rb - - - diff --git a/examples/stm32f072_discovery/can/main.cpp b/examples/stm32f072_discovery/can/main.cpp index 37fd285010..b717aa0725 100644 --- a/examples/stm32f072_discovery/can/main.cpp +++ b/examples/stm32f072_discovery/can/main.cpp @@ -23,6 +23,7 @@ */ // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart1 = BufferedUart; modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/stm32f072_discovery/hard_fault/main.cpp b/examples/stm32f072_discovery/hard_fault/main.cpp index 40916af434..1fa153dd49 100644 --- a/examples/stm32f072_discovery/hard_fault/main.cpp +++ b/examples/stm32f072_discovery/hard_fault/main.cpp @@ -18,6 +18,7 @@ #define MODM_LOG_LEVEL modm::log::INFO // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart1 = BufferedUart; modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/stm32f072_discovery/stusb4500/main.cpp b/examples/stm32f072_discovery/stusb4500/main.cpp index 86bdd3d699..13732ff389 100644 --- a/examples/stm32f072_discovery/stusb4500/main.cpp +++ b/examples/stm32f072_discovery/stusb4500/main.cpp @@ -13,6 +13,7 @@ #include #include +using Usart1 = BufferedUart; modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice; #undef MODM_LOG_LEVEL #define MODM_LOG_LEVEL modm::log::INFO diff --git a/examples/stm32f072_discovery/tmp102/main.cpp b/examples/stm32f072_discovery/tmp102/main.cpp index 35dbbcc4be..8007858c66 100644 --- a/examples/stm32f072_discovery/tmp102/main.cpp +++ b/examples/stm32f072_discovery/tmp102/main.cpp @@ -18,6 +18,7 @@ #include +using Usart1 = BufferedUart; modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > device; modm::IOStream stream(device); diff --git a/examples/stm32f072_discovery/uart/main.cpp b/examples/stm32f072_discovery/uart/main.cpp index 4e93cbac14..2d6897f074 100644 --- a/examples/stm32f072_discovery/uart/main.cpp +++ b/examples/stm32f072_discovery/uart/main.cpp @@ -29,6 +29,7 @@ main() Board::LedUp::set(); // Enable USART 1 + using Usart1 = BufferedUart; Usart1::connect(); Usart1::initialize(); diff --git a/examples/stm32f0_discovery/logger/main.cpp b/examples/stm32f0_discovery/logger/main.cpp index 6129c8a62f..3c535992c4 100644 --- a/examples/stm32f0_discovery/logger/main.cpp +++ b/examples/stm32f0_discovery/logger/main.cpp @@ -18,6 +18,7 @@ #define MODM_LOG_LEVEL modm::log::INFO // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart1 = BufferedUart>; modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/stm32f0_discovery/logger/project.xml b/examples/stm32f0_discovery/logger/project.xml index 0ae889a3ca..e7d965d5c0 100644 --- a/examples/stm32f0_discovery/logger/project.xml +++ b/examples/stm32f0_discovery/logger/project.xml @@ -2,7 +2,6 @@ modm:disco-f051r8 - modm:debug diff --git a/examples/stm32f1_discovery/logger/main.cpp b/examples/stm32f1_discovery/logger/main.cpp index 4363c77c62..a330ff88ab 100644 --- a/examples/stm32f1_discovery/logger/main.cpp +++ b/examples/stm32f1_discovery/logger/main.cpp @@ -22,6 +22,7 @@ #define MODM_LOG_LEVEL modm::log::INFO // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/stm32f3_discovery/adc/continous/main.cpp b/examples/stm32f3_discovery/adc/continous/main.cpp index 5cbd5d2726..8fb0a8674f 100644 --- a/examples/stm32f3_discovery/adc/continous/main.cpp +++ b/examples/stm32f3_discovery/adc/continous/main.cpp @@ -24,6 +24,7 @@ typedef GpioInputC2 Adc2In; typedef GpioInputB13 Adc3In; typedef GpioInputB12 Adc4In; +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; modm::log::Logger modm::log::info(loggerDevice); diff --git a/examples/stm32f3_discovery/adc/interrupt/main.cpp b/examples/stm32f3_discovery/adc/interrupt/main.cpp index ecb66d0a33..a9b68d0618 100644 --- a/examples/stm32f3_discovery/adc/interrupt/main.cpp +++ b/examples/stm32f3_discovery/adc/interrupt/main.cpp @@ -21,6 +21,7 @@ typedef GpioInputB12 AdcIn0; +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; modm::log::Logger modm::log::info(loggerDevice); diff --git a/examples/stm32f3_discovery/adc/simple/main.cpp b/examples/stm32f3_discovery/adc/simple/main.cpp index 333d33494f..b3d2d24071 100644 --- a/examples/stm32f3_discovery/adc/simple/main.cpp +++ b/examples/stm32f3_discovery/adc/simple/main.cpp @@ -21,6 +21,7 @@ typedef GpioInputB12 AdcIn0; +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; modm::log::Logger modm::log::info(loggerDevice); diff --git a/examples/stm32f3_discovery/can/main.cpp b/examples/stm32f3_discovery/can/main.cpp index 7aefc7c952..2bdb8f59c7 100644 --- a/examples/stm32f3_discovery/can/main.cpp +++ b/examples/stm32f3_discovery/can/main.cpp @@ -24,6 +24,7 @@ */ // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/stm32f3_discovery/comp/main.cpp b/examples/stm32f3_discovery/comp/main.cpp index 5695c45d91..d981ca4cac 100644 --- a/examples/stm32f3_discovery/comp/main.cpp +++ b/examples/stm32f3_discovery/comp/main.cpp @@ -19,6 +19,7 @@ #define MODM_LOG_LEVEL modm::log::INFO // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/stm32f3_discovery/uart/logger/main.cpp b/examples/stm32f3_discovery/uart/logger/main.cpp index fbe9ae767c..54fa1bfc79 100644 --- a/examples/stm32f3_discovery/uart/logger/main.cpp +++ b/examples/stm32f3_discovery/uart/logger/main.cpp @@ -21,6 +21,7 @@ #define MODM_LOG_LEVEL modm::log::INFO // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/stm32f401_discovery/uart/main.cpp b/examples/stm32f401_discovery/uart/main.cpp index 02594edcb7..55aa78053b 100644 --- a/examples/stm32f401_discovery/uart/main.cpp +++ b/examples/stm32f401_discovery/uart/main.cpp @@ -30,6 +30,7 @@ main() Board::LedRed::set(); // Enable USART 2 + using Usart2 = BufferedUart; Usart2::connect(); Usart2::initialize(); diff --git a/examples/stm32f407vet6_devebox/flash/main.cpp b/examples/stm32f407vet6_devebox/flash/main.cpp index 1678ba31f2..2ea3a1aeb2 100644 --- a/examples/stm32f407vet6_devebox/flash/main.cpp +++ b/examples/stm32f407vet6_devebox/flash/main.cpp @@ -17,6 +17,7 @@ using namespace Board; +using Usart1 = BufferedUart; modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/stm32f407vet6_devebox/logger/main.cpp b/examples/stm32f407vet6_devebox/logger/main.cpp index 9ebbad99ff..38d00de64a 100644 --- a/examples/stm32f407vet6_devebox/logger/main.cpp +++ b/examples/stm32f407vet6_devebox/logger/main.cpp @@ -14,6 +14,7 @@ using namespace Board; +using Usart1 = BufferedUart; modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/stm32f469_discovery/can/project.xml b/examples/stm32f469_discovery/can/project.xml index 4612114e79..0dd1392d32 100644 --- a/examples/stm32f469_discovery/can/project.xml +++ b/examples/stm32f469_discovery/can/project.xml @@ -8,7 +8,6 @@ modm:platform:can:1 modm:platform:can:2 modm:platform:gpio - modm:platform:uart:3 modm:processing:timer modm:build:scons diff --git a/examples/stm32f4_discovery/adc/interrupt/main.cpp b/examples/stm32f4_discovery/adc/interrupt/main.cpp index b63d72db7c..4773cb518d 100644 --- a/examples/stm32f4_discovery/adc/interrupt/main.cpp +++ b/examples/stm32f4_discovery/adc/interrupt/main.cpp @@ -21,6 +21,7 @@ typedef GpioInputA7 AdcIn; +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; modm::log::Logger modm::log::info(loggerDevice); diff --git a/examples/stm32f4_discovery/adc/oversample/main.cpp b/examples/stm32f4_discovery/adc/oversample/main.cpp index 8692ad5d76..a5b4ca028f 100644 --- a/examples/stm32f4_discovery/adc/oversample/main.cpp +++ b/examples/stm32f4_discovery/adc/oversample/main.cpp @@ -23,6 +23,7 @@ typedef GpioInputA7 AdcIn0; typedef GpioInputA4 AdcIn1; typedef GpioInputA2 AdcIn2; +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; modm::log::Logger modm::log::info(loggerDevice); diff --git a/examples/stm32f4_discovery/adc/simple/main.cpp b/examples/stm32f4_discovery/adc/simple/main.cpp index 42c7d92c0a..24cdec9690 100644 --- a/examples/stm32f4_discovery/adc/simple/main.cpp +++ b/examples/stm32f4_discovery/adc/simple/main.cpp @@ -21,6 +21,7 @@ typedef GpioInputA7 AdcIn; +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; modm::log::Logger modm::log::info(loggerDevice); diff --git a/examples/stm32f4_discovery/app_uart_sniffer/main.cpp b/examples/stm32f4_discovery/app_uart_sniffer/main.cpp index 3befe5ca98..540bf5094d 100644 --- a/examples/stm32f4_discovery/app_uart_sniffer/main.cpp +++ b/examples/stm32f4_discovery/app_uart_sniffer/main.cpp @@ -16,6 +16,9 @@ #include #include +using Usart1 = BufferedUart; +using Usart2 = BufferedUart; +using Usart3 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/stm32f4_discovery/barometer_bmp085_bmp180/main.cpp b/examples/stm32f4_discovery/barometer_bmp085_bmp180/main.cpp index 36e23072db..3243925b3d 100644 --- a/examples/stm32f4_discovery/barometer_bmp085_bmp180/main.cpp +++ b/examples/stm32f4_discovery/barometer_bmp085_bmp180/main.cpp @@ -17,6 +17,7 @@ #include #include +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > device; modm::IOStream stream(device); diff --git a/examples/stm32f4_discovery/can/main.cpp b/examples/stm32f4_discovery/can/main.cpp index 97b109b457..4927954357 100644 --- a/examples/stm32f4_discovery/can/main.cpp +++ b/examples/stm32f4_discovery/can/main.cpp @@ -15,6 +15,7 @@ #include #include +using Usart2 = BufferedUart>; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; modm::log::Logger modm::log::info(loggerDevice); diff --git a/examples/stm32f4_discovery/can/project.xml b/examples/stm32f4_discovery/can/project.xml index d8d565b7ed..acbae34cae 100644 --- a/examples/stm32f4_discovery/can/project.xml +++ b/examples/stm32f4_discovery/can/project.xml @@ -2,7 +2,6 @@ modm:disco-f407vg - modm:debug diff --git a/examples/stm32f4_discovery/can2/main.cpp b/examples/stm32f4_discovery/can2/main.cpp index 1edd388372..8eda656bf1 100644 --- a/examples/stm32f4_discovery/can2/main.cpp +++ b/examples/stm32f4_discovery/can2/main.cpp @@ -25,6 +25,7 @@ */ // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart2 = BufferedUart>; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/stm32f4_discovery/can2/project.xml b/examples/stm32f4_discovery/can2/project.xml index 1b2a1fce1a..9abdb3be4d 100644 --- a/examples/stm32f4_discovery/can2/project.xml +++ b/examples/stm32f4_discovery/can2/project.xml @@ -2,7 +2,6 @@ modm:disco-f407vg - modm:debug diff --git a/examples/stm32f4_discovery/colour_tcs3414/main.cpp b/examples/stm32f4_discovery/colour_tcs3414/main.cpp index c8cc5a5e65..00c804a98c 100644 --- a/examples/stm32f4_discovery/colour_tcs3414/main.cpp +++ b/examples/stm32f4_discovery/colour_tcs3414/main.cpp @@ -19,6 +19,7 @@ #include +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > device; modm::IOStream stream(device); diff --git a/examples/stm32f4_discovery/display/hd44780/main.cpp b/examples/stm32f4_discovery/display/hd44780/main.cpp index 7bd7194fa0..332ba2a369 100644 --- a/examples/stm32f4_discovery/display/hd44780/main.cpp +++ b/examples/stm32f4_discovery/display/hd44780/main.cpp @@ -31,6 +31,7 @@ #include +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > device; modm::IOStream stream(device); diff --git a/examples/stm32f4_discovery/display/nokia_5110/main.cpp b/examples/stm32f4_discovery/display/nokia_5110/main.cpp index bc1df959b2..3024268520 100644 --- a/examples/stm32f4_discovery/display/nokia_5110/main.cpp +++ b/examples/stm32f4_discovery/display/nokia_5110/main.cpp @@ -26,6 +26,7 @@ #include +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > device; modm::IOStream stream(device); diff --git a/examples/stm32f4_discovery/distance_vl6180/main.cpp b/examples/stm32f4_discovery/distance_vl6180/main.cpp index ba1c5851cc..c525add543 100644 --- a/examples/stm32f4_discovery/distance_vl6180/main.cpp +++ b/examples/stm32f4_discovery/distance_vl6180/main.cpp @@ -17,6 +17,7 @@ #include #include +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > device; // Set all four logger streams to use the UART diff --git a/examples/stm32f4_discovery/open407v-d/gui/main.cpp b/examples/stm32f4_discovery/open407v-d/gui/main.cpp index 994beaf434..d980f18b93 100644 --- a/examples/stm32f4_discovery/open407v-d/gui/main.cpp +++ b/examples/stm32f4_discovery/open407v-d/gui/main.cpp @@ -41,6 +41,7 @@ using namespace modm::color::html; #define MODM_LOG_LEVEL modm::log::DEBUG // Create an IODeviceWrapper around the Uart Peripheral we want to use +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; // Set all four logger streams to use the UART diff --git a/examples/stm32f4_discovery/pressure_ams5915/main.cpp b/examples/stm32f4_discovery/pressure_ams5915/main.cpp index 047d9ef2e0..f341ba5e6b 100644 --- a/examples/stm32f4_discovery/pressure_ams5915/main.cpp +++ b/examples/stm32f4_discovery/pressure_ams5915/main.cpp @@ -17,6 +17,7 @@ #include #include +using Usart2 = BufferedUart>; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > device; // Set all four logger streams to use the UART diff --git a/examples/stm32f4_discovery/pressure_ams5915/project.xml b/examples/stm32f4_discovery/pressure_ams5915/project.xml index 29b45d6653..4d8bee99e9 100644 --- a/examples/stm32f4_discovery/pressure_ams5915/project.xml +++ b/examples/stm32f4_discovery/pressure_ams5915/project.xml @@ -2,7 +2,6 @@ modm:disco-f407vg - modm:driver:ams5915 diff --git a/examples/stm32f4_discovery/protothreads/main.cpp b/examples/stm32f4_discovery/protothreads/main.cpp index 7e6be3c182..876c1362ae 100644 --- a/examples/stm32f4_discovery/protothreads/main.cpp +++ b/examples/stm32f4_discovery/protothreads/main.cpp @@ -18,6 +18,7 @@ #include +using Usart2 = BufferedUart; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > device; modm::IOStream stream(device); diff --git a/examples/stm32f4_discovery/sab2/main.cpp b/examples/stm32f4_discovery/sab2/main.cpp index e20da6e3a1..8ad582ed5d 100644 --- a/examples/stm32f4_discovery/sab2/main.cpp +++ b/examples/stm32f4_discovery/sab2/main.cpp @@ -18,6 +18,8 @@ // NOTE: This example requires a connection between PB6 and PC11. // +using Usart1 = BufferedUart; +using Uart4 = BufferedUart; modm::sab2::Interface sabA; modm::sab2::Interface sabB; diff --git a/examples/stm32f4_discovery/temperature_ltc2984/main.cpp b/examples/stm32f4_discovery/temperature_ltc2984/main.cpp index 9581abfb69..25579682fb 100644 --- a/examples/stm32f4_discovery/temperature_ltc2984/main.cpp +++ b/examples/stm32f4_discovery/temperature_ltc2984/main.cpp @@ -17,6 +17,7 @@ #include #include +using Usart2 = BufferedUart>; modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > device; modm::IOStream logger(device); diff --git a/examples/stm32f4_discovery/temperature_ltc2984/project.xml b/examples/stm32f4_discovery/temperature_ltc2984/project.xml index 470c4a5ad8..ac02eb6171 100644 --- a/examples/stm32f4_discovery/temperature_ltc2984/project.xml +++ b/examples/stm32f4_discovery/temperature_ltc2984/project.xml @@ -2,7 +2,6 @@ modm:disco-f407vg - modm:driver:ltc2984 diff --git a/examples/stm32f4_discovery/uart/main.cpp b/examples/stm32f4_discovery/uart/main.cpp index 8a980bcfad..565c3d0bf6 100644 --- a/examples/stm32f4_discovery/uart/main.cpp +++ b/examples/stm32f4_discovery/uart/main.cpp @@ -29,6 +29,7 @@ main() Board::LedRed::set(); // Enable USART 2 + using Usart2 = BufferedUart; Usart2::connect(); Usart2::initialize(); diff --git a/ext/aws/uart_buffer_freertos.hpp b/ext/aws/uart_buffer_freertos.hpp new file mode 100644 index 0000000000..b61ba5076e --- /dev/null +++ b/ext/aws/uart_buffer_freertos.hpp @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2009-2012, Fabian Greif + * Copyright (c) 2010, Martin Rosekeit + * Copyright (c) 2011, Georgi Grinshpun + * Copyright (c) 2011, 2013-2017, Niklas Hauser + * Copyright (c) 2012, Sascha Schade + * Copyright (c) 2013, 2016, Kevin Läufer + * Copyright (c) 2021, Raphael Lehmann + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +// ---------------------------------------------------------------------------- + +#pragma once + +#include +#include +#include +#include "uart_base.hpp" + +namespace modm::platform +{ + +/** + * Universal asynchronous receiver transmitter (implementation based on FreeRTOS queues) + * + * @author Kevin Laeufer + * @author Niklas Hauser + * @author Dima Barsky + * @ingroup modm_platform_uart + * @{ + */ +template +class FreeRtosBuffer +{ + StaticQueue_t queueStructure; + uint8_t storage[SIZE]; +public: + QueueHandle_t queue = xQueueCreateStatic(sizeof(storage), 1, storage, &queueStructure); +}; + +template +class UartRxBufferFreeRtos : public modm::Uart::RxBuffer, public FreeRtosBuffer{}; + +template +class UartTxBufferFreeRtos : public modm::Uart::TxBuffer, public FreeRtosBuffer{}; +/// @} + +/// @cond +template< class Hal, class... Buffers> +class BufferedUart; + +template +class BufferedUart, Buffers...>: public BufferedUart +{ + template< class Hal_, class... Buffers_> friend class BufferedUart; + using Parent = BufferedUart; + static_assert(not Parent::TxBufferSize, "BufferedUart accepts at most one TxBuffer type"); + static inline UartTxBufferFreeRtos txBuffer; + + static bool + InterruptCallback(bool first) + { + BaseType_t xHigherPriorityTaskWoken{false}; + if constexpr (Parent::RxBufferSize) + xHigherPriorityTaskWoken = Parent::InterruptCallback(false); + + if (Hal::isTransmitRegisterEmpty()) + { + if (xQueueIsQueueEmptyFromISR(txBuffer.queue)) + // transmission finished, disable TxEmpty interrupt + Hal::disableInterrupt(Hal::Interrupt::TxEmpty); + else + { + uint8_t data; + xQueueReceiveFromISR(txBuffer.queue, &data, &xHigherPriorityTaskWoken); + Hal::write(data); + } + } + if (first) + { + Hal::acknowledgeInterruptFlags(Hal::InterruptFlag::OverrunError); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } + return xHigherPriorityTaskWoken; + } + +public: + static constexpr size_t TxBufferSize = SIZE; + + template< class SystemClock, baudrate_t baudrate, percent_t tolerance=pct(1) > + static inline void + initialize(Hal::Parity parity=Hal::Parity::Disabled, Hal::WordLength length=Hal::WordLength::Bit8) + { + Parent::template initialize(parity, length); + Hal::InterruptCallback = InterruptCallback; + } + + static bool + write(uint8_t data) + { + if (transmitBufferSize() == 0 and Hal::isTransmitRegisterEmpty()) + Hal::write(data); + else + { + if (not xQueueSend(txBuffer.queue, &data, 0)) return false; + // Disable interrupts while enabling the transmit interrupt + atomic::Lock lock; + // Transmit Data Register Empty Interrupt Enable + Hal::enableInterrupt(Hal::Interrupt::TxEmpty); + } + return true; + } + + static std::size_t + write(const uint8_t *data, std::size_t length) + { + std::size_t count{0}; + for (; count < length; ++count) if (not write(*data++)) break; + return count; + } + + static void + writeBlocking(uint8_t data) + { + if (transmitBufferSize() == 0 and Hal::isTransmitRegisterEmpty()) + Hal::write(data); + else + { + xQueueSend(txBuffer.queue, &data, portMAX_DELAY); + // Disable interrupts while enabling the transmit interrupt + atomic::Lock lock; + // Transmit Data Register Empty Interrupt Enable + Hal::enableInterrupt(Hal::Interrupt::TxEmpty); + } + } + + static void + writeBlocking(const uint8_t *data, std::size_t length) + { + while (length-- != 0) writeBlocking(*data++); + } + + static void + flushWriteBuffer() { while(not isWriteFinished()); } + + bool + isWriteFinished() { return transmitBufferSize() == 0 and Hal::isTransmitRegisterEmpty(); } + + static std::size_t + transmitBufferSize() { return uxQueueMessagesWaiting(txBuffer.queue); } + + std::size_t + discardTransmitBuffer() + { + // disable interrupt since buffer will be cleared + Hal::disableInterrupt(Hal::Interrupt::TxEmpty); + std::size_t count = transmitBufferSize(); + xQueueReset(txBuffer.queue); + return count; + } +}; + +template +class BufferedUart, Buffers...>: public BufferedUart +{ + template< class Hal_, class... Buffers_> friend class BufferedUart; + using Parent = BufferedUart; + static_assert(not Parent::RxBufferSize, "BufferedUart accepts at most one RxBuffer type"); + static inline UartRxBufferFreeRtos rxBuffer; + + static bool + InterruptCallback(bool first) + { + BaseType_t xHigherPriorityTaskWoken{false}; + if constexpr (Parent::TxBufferSize) + xHigherPriorityTaskWoken = Parent::InterruptCallback(false); + + if (Hal::isReceiveRegisterNotEmpty()) + { + uint8_t data; + Hal::read(data); + xQueueSendFromISR(rxBuffer.queue, &data, &xHigherPriorityTaskWoken); + } + if (first) + { + Hal::acknowledgeInterruptFlags(Hal::InterruptFlag::OverrunError); + portYIELD_FROM_ISR (xHigherPriorityTaskWoken); + } + return xHigherPriorityTaskWoken; + } + +public: + static constexpr size_t RxBufferSize = SIZE; + + template< class SystemClock, baudrate_t baudrate, percent_t tolerance=pct(1) > + static inline void + initialize(Hal::Parity parity=Hal::Parity::Disabled, Hal::WordLength length=Hal::WordLength::Bit8) + { + Parent::template initialize(parity, length); + Hal::InterruptCallback = InterruptCallback; + Hal::enableInterrupt(Hal::Interrupt::RxNotEmpty); + } + + static bool + read(uint8_t &data, TickType_t timeout=portMAX_DELAY) + { return bool(xQueueReceive(rxBuffer.queue, &data, timeout)); } + + static std::size_t + read(uint8_t *buffer, std::size_t length, TickType_t timeout=0) + { + std::size_t count{0}; + for (; count < length; ++count) + if (not xQueueReceive(rxBuffer.queue, buffer++, timeout)) + break; + return count; + } + + static std::size_t + receiveBufferSize() { return uxQueueMessagesWaiting(rxBuffer.queue); } + + static std::size_t + discardReceiveBuffer() + { + std::size_t count = 0; + uint8_t data; + while(receiveBufferSize()) + { + ++count; + xQueueReceive(rxBuffer.queue, &data, 0); + } + return count; + } +}; +/// @endcond + +} diff --git a/src/modm/architecture/interface/uart.hpp b/src/modm/architecture/interface/uart.hpp index 7bbd0a9f46..6bd731459f 100644 --- a/src/modm/architecture/interface/uart.hpp +++ b/src/modm/architecture/interface/uart.hpp @@ -30,8 +30,11 @@ namespace modm */ class Uart : public ::modm::PeripheralDriver { -#ifdef __DOXYGEN__ public: + struct RxBuffer { static constexpr bool HasRxBuffer = true; }; + struct TxBuffer { static constexpr bool HasTxBuffer = true; }; + +#ifdef __DOXYGEN__ /// Size of the receive buffer. static constexpr size_t RxBufferSize = 16; diff --git a/src/modm/board/disco_f429zi/board.hpp b/src/modm/board/disco_f429zi/board.hpp index 020b8c3008..0ccd4ecca8 100644 --- a/src/modm/board/disco_f429zi/board.hpp +++ b/src/modm/board/disco_f429zi/board.hpp @@ -242,7 +242,7 @@ namespace stlink /// @{ using Tx = GpioOutputA9; using Rx = GpioInputA10; -using Uart = Usart1; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/disco_f469ni/board.hpp.in b/src/modm/board/disco_f469ni/board.hpp.in index c65d59c136..785008cd49 100644 --- a/src/modm/board/disco_f469ni/board.hpp.in +++ b/src/modm/board/disco_f469ni/board.hpp.in @@ -195,7 +195,7 @@ namespace stlink /// @{ using Tx = GpioOutputB10; // STLK_RX [STLINK V2-1_U2_RX]: USART3_TX using Rx = GpioInputB11; // STLK_TX [STLINK V2-1_U2_TX]: USART3_RX -using Uart = Usart3; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/disco_f469ni/board.xml b/src/modm/board/disco_f469ni/board.xml index 96bb083b86..b6e41eb80d 100644 --- a/src/modm/board/disco_f469ni/board.xml +++ b/src/modm/board/disco_f469ni/board.xml @@ -7,7 +7,6 @@ - diff --git a/src/modm/board/disco_f746ng/board.hpp b/src/modm/board/disco_f746ng/board.hpp index 1556ab94e2..3bbc7c36f0 100644 --- a/src/modm/board/disco_f746ng/board.hpp +++ b/src/modm/board/disco_f746ng/board.hpp @@ -183,7 +183,7 @@ namespace stlink /// @{ using Tx = GpioOutputA9; using Rx = GpioInputB7; -using Uart = Usart1; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/disco_f746ng/board.xml b/src/modm/board/disco_f746ng/board.xml index 23482de56b..76748dc613 100644 --- a/src/modm/board/disco_f746ng/board.xml +++ b/src/modm/board/disco_f746ng/board.xml @@ -7,8 +7,6 @@ - - modm:board:disco-f746ng diff --git a/src/modm/board/disco_f769ni/board.hpp b/src/modm/board/disco_f769ni/board.hpp index 81eb1d2039..6f59252cfe 100644 --- a/src/modm/board/disco_f769ni/board.hpp +++ b/src/modm/board/disco_f769ni/board.hpp @@ -119,7 +119,7 @@ namespace stlink /// @{ using Tx = GpioOutputA9; using Rx = GpioInputA10; -using Uart = Usart1; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/disco_f769ni/board.xml b/src/modm/board/disco_f769ni/board.xml index 060b1d1092..bc0c57a75a 100644 --- a/src/modm/board/disco_f769ni/board.xml +++ b/src/modm/board/disco_f769ni/board.xml @@ -7,8 +7,6 @@ - - modm:board:disco-f769ni diff --git a/src/modm/board/disco_l152rc/board.xml b/src/modm/board/disco_l152rc/board.xml index 6e02b9d481..bb63af0d65 100644 --- a/src/modm/board/disco_l152rc/board.xml +++ b/src/modm/board/disco_l152rc/board.xml @@ -7,8 +7,6 @@ - - modm:board:disco-l152rc diff --git a/src/modm/board/nucleo_f031k6/board.hpp b/src/modm/board/nucleo_f031k6/board.hpp index c2decbfe28..b301f3528b 100644 --- a/src/modm/board/nucleo_f031k6/board.hpp +++ b/src/modm/board/nucleo_f031k6/board.hpp @@ -88,7 +88,7 @@ namespace stlink /// @{ using Rx = GpioInputA15; using Tx = GpioOutputA2; -using Uart = Usart1; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_f031k6/board.xml b/src/modm/board/nucleo_f031k6/board.xml index 7166c79828..8f0eece254 100644 --- a/src/modm/board/nucleo_f031k6/board.xml +++ b/src/modm/board/nucleo_f031k6/board.xml @@ -7,8 +7,6 @@ - - diff --git a/src/modm/board/nucleo_f042k6/board.hpp b/src/modm/board/nucleo_f042k6/board.hpp index 09f8aa93c7..f9ebc59a0b 100644 --- a/src/modm/board/nucleo_f042k6/board.hpp +++ b/src/modm/board/nucleo_f042k6/board.hpp @@ -92,7 +92,7 @@ namespace stlink using Rx = GpioInputA15; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_f042k6/board.xml b/src/modm/board/nucleo_f042k6/board.xml index 1a32157125..153795164e 100644 --- a/src/modm/board/nucleo_f042k6/board.xml +++ b/src/modm/board/nucleo_f042k6/board.xml @@ -7,7 +7,6 @@ - diff --git a/src/modm/board/nucleo_f072rb/board.hpp b/src/modm/board/nucleo_f072rb/board.hpp index 17b9c1d2d5..24e2240e94 100644 --- a/src/modm/board/nucleo_f072rb/board.hpp +++ b/src/modm/board/nucleo_f072rb/board.hpp @@ -92,7 +92,7 @@ namespace stlink /// @{ using Rx = GpioInputA3; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart; /// @} } diff --git a/src/modm/board/nucleo_f091rc/board.hpp b/src/modm/board/nucleo_f091rc/board.hpp index 15a568e159..86efd959b1 100644 --- a/src/modm/board/nucleo_f091rc/board.hpp +++ b/src/modm/board/nucleo_f091rc/board.hpp @@ -91,7 +91,7 @@ namespace stlink /// @{ using Rx = GpioInputA3; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart; /// @} } diff --git a/src/modm/board/nucleo_f103rb/board.hpp b/src/modm/board/nucleo_f103rb/board.hpp index 7ad9c9db30..754e2f9107 100644 --- a/src/modm/board/nucleo_f103rb/board.hpp +++ b/src/modm/board/nucleo_f103rb/board.hpp @@ -103,7 +103,7 @@ namespace stlink /// @{ using Rx = GpioInputA3; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_f103rb/board.xml b/src/modm/board/nucleo_f103rb/board.xml index 3b69f1e091..b82c386c98 100644 --- a/src/modm/board/nucleo_f103rb/board.xml +++ b/src/modm/board/nucleo_f103rb/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-f103rb diff --git a/src/modm/board/nucleo_f303k8/board.hpp b/src/modm/board/nucleo_f303k8/board.hpp index 53c933c586..f4273302b8 100644 --- a/src/modm/board/nucleo_f303k8/board.hpp +++ b/src/modm/board/nucleo_f303k8/board.hpp @@ -99,7 +99,7 @@ namespace stlink { using Rx = GpioInputA15; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; } using LoggerDevice = modm::IODeviceWrapper< stlink::Uart, modm::IOBuffer::BlockIfFull >; diff --git a/src/modm/board/nucleo_f303k8/board.xml b/src/modm/board/nucleo_f303k8/board.xml index ba928eef67..ecbbfa9ce2 100644 --- a/src/modm/board/nucleo_f303k8/board.xml +++ b/src/modm/board/nucleo_f303k8/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-f303k8 diff --git a/src/modm/board/nucleo_f303re/board.hpp b/src/modm/board/nucleo_f303re/board.hpp index 4fd12154b0..a2fedcfc49 100644 --- a/src/modm/board/nucleo_f303re/board.hpp +++ b/src/modm/board/nucleo_f303re/board.hpp @@ -104,7 +104,7 @@ namespace stlink /// @{ using Rx = GpioInputA15; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_f303re/board.xml b/src/modm/board/nucleo_f303re/board.xml index 59a4a23a76..fdb4461663 100644 --- a/src/modm/board/nucleo_f303re/board.xml +++ b/src/modm/board/nucleo_f303re/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-f303re diff --git a/src/modm/board/nucleo_f334r8/board.hpp b/src/modm/board/nucleo_f334r8/board.hpp index 80fde9d9b2..1e6a065da8 100644 --- a/src/modm/board/nucleo_f334r8/board.hpp +++ b/src/modm/board/nucleo_f334r8/board.hpp @@ -101,7 +101,7 @@ namespace stlink /// @{ using Rx = GpioInputA15; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_f334r8/board.xml b/src/modm/board/nucleo_f334r8/board.xml index 53e0c000aa..b787d7b042 100644 --- a/src/modm/board/nucleo_f334r8/board.xml +++ b/src/modm/board/nucleo_f334r8/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-f334r8 diff --git a/src/modm/board/nucleo_f401re/board.hpp b/src/modm/board/nucleo_f401re/board.hpp index e5188b7e64..aa3bf641f6 100644 --- a/src/modm/board/nucleo_f401re/board.hpp +++ b/src/modm/board/nucleo_f401re/board.hpp @@ -101,7 +101,7 @@ namespace stlink /// @{ using Rx = GpioInputA3; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_f401re/board.xml b/src/modm/board/nucleo_f401re/board.xml index 6de8744383..9b51eeff29 100644 --- a/src/modm/board/nucleo_f401re/board.xml +++ b/src/modm/board/nucleo_f401re/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-f401re diff --git a/src/modm/board/nucleo_f411re/board.hpp b/src/modm/board/nucleo_f411re/board.hpp index 5fff5998fb..ae974cf914 100644 --- a/src/modm/board/nucleo_f411re/board.hpp +++ b/src/modm/board/nucleo_f411re/board.hpp @@ -103,7 +103,7 @@ namespace stlink /// @{ using Rx = GpioInputA3; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_f411re/board.xml b/src/modm/board/nucleo_f411re/board.xml index d379ec5ba2..2b437f847e 100644 --- a/src/modm/board/nucleo_f411re/board.xml +++ b/src/modm/board/nucleo_f411re/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-f411re diff --git a/src/modm/board/nucleo_f429zi/board.hpp b/src/modm/board/nucleo_f429zi/board.hpp index 7fbd76ab26..d96cf71469 100644 --- a/src/modm/board/nucleo_f429zi/board.hpp +++ b/src/modm/board/nucleo_f429zi/board.hpp @@ -135,7 +135,7 @@ namespace stlink /// @{ using Tx = GpioOutputD8; using Rx = GpioInputD9; -using Uart = Usart3; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_f429zi/board.xml b/src/modm/board/nucleo_f429zi/board.xml index d5d1e04c99..8c3547b161 100644 --- a/src/modm/board/nucleo_f429zi/board.xml +++ b/src/modm/board/nucleo_f429zi/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-f429zi diff --git a/src/modm/board/nucleo_f439zi/board.xml b/src/modm/board/nucleo_f439zi/board.xml index 0d1bbd37d0..86d58c24a2 100644 --- a/src/modm/board/nucleo_f439zi/board.xml +++ b/src/modm/board/nucleo_f439zi/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-f439zi diff --git a/src/modm/board/nucleo_f446re/board.hpp b/src/modm/board/nucleo_f446re/board.hpp index 783fbb4cb6..9d847edaee 100644 --- a/src/modm/board/nucleo_f446re/board.hpp +++ b/src/modm/board/nucleo_f446re/board.hpp @@ -113,7 +113,7 @@ namespace stlink /// @{ using Rx = GpioInputA3; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_f446re/board.xml b/src/modm/board/nucleo_f446re/board.xml index 452b7ed6e8..b4c1222da4 100644 --- a/src/modm/board/nucleo_f446re/board.xml +++ b/src/modm/board/nucleo_f446re/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-f446re diff --git a/src/modm/board/nucleo_f446ze/board.hpp b/src/modm/board/nucleo_f446ze/board.hpp index ed745af920..ee9f66b7b1 100644 --- a/src/modm/board/nucleo_f446ze/board.hpp +++ b/src/modm/board/nucleo_f446ze/board.hpp @@ -140,7 +140,7 @@ namespace stlink /// @{ using Tx = GpioOutputD8; using Rx = GpioInputD9; -using Uart = Usart3; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_f446ze/board.xml b/src/modm/board/nucleo_f446ze/board.xml index be0aaa195e..2eca5bec7b 100644 --- a/src/modm/board/nucleo_f446ze/board.xml +++ b/src/modm/board/nucleo_f446ze/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-f446ze diff --git a/src/modm/board/nucleo_f746zg/board.hpp b/src/modm/board/nucleo_f746zg/board.hpp index 4d2c366447..c3bd028392 100755 --- a/src/modm/board/nucleo_f746zg/board.hpp +++ b/src/modm/board/nucleo_f746zg/board.hpp @@ -127,7 +127,7 @@ namespace stlink /// @{ using Tx = GpioOutputD8; using Rx = GpioInputD9; -using Uart = Usart3; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_f746zg/board.xml b/src/modm/board/nucleo_f746zg/board.xml index 6ba895d410..b067053e45 100755 --- a/src/modm/board/nucleo_f746zg/board.xml +++ b/src/modm/board/nucleo_f746zg/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-f746zg diff --git a/src/modm/board/nucleo_f767zi/board.hpp b/src/modm/board/nucleo_f767zi/board.hpp index 9f02baa432..72c233639c 100755 --- a/src/modm/board/nucleo_f767zi/board.hpp +++ b/src/modm/board/nucleo_f767zi/board.hpp @@ -126,7 +126,7 @@ namespace stlink /// @{ using Tx = GpioOutputD8; using Rx = GpioInputD9; -using Uart = Usart3; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_f767zi/board.xml b/src/modm/board/nucleo_f767zi/board.xml index 9d1eb6c707..2a3261bb1e 100755 --- a/src/modm/board/nucleo_f767zi/board.xml +++ b/src/modm/board/nucleo_f767zi/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-f767zi diff --git a/src/modm/board/nucleo_g070rb/board.xml b/src/modm/board/nucleo_g070rb/board.xml index 2aa603ab34..d84381c320 100644 --- a/src/modm/board/nucleo_g070rb/board.xml +++ b/src/modm/board/nucleo_g070rb/board.xml @@ -7,7 +7,6 @@ - modm:board:nucleo-g070rb diff --git a/src/modm/board/nucleo_g071rb/board.hpp b/src/modm/board/nucleo_g071rb/board.hpp index 59c91861ca..8fd2ac808e 100644 --- a/src/modm/board/nucleo_g071rb/board.hpp +++ b/src/modm/board/nucleo_g071rb/board.hpp @@ -139,7 +139,7 @@ namespace stlink /// @{ using Rx = GpioInputA3; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_g071rb/board.xml b/src/modm/board/nucleo_g071rb/board.xml index 29b5be9828..06086ed929 100644 --- a/src/modm/board/nucleo_g071rb/board.xml +++ b/src/modm/board/nucleo_g071rb/board.xml @@ -7,7 +7,6 @@ - modm:board:nucleo-g071rb diff --git a/src/modm/board/nucleo_g431kb/board.hpp b/src/modm/board/nucleo_g431kb/board.hpp index 0b6b999c4d..7052b68c0e 100644 --- a/src/modm/board/nucleo_g431kb/board.hpp +++ b/src/modm/board/nucleo_g431kb/board.hpp @@ -147,7 +147,7 @@ namespace stlink /// @{ using Rx = GpioInputA3; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_g431kb/board.xml b/src/modm/board/nucleo_g431kb/board.xml index 1a2b7bad9c..1bcc162637 100644 --- a/src/modm/board/nucleo_g431kb/board.xml +++ b/src/modm/board/nucleo_g431kb/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-g431kb diff --git a/src/modm/board/nucleo_g431rb/board.hpp b/src/modm/board/nucleo_g431rb/board.hpp index de04fe9c12..eef07b41fe 100644 --- a/src/modm/board/nucleo_g431rb/board.hpp +++ b/src/modm/board/nucleo_g431rb/board.hpp @@ -121,7 +121,7 @@ namespace stlink /// @{ using Rx = GpioInputA3; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_g431rb/board.xml b/src/modm/board/nucleo_g431rb/board.xml index 5df9bb5540..4659d67098 100644 --- a/src/modm/board/nucleo_g431rb/board.xml +++ b/src/modm/board/nucleo_g431rb/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-g431rb diff --git a/src/modm/board/nucleo_g474re/board.hpp b/src/modm/board/nucleo_g474re/board.hpp index 29d9ec86a5..31005e0eb4 100644 --- a/src/modm/board/nucleo_g474re/board.hpp +++ b/src/modm/board/nucleo_g474re/board.hpp @@ -135,7 +135,7 @@ namespace stlink /// @{ using Rx = GpioInputA3; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_g474re/board.xml b/src/modm/board/nucleo_g474re/board.xml index a3c207b0ff..cd40e9dedc 100644 --- a/src/modm/board/nucleo_g474re/board.xml +++ b/src/modm/board/nucleo_g474re/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-g474re diff --git a/src/modm/board/nucleo_h723zg/board.hpp b/src/modm/board/nucleo_h723zg/board.hpp index eb974e48cd..878f9bc089 100644 --- a/src/modm/board/nucleo_h723zg/board.hpp +++ b/src/modm/board/nucleo_h723zg/board.hpp @@ -186,7 +186,7 @@ namespace stlink /// @{ using Tx = GpioOutputD8; using Rx = GpioInputD9; -using Uart = Usart3; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_h723zg/board.xml b/src/modm/board/nucleo_h723zg/board.xml index 8f319c77d0..c9a23842c5 100644 --- a/src/modm/board/nucleo_h723zg/board.xml +++ b/src/modm/board/nucleo_h723zg/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-h723zg diff --git a/src/modm/board/nucleo_h743zi/board.hpp b/src/modm/board/nucleo_h743zi/board.hpp index 7847157a3c..b441ec1f68 100644 --- a/src/modm/board/nucleo_h743zi/board.hpp +++ b/src/modm/board/nucleo_h743zi/board.hpp @@ -173,7 +173,7 @@ namespace stlink /// @{ using Tx = GpioOutputD8; using Rx = GpioInputD9; -using Uart = Usart3; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_h743zi/board.xml b/src/modm/board/nucleo_h743zi/board.xml index e2044f6840..d35d4e06dd 100644 --- a/src/modm/board/nucleo_h743zi/board.xml +++ b/src/modm/board/nucleo_h743zi/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-h743zi diff --git a/src/modm/board/nucleo_l031k6/board.hpp b/src/modm/board/nucleo_l031k6/board.hpp index ce88228d8c..643358e917 100644 --- a/src/modm/board/nucleo_l031k6/board.hpp +++ b/src/modm/board/nucleo_l031k6/board.hpp @@ -95,7 +95,7 @@ namespace stlink /// @{ using Rx = GpioInputA15; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_l031k6/board.xml b/src/modm/board/nucleo_l031k6/board.xml index c72abd5225..a67e0ee705 100644 --- a/src/modm/board/nucleo_l031k6/board.xml +++ b/src/modm/board/nucleo_l031k6/board.xml @@ -7,8 +7,6 @@ - - diff --git a/src/modm/board/nucleo_l053r8/board.hpp b/src/modm/board/nucleo_l053r8/board.hpp index ba8ca0d7c3..c90b17bf71 100644 --- a/src/modm/board/nucleo_l053r8/board.hpp +++ b/src/modm/board/nucleo_l053r8/board.hpp @@ -101,7 +101,7 @@ namespace stlink /// @{ using Rx = GpioInputA3; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_l053r8/board.xml b/src/modm/board/nucleo_l053r8/board.xml index 589d058b62..65e8d06394 100644 --- a/src/modm/board/nucleo_l053r8/board.xml +++ b/src/modm/board/nucleo_l053r8/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-l053r8 diff --git a/src/modm/board/nucleo_l152re/board.hpp b/src/modm/board/nucleo_l152re/board.hpp index a33e6079e6..4c67150a60 100644 --- a/src/modm/board/nucleo_l152re/board.hpp +++ b/src/modm/board/nucleo_l152re/board.hpp @@ -126,7 +126,7 @@ namespace stlink /// @{ using Rx = GpioInputA3; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_l152re/board.xml b/src/modm/board/nucleo_l152re/board.xml index 40509a8457..e4837c56c6 100644 --- a/src/modm/board/nucleo_l152re/board.xml +++ b/src/modm/board/nucleo_l152re/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-l152re diff --git a/src/modm/board/nucleo_l432kc/board.hpp b/src/modm/board/nucleo_l432kc/board.hpp index 3627d45d9b..428f5c27a7 100644 --- a/src/modm/board/nucleo_l432kc/board.hpp +++ b/src/modm/board/nucleo_l432kc/board.hpp @@ -107,7 +107,7 @@ namespace stlink /// @{ using Rx = GpioInputA15; using Tx = GpioOutputA2; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_l432kc/board.xml b/src/modm/board/nucleo_l432kc/board.xml index 564be2a940..0733e29df1 100644 --- a/src/modm/board/nucleo_l432kc/board.xml +++ b/src/modm/board/nucleo_l432kc/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-l432kc diff --git a/src/modm/board/nucleo_l452re/board.hpp b/src/modm/board/nucleo_l452re/board.hpp index 5b8d38e020..c36e5251c4 100644 --- a/src/modm/board/nucleo_l452re/board.hpp +++ b/src/modm/board/nucleo_l452re/board.hpp @@ -116,7 +116,7 @@ namespace stlink /// @{ using Tx = GpioOutputA2; using Rx = GpioInputA3; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_l452re/board.xml b/src/modm/board/nucleo_l452re/board.xml index 2c4c58d187..e04b757dfa 100644 --- a/src/modm/board/nucleo_l452re/board.xml +++ b/src/modm/board/nucleo_l452re/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-l452re diff --git a/src/modm/board/nucleo_l476rg/board.hpp b/src/modm/board/nucleo_l476rg/board.hpp index 2d887a5753..e313429440 100644 --- a/src/modm/board/nucleo_l476rg/board.hpp +++ b/src/modm/board/nucleo_l476rg/board.hpp @@ -84,7 +84,7 @@ namespace stlink /// @{ using Tx = GpioOutputA2; using Rx = GpioInputA3; -using Uart = Usart2; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_l476rg/board.xml b/src/modm/board/nucleo_l476rg/board.xml index a61b9266c6..9f8762d2d5 100644 --- a/src/modm/board/nucleo_l476rg/board.xml +++ b/src/modm/board/nucleo_l476rg/board.xml @@ -7,8 +7,6 @@ - - modm:board:nucleo-l476rg diff --git a/src/modm/board/nucleo_l496zg-p/board.hpp b/src/modm/board/nucleo_l496zg-p/board.hpp index c0974a885a..1b2a2a2469 100644 --- a/src/modm/board/nucleo_l496zg-p/board.hpp +++ b/src/modm/board/nucleo_l496zg-p/board.hpp @@ -143,7 +143,7 @@ namespace stlink /// @{ using Rx = GpioOutputG8; using Tx = GpioInputG7; -using Uart = Lpuart1; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_l496zg-p/board.xml b/src/modm/board/nucleo_l496zg-p/board.xml index 99f52cfbe7..d7a4bc360d 100644 --- a/src/modm/board/nucleo_l496zg-p/board.xml +++ b/src/modm/board/nucleo_l496zg-p/board.xml @@ -7,7 +7,6 @@ - diff --git a/src/modm/board/nucleo_l552ze-q/board.hpp b/src/modm/board/nucleo_l552ze-q/board.hpp index 4b391492fa..a99b2d5e39 100644 --- a/src/modm/board/nucleo_l552ze-q/board.hpp +++ b/src/modm/board/nucleo_l552ze-q/board.hpp @@ -145,7 +145,7 @@ namespace stlink /// @{ using Rx = GpioOutputG8; using Tx = GpioInputG7; -using Uart = Lpuart1; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_l552ze-q/board.xml b/src/modm/board/nucleo_l552ze-q/board.xml index 05528bce78..b68cf70fb0 100644 --- a/src/modm/board/nucleo_l552ze-q/board.xml +++ b/src/modm/board/nucleo_l552ze-q/board.xml @@ -7,7 +7,6 @@ - diff --git a/src/modm/board/nucleo_u575zi-q/board.hpp b/src/modm/board/nucleo_u575zi-q/board.hpp index 2b4efeb31d..e5c7f737d5 100644 --- a/src/modm/board/nucleo_u575zi-q/board.hpp +++ b/src/modm/board/nucleo_u575zi-q/board.hpp @@ -153,7 +153,7 @@ namespace stlink /// @{ using Rx = GpioOutputA10; using Tx = GpioInputA9; -using Uart = Usart1; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/nucleo_u575zi-q/board.xml b/src/modm/board/nucleo_u575zi-q/board.xml index bfb4a97c85..fbb6198a10 100644 --- a/src/modm/board/nucleo_u575zi-q/board.xml +++ b/src/modm/board/nucleo_u575zi-q/board.xml @@ -7,7 +7,6 @@ - diff --git a/src/modm/board/olimexino_stm32/board.hpp b/src/modm/board/olimexino_stm32/board.hpp index 94a3d1a47f..b69c910bcc 100644 --- a/src/modm/board/olimexino_stm32/board.hpp +++ b/src/modm/board/olimexino_stm32/board.hpp @@ -130,7 +130,7 @@ namespace uext /// @{ using Rx = GpioInputA10; using Tx = GpioOutputA9; -using Uart = Usart1; +using Uart = BufferedUart>; /// @} } diff --git a/src/modm/board/olimexino_stm32/board.xml b/src/modm/board/olimexino_stm32/board.xml index 05e2a4a30b..a3dbe4eacf 100644 --- a/src/modm/board/olimexino_stm32/board.xml +++ b/src/modm/board/olimexino_stm32/board.xml @@ -7,8 +7,6 @@ - - modm:board:olimexino-stm32 diff --git a/src/modm/board/stm32_f4ve/board.hpp b/src/modm/board/stm32_f4ve/board.hpp index 12d99a479e..495d61d3a8 100644 --- a/src/modm/board/stm32_f4ve/board.hpp +++ b/src/modm/board/stm32_f4ve/board.hpp @@ -107,6 +107,7 @@ struct SystemClock } }; +using Usart1 = BufferedUart; using LoggerDevice = modm::IODeviceWrapper< Usart1 , modm::IOBuffer::BlockIfFull >; using Button = GpioInputA0; diff --git a/src/modm/platform/uart/stm32/module.lb b/src/modm/platform/uart/stm32/module.lb index df28ab74c3..91f40feb52 100644 --- a/src/modm/platform/uart/stm32/module.lb +++ b/src/modm/platform/uart/stm32/module.lb @@ -28,20 +28,6 @@ class Instance(Module): def prepare(self, module, options): module.depends(":platform:uart") - - module.add_option( - NumericOption( - name="buffer.tx", - description="", - minimum=0, maximum="64Ki-2", - default=0)) - module.add_option( - NumericOption( - name="buffer.rx", - description="", - minimum=0, maximum="64Ki-2", - default=0)) - return True def build(self, env): @@ -53,7 +39,6 @@ class Instance(Module): props["uart_type"] = self.driver["name"].capitalize() props["name"] = self.driver["name"].capitalize() + str(self.instance) props["hal"] = self.driver["name"].capitalize() + "Hal" + str(self.instance) - props["buffered"] = env["buffer.tx"] or env["buffer.rx"] env.substitutions = props env.outbasepath = "modm/src/modm/platform/uart" @@ -65,13 +50,8 @@ class Instance(Module): env.template("uart_hal.hpp.in", "{}_hal_{}.hpp".format(uart, self.instance)) env.template("uart_hal_impl.hpp.in", "{}_hal_{}_impl.hpp".format(uart, self.instance)) - env.template("uart.hpp.in", "{}_{}.hpp".format(uart, self.instance)) env.template("uart.cpp.in", "{}_{}.cpp".format(uart, self.instance)) - - #props["instances"].append(props["name"]) - if props["buffered"]: - props["buffered_instances"].append(props["name"]) - + props["instances"].append(props["name"]) def init(module): module.name = ":platform:uart" @@ -92,7 +72,8 @@ def prepare(module, options): ":math:algorithm", ":cmsis:device", ":platform:gpio", - ":platform:rcc") + ":platform:rcc", + ":utils") global props drivers = (device.get_all_drivers("uart") + device.get_all_drivers("usart") + device.get_all_drivers("lpuart")) @@ -100,7 +81,6 @@ def prepare(module, options): props["over8"] = ("feature" in drivers[0]) and ("over8" in drivers[0]["feature"]) props["tcbgt"] = ("feature" in drivers[0]) and ("tcbgt" in drivers[0]["feature"]) props["instances"] = [] - props["buffered_instances"] = [] for driver in drivers: for instance in driver["instance"]: @@ -142,7 +122,7 @@ def build(env): env.template("uart_base.hpp.in") props["uart_shared_irqs_data"] = dict() - for name in props["buffered_instances"]: + for name in props["instances"]: if name in props["shared_irqs"].keys(): irq = props["shared_irqs"][name] if irq not in props["uart_shared_irqs_data"]: @@ -154,3 +134,9 @@ def build(env): }) if len(props["uart_shared_irqs_data"]): env.template("uart_shared.cpp.in") + + env.copy("uart.hpp") + env.copy("uart_buffer.hpp") + if env.has_module(":freertos"): + env.copy(repopath("ext/aws/uart_buffer_freertos.hpp"), "uart_buffer_freertos.hpp") + diff --git a/src/modm/platform/uart/stm32/uart.cpp.in b/src/modm/platform/uart/stm32/uart.cpp.in index b51422421c..f0da3181c4 100644 --- a/src/modm/platform/uart/stm32/uart.cpp.in +++ b/src/modm/platform/uart/stm32/uart.cpp.in @@ -16,254 +16,28 @@ */ // ---------------------------------------------------------------------------- -#include "../device.hpp" %% if "Lpuart" in uart_type -#include "lpuart_{{ id }}.hpp" +#include "lpuart_hal_{{ id }}.hpp" %% else -#include "uart_{{ id }}.hpp" +#include "uart_hal_{{ id }}.hpp" %%endif -%% if buffered -#include -#include - -namespace -{ -%% if options["buffer.rx"] - static modm::atomic::Queue rxBuffer; -%% endif -%% if options["buffer.tx"] - static modm::atomic::Queue txBuffer; -%% endif -} -%% endif - -namespace modm::platform -{ - -void -{{ name }}::writeBlocking(uint8_t data) -{ - while(!{{ hal }}::isTransmitRegisterEmpty()); - {{ hal }}::write(data); -} - -void -{{ name }}::writeBlocking(const uint8_t *data, std::size_t length) +%% if name in shared_irqs.keys() +namespace modm::platform::{{ name }} { - while (length-- != 0) { - writeBlocking(*data++); - } -} - void -{{ name }}::flushWriteBuffer() -{ -%% if options["buffer.tx"] - while(!isWriteFinished()); -%% else - return; -%% endif -} - -bool -{{ name }}::write(uint8_t data) -{ -%% if options["buffer.tx"] - if(txBuffer.isEmpty() && {{ hal }}::isTransmitRegisterEmpty()) { - {{ hal }}::write(data); - } else { - if (!txBuffer.push(data)) - return false; - // Disable interrupts while enabling the transmit interrupt - atomic::Lock lock; - // Transmit Data Register Empty Interrupt Enable - {{ hal }}::enableInterrupt(Interrupt::TxEmpty); - } - return true; -%% else - if({{ hal }}::isTransmitRegisterEmpty()) { - {{ hal }}::write(data); - return true; - } else { - return false; - } -%% endif -} - -std::size_t -{{ name }}::write(const uint8_t *data, std::size_t length) -{ - uint32_t i = 0; - for (; i < length; ++i) - { - if (!write(*data++)) { - return i; - } - } - return i; -} - -bool -{{ name }}::isWriteFinished() -{ -%% if options["buffer.tx"] - return txBuffer.isEmpty() && {{ hal }}::isTransmitRegisterEmpty(); -%% else - return {{ hal }}::isTransmitRegisterEmpty(); -%% endif -} - -std::size_t -{{ name }}::transmitBufferSize() -{ -%% if options["buffer.tx"] - return txBuffer.getSize(); -%% else - return {{ hal }}::isTransmitRegisterEmpty() ? 0 : 1; -%% endif -} - -std::size_t -{{ name }}::discardTransmitBuffer() -{ -%% if options["buffer.tx"] - std::size_t count = 0; - // disable interrupt since buffer will be cleared - {{ hal }}::disableInterrupt({{ hal }}::Interrupt::TxEmpty); - while(!txBuffer.isEmpty()) { - ++count; - txBuffer.pop(); - } - return count; -%% else - return 0; -%% endif -} - -bool -{{ name }}::read(uint8_t &data) -{ -%% if options["buffer.rx"] - if (rxBuffer.isEmpty()) { - return false; - } else { - data = rxBuffer.get(); - rxBuffer.pop(); - return true; - } +irq() %% else - if({{ hal }}::isReceiveRegisterNotEmpty()) { - {{ hal }}::read(data); - return true; - } else { - return false; - } +MODM_ISR({{ name | upper }}) %% endif -} - -std::size_t -{{ name }}::read(uint8_t *data, std::size_t length) { -%% if options["buffer.rx"] - uint32_t i = 0; - for (; i < length; ++i) + using namespace modm::platform; + if ({{ hal }}::InterruptCallback) { - if (rxBuffer.isEmpty()) { - return i; - } else { - *data++ = rxBuffer.get(); - rxBuffer.pop(); - } - } - return i; -%% else - (void)length; // avoid compiler warning - if(read(*data)) { - return 1; - } else { - return 0; + {{ hal }}::InterruptCallback(true); } -%% endif } -std::size_t -{{ name }}::receiveBufferSize() -{ -%% if options["buffer.rx"] - return rxBuffer.getSize(); -%% else - return {{ hal }}::isReceiveRegisterNotEmpty() ? 1 : 0; -%% endif -} - -std::size_t -{{ name }}::discardReceiveBuffer() -{ -%% if options["buffer.rx"] - std::size_t count = 0; - while(!rxBuffer.isEmpty()) { - ++count; - rxBuffer.pop(); - } - return count; -%% else - return 0; -%% endif -} - -bool -{{ name }}::hasError() -{ - return {{ hal }}::getInterruptFlags().any( - {{ hal }}::InterruptFlag::ParityError | -#ifdef USART_ISR_NE - {{ hal }}::InterruptFlag::NoiseError | -#endif - {{ hal }}::InterruptFlag::OverrunError | {{ hal }}::InterruptFlag::FramingError); -} -void -{{ name }}::clearError() -{ - return {{ hal }}::acknowledgeInterruptFlags( - {{ hal }}::InterruptFlag::ParityError | -#ifdef USART_ISR_NE - {{ hal }}::InterruptFlag::NoiseError | -#endif - {{ hal }}::InterruptFlag::OverrunError | {{ hal }}::InterruptFlag::FramingError); -} - -} // namespace modm::platform - -%% if buffered %% if name in shared_irqs.keys() -void -modm::platform::{{ name }}::irq() -%% else -MODM_ISR({{ name | upper }}) -%% endif -{ - using namespace modm::platform; -%% if options["buffer.rx"] - if ({{ hal }}::isReceiveRegisterNotEmpty()) { - // TODO: save the errors - uint8_t data; - {{ hal }}::read(data); - rxBuffer.push(data); - } -%% endif -%% if options["buffer.tx"] - if ({{ hal }}::isTransmitRegisterEmpty()) { - if (txBuffer.isEmpty()) { - // transmission finished, disable TxEmpty interrupt - {{ hal }}::disableInterrupt({{ hal }}::Interrupt::TxEmpty); - } - else { - {{ hal }}::write(txBuffer.get()); - txBuffer.pop(); - } - } -%% endif - {{ hal }}::acknowledgeInterruptFlags({{ hal }}::InterruptFlag::OverrunError); -} +} // namespace modm::platform::{{ name }} %% endif diff --git a/src/modm/platform/uart/stm32/uart.hpp b/src/modm/platform/uart/stm32/uart.hpp new file mode 100644 index 0000000000..c8faed50f5 --- /dev/null +++ b/src/modm/platform/uart/stm32/uart.hpp @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2009-2012, Fabian Greif + * Copyright (c) 2010, Martin Rosekeit + * Copyright (c) 2011, Georgi Grinshpun + * Copyright (c) 2011, 2013-2017, Niklas Hauser + * Copyright (c) 2012, Sascha Schade + * Copyright (c) 2013, 2016, Kevin Läufer + * Copyright (c) 2021, Raphael Lehmann + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +// ---------------------------------------------------------------------------- + +#ifndef MODM_STM32_BUFFERED_UART_HPP +#define MODM_STM32_BUFFERED_UART_HPP + +#include +#include +#include +#include "uart_base.hpp" + +namespace modm::platform +{ + +/** + * Universal asynchronous receiver transmitter (with modular buffers) + * + * @author Kevin Laeufer + * @author Niklas Hauser + * @author Dima Barsky + * @ingroup modm_platform_uart + */ +template< class Hal, typename... Buffers> +struct BufferedUart : public UartBase, public ::modm::Uart +{ + static constexpr size_t RxBufferSize = 0; + static constexpr size_t TxBufferSize = 0; + + template< class... Signals > + static void + connect(Gpio::InputType InputTypeRx = Gpio::InputType::PullUp, + Gpio::OutputType OutputTypeTx = Gpio::OutputType::PushPull) + { + using Connector = GpioConnector; + using Tx = typename Connector::template GetSignal< Gpio::Signal::Tx >; + using Rx = typename Connector::template GetSignal< Gpio::Signal::Rx >; + static_assert(((Connector::template IsValid and Connector::template IsValid) and sizeof...(Signals) == 2) or + ((Connector::template IsValid or Connector::template IsValid) and sizeof...(Signals) == 1), + "BufferedUart::connect() requires one Tx and/or one Rx signal!"); + + Tx::setOutput(true); + Tx::setOutput(OutputTypeTx); + Rx::setInput(InputTypeRx); + Connector::connect(); + } + + /// @warning Remember to set word length correctly when using the parity bit! + template< class SystemClock, baudrate_t baudrate, percent_t tolerance=pct(1) > + static inline void + initialize(Hal::Parity parity=Hal::Parity::Disabled, Hal::WordLength length=Hal::WordLength::Bit8) + { + Hal::template initialize(parity, length); + Hal::enableInterruptVector(true, 12); + Hal::setTransmitterEnable(true); + Hal::setReceiverEnable(true); + Hal::enableOperation(); + } + + static void + writeBlocking(uint8_t data) + { + while(!Hal::isTransmitRegisterEmpty()); + Hal::write(data); + } + + static void + writeBlocking(const uint8_t *data, std::size_t length) + { + while (length-- != 0) { + writeBlocking(*data++); + } + } + + static void + flushWriteBuffer() { while(!isWriteFinished()); } + + static bool + write(uint8_t data) + { + if(!Hal::isTransmitRegisterEmpty()) + return false; + + Hal::write(data); + return true; + } + + static std::size_t + write(const uint8_t *data, std::size_t length) + { + uint32_t i = 0; + for (; i < length; ++i) + { + if (!write(*data++)) { + return i; + } + } + return i; + } + + static bool + isWriteFinished() { return Hal::isTransmitRegisterEmpty(); } + + static std::size_t + transmitBufferSize() { return Hal::isTransmitRegisterEmpty() ? 0 : 1; } + + static std::size_t + discardTransmitBuffer() { return 0; } + + static bool + read(uint8_t &data) + { + if(!Hal::isReceiveRegisterNotEmpty()) + return false; + + Hal::read(data); + return true; + } + + static std::size_t + read(uint8_t *buffer, std::size_t) { return read(*buffer) ? 1 : 0; } + + static std::size_t + receiveBufferSize() { return Hal::isReceiveRegisterNotEmpty() ? 1 : 0; } + + static std::size_t + discardReceiveBuffer() { return 0; } + + static bool + hasError() + { + return Hal::getInterruptFlags().any( + Hal::InterruptFlag::ParityError | +#ifdef USART_ISR_NE + Hal::InterruptFlag::NoiseError | +#endif + Hal::InterruptFlag::OverrunError | Hal::InterruptFlag::FramingError); + } + + static void + clearError() + { + return Hal::acknowledgeInterruptFlags( + Hal::InterruptFlag::ParityError | +#ifdef USART_ISR_NE + Hal::InterruptFlag::NoiseError | +#endif + Hal::InterruptFlag::OverrunError | Hal::InterruptFlag::FramingError); + } +}; + +} + +#endif // MODM_STM32_BUFFERED_UART_HPP diff --git a/src/modm/platform/uart/stm32/uart.hpp.in b/src/modm/platform/uart/stm32/uart.hpp.in deleted file mode 100644 index 7751204d9c..0000000000 --- a/src/modm/platform/uart/stm32/uart.hpp.in +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2009-2012, Fabian Greif - * Copyright (c) 2010, Martin Rosekeit - * Copyright (c) 2011, Georgi Grinshpun - * Copyright (c) 2011, 2013-2017, Niklas Hauser - * Copyright (c) 2012, Sascha Schade - * Copyright (c) 2013, 2016, Kevin Läufer - * Copyright (c) 2021, Raphael Lehmann - * - * This file is part of the modm project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -// ---------------------------------------------------------------------------- - -%% if "Lpuart" in uart_type -#ifndef MODM_STM32_LPUART_{{ id }}_HPP -#define MODM_STM32_LPUART_{{ id }}_HPP -%% else -#ifndef MODM_STM32_UART_{{ id }}_HPP -#define MODM_STM32_UART_{{ id }}_HPP -%%endif - -#include -#include -#include "uart_base.hpp" -%% if "Lpuart" in uart_type -#include "lpuart_hal_{{ id }}.hpp" -%% else -#include "uart_hal_{{ id }}.hpp" -%%endif - -namespace modm::platform -{ - -/** - * Universal asynchronous receiver transmitter ({{ name }}) - * - * @author Kevin Laeufer - * @author Niklas Hauser - * @ingroup modm_platform_uart modm_platform_uart_{{id}} - */ -class {{ name }} : public UartBase, public ::modm::Uart -{ -public: - using Hal = {{ hal }}; - // Expose jinja template parameters to be checked by e.g. drivers or application - static constexpr size_t RxBufferSize = {{ options["buffer.rx"] }}; - static constexpr size_t TxBufferSize = {{ options["buffer.tx"] }}; - -public: - template< class... Signals > - static void - connect(Gpio::InputType InputTypeRx = Gpio::InputType::PullUp, - Gpio::OutputType OutputTypeTx = Gpio::OutputType::PushPull) - { - using Connector = GpioConnector; - using Tx = typename Connector::template GetSignal< Gpio::Signal::Tx >; - using Rx = typename Connector::template GetSignal< Gpio::Signal::Rx >; - static_assert(((Connector::template IsValid and Connector::template IsValid) and sizeof...(Signals) == 2) or - ((Connector::template IsValid or Connector::template IsValid) and sizeof...(Signals) == 1), - "{{ name }}::connect() requires one Tx and/or one Rx signal!"); - - // Connector::disconnect(); - Tx::setOutput(OutputTypeTx); - Rx::setInput(InputTypeRx); - Connector::connect(); - } - - /// @warning Remember to set word length correctly when using the parity bit! - template< class SystemClock, baudrate_t baudrate, percent_t tolerance=pct(1) > - static inline void - initialize(Parity parity=Parity::Disabled, WordLength length=WordLength::Bit8) - { - {{ hal }}::initialize(parity, length); -%% if buffered - {{ hal }}::enableInterruptVector(true, 12); -%% endif -%% if options["buffer.rx"] - {{ hal }}::enableInterrupt(Interrupt::RxNotEmpty); -%% endif - {{ hal }}::setTransmitterEnable(true); - {{ hal }}::setReceiverEnable(true); - {{ hal }}::enableOperation(); - } - - static void - writeBlocking(uint8_t data); - - static void - writeBlocking(const uint8_t *data, std::size_t length); - - static void - flushWriteBuffer(); - - static bool - write(uint8_t data); - - static std::size_t - write(const uint8_t *data, std::size_t length); - - static bool - isWriteFinished(); - - static std::size_t - transmitBufferSize(); - - static std::size_t - discardTransmitBuffer(); - - static bool - read(uint8_t &data); - - static std::size_t - read(uint8_t *buffer, std::size_t length); - - static std::size_t - receiveBufferSize(); - - static std::size_t - discardReceiveBuffer(); - - static bool - hasError(); - - static void - clearError(); - -%% if name in shared_irqs.keys() - static void - irq(); -%% endif -}; - -} // namespace modm::platform - -#endif // MODM_STM32_UART_{{ id }}_HPP diff --git a/src/modm/platform/uart/stm32/uart_base.hpp.in b/src/modm/platform/uart/stm32/uart_base.hpp.in index a7932706d0..0d60c11937 100644 --- a/src/modm/platform/uart/stm32/uart_base.hpp.in +++ b/src/modm/platform/uart/stm32/uart_base.hpp.in @@ -18,6 +18,7 @@ #include "../device.hpp" #include #include +#include /// @cond %% if not extended_driver diff --git a/src/modm/platform/uart/stm32/uart_buffer.hpp b/src/modm/platform/uart/stm32/uart_buffer.hpp new file mode 100644 index 0000000000..13f8085445 --- /dev/null +++ b/src/modm/platform/uart/stm32/uart_buffer.hpp @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2009-2012, Fabian Greif + * Copyright (c) 2010, Martin Rosekeit + * Copyright (c) 2011, Georgi Grinshpun + * Copyright (c) 2011, 2013-2017, 2024, Niklas Hauser + * Copyright (c) 2012, Sascha Schade + * Copyright (c) 2013, 2016, Kevin Läufer + * Copyright (c) 2021, Raphael Lehmann + * Copyright (c) 2024, Dima Barsky + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +// ---------------------------------------------------------------------------- + +#pragma once + +#include +#include +#include "uart_base.hpp" + +namespace modm::platform +{ + +/** + * Universal asynchronous receiver transmitter (implementation based on modm::atomic::Queue) + * + * @author Kevin Laeufer + * @author Niklas Hauser + * @author Dima Barsky + * @ingroup modm_platform_uart + * @{ + */ +template +class UartRxBuffer : public modm::Uart::RxBuffer, public modm::atomic::Queue {}; +template +class UartTxBuffer : public modm::Uart::TxBuffer, public modm::atomic::Queue {}; +/// @} + +/// @cond +template< class Hal, class... Buffers > +class BufferedUart; + +template +class BufferedUart, Buffers...>: public BufferedUart +{ + template< class Hal_, class... Buffers_> friend class BufferedUart; + using Parent = BufferedUart; + static_assert(not Parent::TxBufferSize, "BufferedUart accepts at most one TxBuffer type"); + static inline UartTxBuffer txBuffer; + + static bool + InterruptCallback(bool first) + { + if constexpr (Parent::RxBufferSize) Parent::InterruptCallback(false); + + if (Hal::isTransmitRegisterEmpty()) + { + if (txBuffer.isEmpty()) + { + atomic::Lock lock; + // transmission finished, disable TxEmpty interrupt + Hal::disableInterrupt(Hal::Interrupt::TxEmpty); + } + else + { + Hal::write(txBuffer.get()); + txBuffer.pop(); + } + } + if (first) Hal::acknowledgeInterruptFlags(Hal::InterruptFlag::OverrunError); + return true; + } + +public: + static constexpr size_t TxBufferSize = SIZE; + + template< class SystemClock, baudrate_t baudrate, percent_t tolerance=pct(1) > + static inline void + initialize(Hal::Parity parity=Hal::Parity::Disabled, Hal::WordLength length=Hal::WordLength::Bit8) + { + Parent::template initialize(parity, length); + Hal::InterruptCallback = InterruptCallback; + } + + static bool + write(uint8_t data) + { + if (transmitBufferSize() == 0 and txBuffer.isEmpty()) + Hal::write(data); + else + { + if (not txBuffer.push(data)) return false; + // Disable interrupts while enabling the transmit interrupt + atomic::Lock lock; + // Transmit Data Register Empty Interrupt Enable + Hal::enableInterrupt(Hal::Interrupt::TxEmpty); + } + return true; + } + + static std::size_t + write(const uint8_t *data, std::size_t length) + { + std::size_t count{0}; + for (; count < length; ++count) if (not write(*data++)) break; + return count; + } + + static void + flushWriteBuffer() { while(not isWriteFinished()); } + + static bool + isWriteFinished() { return txBuffer.isEmpty() and Hal::isTransmitRegisterEmpty(); } + + static std::size_t + transmitBufferSize() { return txBuffer.getSize(); } + + std::size_t + discardTransmitBuffer() + { + { + atomic::Lock lock; + // disable interrupt since buffer will be cleared + Hal::disableInterrupt(Hal::Interrupt::TxEmpty); + } + std::size_t count{0}; + while(not txBuffer.isEmpty()) + { + ++count; + txBuffer.pop(); + } + return count; + } +}; + +template +class BufferedUart, Buffers...>: public BufferedUart +{ + template< class Hal_, class... Buffers_> friend class BufferedUart; + using Parent = BufferedUart; + static_assert(not Parent::RxBufferSize, "BufferedUart accepts at most one RxBuffer type"); + static inline UartRxBuffer rxBuffer; + + static bool + InterruptCallback(bool first) + { + if constexpr (Parent::TxBufferSize) Parent::InterruptCallback(false); + + if (Hal::isReceiveRegisterNotEmpty()) + { + uint8_t data; + Hal::read(data); + rxBuffer.push(data); + } + if (first) Hal::acknowledgeInterruptFlags(Hal::InterruptFlag::OverrunError); + return true; + } + +public: + static constexpr size_t RxBufferSize = SIZE; + + template< class SystemClock, baudrate_t baudrate, percent_t tolerance=pct(1) > + static inline void + initialize(Hal::Parity parity=Hal::Parity::Disabled, Hal::WordLength length=Hal::WordLength::Bit8) + { + Parent::template initialize(parity, length); + Hal::InterruptCallback = InterruptCallback; + Hal::enableInterrupt(Hal::Interrupt::RxNotEmpty); + } + + static bool + read(uint8_t &data) + { + if (rxBuffer.isEmpty()) return false; + + data = rxBuffer.get(); + rxBuffer.pop(); + return true; + } + + static std::size_t + read(uint8_t *data, std::size_t length) + { + std::size_t count{0}; + for (; count < length; ++count) + { + if (rxBuffer.isEmpty()) break; + + *data++ = rxBuffer.get(); + rxBuffer.pop(); + } + return count; + } + + static std::size_t + receiveBufferSize() { return rxBuffer.getSize(); } + + static std::size_t + discardReceiveBuffer() + { + std::size_t count{0}; + while(not rxBuffer.isEmpty()) + { + ++count; + rxBuffer.pop(); + } + return count; + } +}; +/// @endcond + +} // namespace modm::platform + diff --git a/src/modm/platform/uart/stm32/uart_hal.hpp.in b/src/modm/platform/uart/stm32/uart_hal.hpp.in index 32a5f57c36..f3fb61b883 100644 --- a/src/modm/platform/uart/stm32/uart_hal.hpp.in +++ b/src/modm/platform/uart/stm32/uart_hal.hpp.in @@ -24,6 +24,7 @@ #include "../device.hpp" #include "uart_base.hpp" #include +#include namespace modm::platform @@ -44,6 +45,8 @@ class {{ hal }} : public UartBase { public: static constexpr bool isExtended = {{ extended_driver | lower }}; + static const Peripheral UartPeripheral = Peripheral::{{name}}; + static inline modm::inplace_function InterruptCallback; /// Enables the clock, resets the hardware /// @warning Call `enableOperation()` to start the peripheral! diff --git a/src/modm/platform/uart/stm32/uart_hal_impl.hpp.in b/src/modm/platform/uart/stm32/uart_hal_impl.hpp.in index 821b307356..2c274ad5c1 100644 --- a/src/modm/platform/uart/stm32/uart_hal_impl.hpp.in +++ b/src/modm/platform/uart/stm32/uart_hal_impl.hpp.in @@ -287,7 +287,6 @@ void tmp = {{ peripheral }}->DR; (void) tmp; } - (void) flags; // avoid compiler warning %% endif } diff --git a/src/modm/platform/uart/stm32/uart_shared.cpp.in b/src/modm/platform/uart/stm32/uart_shared.cpp.in index 10c2bb9653..08d5bec6e2 100644 --- a/src/modm/platform/uart/stm32/uart_shared.cpp.in +++ b/src/modm/platform/uart/stm32/uart_shared.cpp.in @@ -10,14 +10,14 @@ // ---------------------------------------------------------------------------- #include "../device.hpp" +#include "uart_base.hpp" %% for irq, uarts in uart_shared_irqs_data.items() %% for uart in uarts -%% if "Lpuart" in uart.type -#include "lpuart_{{ uart["id"] }}.hpp" -%%else -#include "uart_{{ uart["id"] }}.hpp" -%%endif +namespace modm::platform::{{ uart.name }} +{ + extern void irq(); +} %% endfor %% endfor