Skip to content

Commit

Permalink
Fix USART support
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehaenger committed Jul 17, 2024
1 parent a429199 commit 68a5e95
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
21 changes: 21 additions & 0 deletions examples/stm32c0x/blink-timer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,37 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <modm/debug/logger.hpp>
#include <modm/platform.hpp>

#include "../custom-board.hpp"

using namespace Board;
using namespace std::chrono_literals;

// --- UART Debugging ---
#undef MODM_LOG_LEVEL
#define MODM_LOG_LEVEL modm::log::DEBUG
// Create an IODeviceWrapper around the Uart Peripheral we want to use
modm::IODeviceWrapper<proto_uart::Uart, modm::IOBuffer::BlockIfFull> loggerDevice;
// Set all four logger streams to use the UART
modm::log::Logger modm::log::debug(loggerDevice);
modm::log::Logger modm::log::info(loggerDevice);
modm::log::Logger modm::log::warning(loggerDevice);
modm::log::Logger modm::log::error(loggerDevice);


MODM_ISR(TIM14)
{
Timer14::acknowledgeInterruptFlags(Timer14::InterruptFlag::Update);
MODM_LOG_DEBUG << "Toggle green LED" << modm::endl;
LedGn::toggle();
}

MODM_ISR(TIM16)
{
Timer16::acknowledgeInterruptFlags(Timer16::InterruptFlag::Update);
MODM_LOG_DEBUG << "Toggle red LED" << modm::endl;
LedRd::toggle();
}

Expand All @@ -32,6 +47,12 @@ main()
{
Board::initialize();

// Initialize prototyping-UART for MODM_LOG_*
proto_uart::Uart::connect<proto_uart::Tx::Tx, proto_uart::Rx::Rx>();
proto_uart::Uart::initialize<SystemClock, 115200_Bd>();

MODM_LOG_INFO << "Board & Logger initialized" << modm::endl;

Timer14::enable();
Timer14::setMode(Timer14::Mode::UpCounter);
Timer14::setPeriod<Board::SystemClock>(1000ms);
Expand Down
7 changes: 5 additions & 2 deletions examples/stm32c0x/blink-timer/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
<option name="modm:build:build.path">../../../build/stm32c0x/blink-timer</option>
</options>
<modules>
<module>modm:architecture:clock</module>
<module>modm:build:scons</module>
<module>modm:debug</module>
<module>modm:platform:core</module>
<module>modm:platform:rcc</module>
<module>modm:platform:gpio</module>
<module>modm:platform:timer:14</module>
<module>modm:platform:timer:16</module>
<module>modm:architecture:clock</module>
<module>modm:build:scons</module>
<module>modm:platform:uart:1</module>
<module>modm:platform:uart:2</module>
</modules>
</library>
33 changes: 19 additions & 14 deletions examples/stm32c0x/custom-board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

#include <modm/architecture/interface/clock.hpp>
#include <modm/platform.hpp>
// #include <modm/debug/logger.hpp>
/// @ingroup modm_board_custom_stm32c0x modm_board_custom_stm32c0x
// #define MODM_BOARD_HAS_LOGGER

using namespace modm::platform;

Expand All @@ -40,6 +37,8 @@ struct SystemClock
static constexpr uint32_t Timer14 = Apb;
static constexpr uint32_t Timer16 = Apb;
static constexpr uint32_t Timer17 = Apb;
static constexpr uint32_t Usart1 = Ahb;
static constexpr uint32_t Usart2 = Ahb;

static bool inline enable()
{
Expand All @@ -60,33 +59,39 @@ using LedRd = GpioC14;
using Leds = SoftwareGpioPort<LedGn, LedRd>;
/// @}

/*namespace stlink
namespace om_uart
{
/// @ingroup modm_board_custom_stm32c0x modm_board_custom_stm32c0x
/// @ingroup modm_board_custom_stm32c0x
/// @{
using Rx = GpioInputA3;
using Tx = GpioOutputA2;
using Uart = BufferedUart<UsartHal2, UartTxBuffer<2048>>;
using Tx = GpioOutputA9;
using Rx = GpioInputA10;
using Uart = BufferedUart<UsartHal1, UartTxBuffer<64>>;
/// @}
}*/
} // namespace om_uart

/// @ingroup modm_board_custom_stm32c0x modm_board_custom_stm32c0x
namespace proto_uart
{
/// @ingroup modm_board_custom_stm32c0x
/// @{
// using LoggerDevice = modm::IODeviceWrapper< stlink::Uart, modm::IOBuffer::BlockIfFull >;
using Tx = GpioOutputA4;
using Rx = GpioInputA5;
using Uart = BufferedUart<UsartHal2, UartTxBuffer<64>>;
/// @}
} // namespace proto_uart

inline void
initialize()
{
SystemClock::enable();
SysTickTimer::initialize<SystemClock>();

// stlink::Uart::connect<stlink::Tx::Tx, stlink::Rx::Rx>();
// stlink::Uart::initialize<SystemClock, 115200_Bd>();
// Remap om_uart GPIOs
GpioA9::remap(); // Remap A9 -> A11
GpioA10::remap(); // Remap A10 -> A12

LedGn::setOutput();
LedRd::setOutput();
}
/// @}

} // namespace Board

Expand Down
4 changes: 2 additions & 2 deletions src/modm/platform/uart/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def prepare(module, options):

global props
drivers = (device.get_all_drivers("uart") + device.get_all_drivers("usart") + device.get_all_drivers("lpuart"))
props["extended_driver"] = ("extended" in drivers[0]["type"])
props["extended_driver"] = ("extended" in drivers[0]["type"]) or device.identifier.family == "c0" # FIXME: C0 doesn't has this feature in modm-devices. Add there?
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["tcbgt"] = (("feature" in drivers[0]) and ("tcbgt" in drivers[0]["feature"])) or device.identifier.family == "c0" # FIXME: C0 doesn't has this feature in modm-devices. Add there?
props["instances"] = []

for driver in drivers:
Expand Down

0 comments on commit 68a5e95

Please sign in to comment.