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

[uart] Refactor STM32 USART HAL and make TX/RX buffer optional #564

Merged
merged 5 commits into from
Feb 23, 2021
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ before_install:
- sudo apt-get install -y python3 python3-pip scons cmake doxygen gcc-10 g++-10 build-essential libboost-all-dev libwiringpi-dev
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 90 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10
#- sudo apt-get install -y gcc-arm-none-eabi
- wget -qO- https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2 | tar xj -C /opt
- wget -qO- https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2 | tar xvj -C /opt
- export PATH="/opt/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH"
- pip3 install modm
- export PATH="~/.local/bin:$PATH"
Expand Down
2 changes: 1 addition & 1 deletion examples/generic/i2c_multiplex/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ main()

#ifndef MODM_BOARD_HAS_LOGGER
LoggerUsart::connect<LoggerUsartTx::Tx, LoggerUsartRx::Rx>();
LoggerUsart::initialize<Board::SystemClock, 115200_Bd>(12);
LoggerUsart::initialize<Board::SystemClock, 115200_Bd>();
#endif

modm::platform::I2cMaster1::connect<modm::platform::GpioB7::Sda, modm::platform::GpioB6::Scl>();
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 @@ -95,7 +95,7 @@ main()

// Reinit onboard UART to 1 Mbps
// Do not use it for logging because this will destroy ROS serial messages.
RosSerialUart::initialize<Board::SystemClock, 250_kBd>(12);
RosSerialUart::initialize<Board::SystemClock, 250_kBd>();

CanFilter::setStartFilterBankForCan2(14);

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 @@ -62,7 +62,7 @@ main()

// Reinit onboard UART to 1 Mbps
// Do not use it for logging because this will destroy ROS serial messages.
Board::stlink::Uart::initialize<Board::SystemClock, 1_MBd>(12);
Board::stlink::Uart::initialize<Board::SystemClock, 1_MBd>();

MyI2cMaster::connect<Board::D14::Sda, Board::D15::Scl>();
MyI2cMaster::initialize<Board::SystemClock, 100_kHz>();
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 @@ -74,7 +74,7 @@ main()

// Reinit onboard UART to 1 Mbps
// Do not use it for logging because this will destroy ROS serial messages.
Board::stlink::Uart::initialize<Board::SystemClock, 1_MBd>(12);
Board::stlink::Uart::initialize<Board::SystemClock, 1_MBd>();

Board::LedGreen::set();

Expand Down
6 changes: 3 additions & 3 deletions examples/nucleo_g071rb/amnb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ main()
LedD13::setOutput();

Usart1::connect<PinNode1::Tx>();
Usart1::initialize<SystemClock, 115200>();
Usart1::initialize<SystemClock, 115200>(Usart1::Parity::Even, Usart1::WordLength::Bit9);
// Use Single-Wire Half-Duplex Mode
PinNode1::configure(Gpio::OutputType::OpenDrain);
PinNode1::configure(Gpio::InputType::PullUp);
Expand All @@ -78,7 +78,7 @@ main()
USART1->CR1 |= USART_CR1_UE;

Usart3::connect<PinNode2::Tx>();
Usart3::initialize<SystemClock, 115200>();
Usart3::initialize<SystemClock, 115200>(Usart1::Parity::Even, Usart1::WordLength::Bit9);
// Use Single-Wire Half-Duplex Mode
PinNode2::configure(Gpio::OutputType::OpenDrain);
PinNode2::configure(Gpio::InputType::PullUp);
Expand All @@ -87,7 +87,7 @@ main()
USART3->CR1 |= USART_CR1_UE;

Usart4::connect<PinNode3::Tx>();
Usart4::initialize<SystemClock, 115200>();
Usart4::initialize<SystemClock, 115200>(Usart1::Parity::Even, Usart1::WordLength::Bit9);
// Use Single-Wire Half-Duplex Mode
PinNode3::configure(Gpio::OutputType::OpenDrain);
PinNode3::configure(Gpio::InputType::PullUp);
Expand Down
5 changes: 2 additions & 3 deletions examples/nucleo_g071rb/amnb/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
<extends>modm:nucleo-g071rb</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_g071rb/amnb</option>
<option name="modm:platform:uart:1:buffer.tx">1</option>
<option name="modm:platform:uart:1:buffer.rx">32</option>
<option name="modm:platform:uart:3:buffer.tx">1</option>
<option name="modm:platform:uart:3: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
2 changes: 1 addition & 1 deletion examples/stm32f0_discovery/logger/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ main()

