Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BufferedUart template and its specialisation for FreeRTOS queues #1156

Merged
merged 4 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions examples/black_pill_f401/uart_freertos/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <modm/board.hpp>
#include <freertos/FreeRTOS.h>
#include <freertos/queue.h>

/*
* 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<UsartHal1, UartTxBuffer<4>>;
using FreeRtosUart = BufferedUart<UsartHal1, UartRxBufferFreeRtos<8>, UartTxBufferFreeRtos<4>>;

void
taskMain(void *)
{
// Let's test the old driver first:
Uart::connect<GpioOutputB6::Tx, GpioInputB7::Rx>();
Uart::initialize<SystemClock, 115200_Bd>();
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<GpioOutputB6::Tx, GpioInputB7::Rx>();
FreeRtosUart::initialize<SystemClock, 115200_Bd>();
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;
}
12 changes: 12 additions & 0 deletions examples/black_pill_f401/uart_freertos/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<library>
<extends>modm:black-pill-f401</extends>
<options>
<option name="modm:build:build.path">../../../build/black_pill_f401/uart_freertos</option>
</options>
<modules>
<module>modm:build:make</module>
<module>modm:build:scons</module>
<module>modm:platform:uart:1</module>
<module>modm:freertos</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/blue_pill_f103/adns_9800/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#undef MODM_LOG_LEVEL
#define MODM_LOG_LEVEL modm::log::DEBUG

using Usart2 = BufferedUart<UsartHal2, UartTxBuffer<256>>;
// Create an IODeviceWrapper around the Uart Peripheral we want to use
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;

Expand Down
2 changes: 2 additions & 0 deletions examples/blue_pill_f103/can/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <modm/board.hpp>
#include <modm/debug/logger.hpp>


using Usart2 = BufferedUart<UsartHal2, UartTxBuffer<256>>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;
modm::log::Logger modm::log::info(loggerDevice);

Expand Down
1 change: 1 addition & 0 deletions examples/blue_pill_f103/encoder_input/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsartHal2, UartTxBuffer<256>>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
Expand Down
1 change: 1 addition & 0 deletions examples/blue_pill_f103/encoder_input_bitbang/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsartHal2, UartTxBuffer<256>>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
Expand Down
1 change: 1 addition & 0 deletions examples/blue_pill_f103/environment/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsartHal2, UartTxBuffer<256>>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;
modm::IOStream stream(loggerDevice);

Expand Down
1 change: 1 addition & 0 deletions examples/blue_pill_f103/flash/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using namespace std::chrono_literals;

using Usart2 = BufferedUart<UsartHal2, UartTxBuffer<256>>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;
modm::log::Logger modm::log::info(loggerDevice);

Expand Down
1 change: 1 addition & 0 deletions examples/blue_pill_f103/logger/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsartHal2, UartTxBuffer<256>>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
Expand Down
1 change: 1 addition & 0 deletions examples/blue_pill_f103/weight_scale_hx711/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsartHal1, UartTxBuffer<256>>;
modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
Expand Down
1 change: 1 addition & 0 deletions examples/generic/i2c_multiplex/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ using I2cMultiplexer = modm::I2cMultiplexer<MyI2cMaster, Mpx>;
#ifndef MODM_BOARD_HAS_LOGGER
#include <modm/debug.hpp>
// Add logger manually
using Usart2 = BufferedUart<UsartHal2, UartTxBuffer<2048>, UartRxBuffer<2048>>;
using LoggerUsart = Usart2;
using LoggerUsartTx = modm::platform::GpioA2;
using LoggerUsartRx = modm::platform::GpioA3;
Expand Down
2 changes: 0 additions & 2 deletions examples/generic/i2c_multiplex/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<options>
<option name=":target">stm32f303k8t6</option>
<!-- <option name=":target">stm32f103c8t6</option> -->
<option name=":platform:uart:2:buffer.tx">2Ki</option>
<option name=":platform:uart:2:buffer.rx">2Ki</option>
<option name=":build:build.path">../../../build/generic/i2c_multiplex</option>
</options>
<modules>
Expand Down
2 changes: 1 addition & 1 deletion examples/generic/ros/can_bridge/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsartHal2, UartTxBuffer<512>, UartRxBuffer<512>>;

namespace ros
{
Expand Down
2 changes: 0 additions & 2 deletions examples/generic/ros/can_bridge/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<options>
<option name="modm:build:build.path">../../../../build/generic/ros/can_bridge</option>
<option name="modm:build:openocd.cfg">openocd.cfg</option>
<option name="modm:platform:uart:2:buffer.tx">512</option>
<option name="modm:platform:uart:2:buffer.rx">512</option>
</options>
<modules>
<module>modm:build:scons</module>
Expand Down
2 changes: 1 addition & 1 deletion examples/generic/ros/environment/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsartHal2, UartTxBuffer<512>, UartRxBuffer<512>>;

namespace ros
{
Expand Down
2 changes: 0 additions & 2 deletions examples/generic/ros/environment/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<extends>modm:nucleo-l476rg</extends>
<options>
<option name="modm:build:build.path">../../../../build/generic/ros/environment</option>
<option name="modm:platform:uart:2:buffer.tx">512</option>
<option name="modm:platform:uart:2:buffer.rx">512</option>
</options>
<modules>
<module>modm:driver:bme280</module>
Expand Down
2 changes: 1 addition & 1 deletion examples/generic/ros/sub_pub/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsartHal2, UartTxBuffer<512>, UartRxBuffer<512>>;

namespace ampel
{
Expand Down
2 changes: 0 additions & 2 deletions examples/generic/ros/sub_pub/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<extends>modm:nucleo-l476rg</extends>
<options>
<option name="modm:build:build.path">../../../../build/generic/ros/sub_pub</option>
<option name="modm:platform:uart:2:buffer.tx">512</option>
<option name="modm:platform:uart:2:buffer.rx">512</option>
</options>
<modules>
<module>modm:communication:ros</module>
Expand Down
3 changes: 3 additions & 0 deletions examples/nucleo_g071rb/amnb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
using namespace Board;
using namespace std::chrono_literals;
using namespace modm::amnb;
using Usart1 = BufferedUart<UsartHal1, UartRxBuffer<32>>;
using Usart3 = BufferedUart<UsartHal3, UartRxBuffer<16>>;
using Usart4 = BufferedUart<UsartHal4>;
// ----------------------------------------------------------------------------

Listener listeners[] =
Expand Down
3 changes: 0 additions & 3 deletions examples/nucleo_g071rb/amnb/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
<extends>modm:nucleo-g071rb</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_g071rb/amnb</option>
<option name="modm:platform:uart:1:buffer.rx">32</option>
<option name="modm:platform:uart:3:buffer.rx">16</option>
<option name="modm:platform:uart:4:buffer.rx">0</option>
<option name="modm:communication:amnb:with_heap">False</option>
</options>
<modules>
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f072_discovery/can/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

// Create an IODeviceWrapper around the Uart Peripheral we want to use
using Usart1 = BufferedUart<UsartHal1>;
modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f072_discovery/hard_fault/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsartHal1>;
modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f072_discovery/stusb4500/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <modm/debug/logger.hpp>
#include <modm/driver/usb/stusb4500.hpp>

using Usart1 = BufferedUart<UsartHal1>;
modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice;
#undef MODM_LOG_LEVEL
#define MODM_LOG_LEVEL modm::log::INFO
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f072_discovery/tmp102/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <modm/io/iostream.hpp>

using Usart1 = BufferedUart<UsartHal1>;
modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > device;
modm::IOStream stream(device);

Expand Down
1 change: 1 addition & 0 deletions examples/stm32f072_discovery/uart/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ main()
Board::LedUp::set();

// Enable USART 1
using Usart1 = BufferedUart<UsartHal1>;
Usart1::connect<GpioOutputA9::Tx>();
Usart1::initialize<Board::SystemClock, 9600_Bd>();

Expand Down
1 change: 1 addition & 0 deletions examples/stm32f0_discovery/logger/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsartHal1, UartTxBuffer<1024>>;
modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
Expand Down
1 change: 0 additions & 1 deletion examples/stm32f0_discovery/logger/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<extends>modm:disco-f051r8</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f0_discovery/logger</option>
<option name="modm:platform:uart:1:buffer.tx">1Ki</option>
</options>
<modules>
<module>modm:debug</module>
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f1_discovery/logger/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsartHal2>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f3_discovery/adc/continous/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef GpioInputC2 Adc2In;
typedef GpioInputB13 Adc3In;
typedef GpioInputB12 Adc4In;

using Usart2 = BufferedUart<UsartHal2>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;
modm::log::Logger modm::log::info(loggerDevice);

Expand Down
1 change: 1 addition & 0 deletions examples/stm32f3_discovery/adc/interrupt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

typedef GpioInputB12 AdcIn0;

using Usart2 = BufferedUart<UsartHal2>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;
modm::log::Logger modm::log::info(loggerDevice);

Expand Down
1 change: 1 addition & 0 deletions examples/stm32f3_discovery/adc/simple/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

typedef GpioInputB12 AdcIn0;

using Usart2 = BufferedUart<UsartHal2>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;
modm::log::Logger modm::log::info(loggerDevice);

Expand Down
1 change: 1 addition & 0 deletions examples/stm32f3_discovery/can/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

// Create an IODeviceWrapper around the Uart Peripheral we want to use
using Usart2 = BufferedUart<UsartHal2>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f3_discovery/comp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsartHal2>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f3_discovery/uart/logger/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsartHal2>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f401_discovery/uart/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ main()
Board::LedRed::set();

// Enable USART 2
using Usart2 = BufferedUart<UsartHal2>;
Usart2::connect<GpioA2::Tx>();
Usart2::initialize<Board::SystemClock, 9600_Bd>();

Expand Down
1 change: 1 addition & 0 deletions examples/stm32f407vet6_devebox/flash/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using namespace Board;

using Usart1 = BufferedUart<UsartHal1>;
modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f407vet6_devebox/logger/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using namespace Board;

using Usart1 = BufferedUart<UsartHal1>;
modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
Expand Down
1 change: 0 additions & 1 deletion examples/stm32f469_discovery/can/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<module>modm:platform:can:1</module>
<module>modm:platform:can:2</module>
<module>modm:platform:gpio</module>
<module>modm:platform:uart:3</module>
<module>modm:processing:timer</module>
<module>modm:build:scons</module>
</modules>
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f4_discovery/adc/interrupt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

typedef GpioInputA7 AdcIn;

using Usart2 = BufferedUart<UsartHal2>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;
modm::log::Logger modm::log::info(loggerDevice);

Expand Down
1 change: 1 addition & 0 deletions examples/stm32f4_discovery/adc/oversample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef GpioInputA7 AdcIn0;
typedef GpioInputA4 AdcIn1;
typedef GpioInputA2 AdcIn2;

using Usart2 = BufferedUart<UsartHal2>;
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;
modm::log::Logger modm::log::info(loggerDevice);

Expand Down
Loading
Loading