// initialize Uart1 for MODM_LOG_*
Usart1::connect<GpioOutputA9::Tx, GpioInputA10::Rx>();
Usart1::initialize<Board::SystemClock, 115200_Bd>(12);
Usart1::initialize<Board::SystemClock, 115200_Bd>();

// Use the logging streams to print some messages.
// Change MODM_LOG_LEVEL above to enable or disable these messages
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f0_discovery/logger/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<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">1024</option>
</options>
<modules>
<module>modm:debug</module>
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f4_discovery/can/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<extends>modm:disco-f407vg</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f4_discovery/can</option>
<option name="modm:platform:uart:2:buffer.tx">2048</option>
</options>
<modules>
<module>modm:debug</module>
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f4_discovery/can2/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<extends>modm:disco-f407vg</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f4_discovery/can2</option>
<option name="modm:platform:uart:2:buffer.tx">2048</option>
</options>
<modules>
<module>modm:debug</module>
Expand Down
2 changes: 1 addition & 1 deletion examples/stm32f4_discovery/pressure_ams5915/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ main()
Board::initialize();

Usart2::connect<GpioOutputA2::Tx>();
Usart2::initialize<Board::SystemClock, 115200_Bd>(10);
Usart2::initialize<Board::SystemClock, 115200_Bd>();

MyI2cMaster::connect<GpioB10::Scl, GpioB11::Sda>();
MyI2cMaster::initialize<Board::SystemClock, 400_kHz>();
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f4_discovery/pressure_ams5915/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<extends>modm:disco-f407vg</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f4_discovery/pressure_ams5915</option>
<option name="modm:platform:uart:2:buffer.tx">2048</option>
</options>
<modules>
<module>modm:driver:ams5915</module>
Expand Down
2 changes: 1 addition & 1 deletion examples/stm32f4_discovery/temperature_ltc2984/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ main()
Board::initialize();

Usart2::connect<GpioOutputA2::Tx>();
Usart2::initialize<Board::SystemClock, 115200_Bd>(10);
Usart2::initialize<Board::SystemClock, 115200_Bd>();

// Connect the GPIOs to the SPIs alternate function
SpiMaster::connect<Sck::Sck, Mosi::Mosi, Miso::Miso>();
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f4_discovery/temperature_ltc2984/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<extends>modm:disco-f407vg</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f4_discovery/temperature_ltc2984</option>
<option name="modm:platform:uart:2:buffer.tx">2048</option>
</options>
<modules>
<module>modm:driver:ltc2984</module>
Expand Down
2 changes: 1 addition & 1 deletion src/modm/board/olimexino_stm32/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ initialize()
SysTickTimer::initialize<SystemClock>();

uext::Uart::connect<uext::Tx::Tx, uext::Rx::Rx>();
uext::Uart::initialize<SystemClock, 115200_Bd>(12);
uext::Uart::initialize<SystemClock, 115200_Bd>();

}

Expand Down
10 changes: 6 additions & 4 deletions src/modm/platform/spi/stm32_uart/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

def get_properties(env):
device = env[":target"]
driver = device.get_driver("usart:stm32")
properties = device.properties
properties["target"] = device.identifier
properties["driver"] = driver
driver = device.get_driver("usart:stm32*")
properties = {
"target": device.identifier,
"driver": driver,
"over8_sampling": ("feature" in driver) and ("over8" in driver["feature"]),
}
return properties

class Instance(Module):
Expand Down
29 changes: 7 additions & 22 deletions src/modm/platform/spi/stm32_uart/uart_spi_master.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,13 @@ public:
static void
initialize()
{
%% if target["family"] != "f1"
constexpr UartBase::OversamplingMode oversample =
UartBaudrate::getOversamplingMode(SystemClock::Usart{{ id }}, baudrate);
%% endif
UsartHal{{ id }}::initializeWithBrr(
UartBaudrate::getBrr<SystemClock::Usart{{ id }}, baudrate, tolerance>(),
%% if target["family"] == "f1"
UsartHal{{ id }}::Parity::Disabled);
%% else
UsartHal{{ id }}::Parity::Disabled,
oversample);
%% endif

%% if extended
UsartHal{{ id }}::disableOperation();
%% endif
UsartHal{{ id }}::setLastBitClockPulse(UsartHal{{ id }}::LastBitClockPulse::Output);
UsartHal{{ id }}::setSpiClock(UsartHal{{ id }}::SpiClock::Enabled);
%% if extended
UsartHal{{ id }}::enableOperation();
%% endif

UsartHal{{ id }}::initialize<SystemClock, baudrate, tolerance>(
UsartHal{{ id }}::Parity::Disabled, UsartHal{{ id }}::WordLength::Bit8);
UsartHal{{ id }}::setSpiClock(UsartHal{{ id }}::SpiClock::Enabled,
UsartHal{{ id }}::LastBitClockPulse::Output);
UsartHal{{ id }}::setTransmitterEnable(true);
UsartHal{{ id }}::setReceiverEnable(true);
UsartHal{{ id }}::enableOperation();
dataOrder = DataOrder::MsbFirst;
state = 0;
}
Expand All @@ -104,7 +87,9 @@ public:
static void
setDataMode(DataMode mode)
{
if constexpr (UsartHal{{ id }}::isExtended) UsartHal{{ id }}::disableOperation();
UsartHal{{ id }}::setSpiDataMode(static_cast<UartBase::SpiDataMode>(mode));
if constexpr (UsartHal{{ id }}::isExtended) UsartHal{{ id }}::enableOperation();
}

/// @warning On this target, only `DataOrder::LsbFirst` is natively
Expand Down
5 changes: 0 additions & 5 deletions src/modm/platform/uart/at90_tiny_mega/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ def get_properties(env):
return properties

def load_options(module):
module.add_option(
BooleanOption(
name="buffered",
description="",
default=True))
module.add_option(
NumericOption(
name="buffer.tx",
Expand Down
21 changes: 2 additions & 19 deletions src/modm/platform/uart/sam/module.lb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2018, Niklas Hauser
# Copyright (c) 2017, Fabian Greif
# Copyright (c) 2017, Erik Henriksson
# Copyright (c) 2020, Erik Henriksson
#
# This file is part of the modm project.
#
Expand All @@ -30,9 +28,6 @@ class Instance(Module):
device = env[":target"].identifier
global props
props["id"] = self.instance
props["driver"] = self.driver
props["features"] = self.driver["feature"] if "feature" in self.driver else []
props["uart_name"] = 'Uart'
props["sercom_name"] = self.driver["name"].capitalize()

env.substitutions = props
Expand All @@ -43,22 +38,17 @@ class Instance(Module):
env.template("uart.hpp.in", "uart_{}.hpp".format(self.instance))
env.template("uart.cpp.in", "uart_{}.cpp".format(self.instance))

props["instances"].append(self.instance)


def init(module):
module.name = ":platform:uart"
module.description = "Universal Asynchronous Receiver Transmitter (UART)"

def prepare(module, options):
device = options[":target"]
if not (device.has_driver("sercom:*")):
if not (device.has_driver("sercom:sam")):
return False

module.depends(
":architecture:atomic",
":architecture:interrupt",
":architecture:register",
":architecture:uart",
":math:algorithm",
":cmsis:device",
Expand All @@ -67,11 +57,6 @@ def prepare(module, options):

global props
drivers = options[":target"].get_all_drivers("sercom")
props["extended_driver"] = ("extended" in drivers[0]["type"])
props["over8_sampling"] = ("feature" in drivers[0]) and ("over8" in drivers[0]["feature"])
props["tcbgt"] = ("feature" in drivers[0]) and ("tcbgt" in drivers[0]["feature"])
props["instances"] = []

for driver in drivers:
for instance in driver["instance"]:
module.add_submodule(Instance(driver, instance))
Expand All @@ -80,8 +65,6 @@ def prepare(module, options):
return True

def build(env):
device = env[":target"]

global props
env.substitutions = props
env.outbasepath = "modm/src/modm/platform/uart"
Expand Down
Loading