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

Refactor IWDG driver and add initialize function for prescaler with downcounter #1127

Merged
merged 12 commits into from
Feb 6, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <modm/platform.hpp>

using namespace Board;
using namespace std::chrono_literals;

/**
* If the button is pressed for more than 4 seconds, the MCU will be reset by the Watchdog.
Expand All @@ -25,7 +26,7 @@ main()
Board::initialize();
LedD13::setOutput();
// set the watchdog timeout to 4 seconds
Iwdg::initialize(Iwdg::Prescaler::Div32, 0x0FFFu);
Iwdg::initialize<SystemClock, 4s>();

// Use the logging streams to print some messages.
// Change MODM_LOG_LEVEL above to enable or disable these messages
Expand Down
2 changes: 1 addition & 1 deletion examples/nucleo_l432kc/gyroscope/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ main()
Board::initialize();

UartSpi::Master::connect<UartSpi::Ck::Ck, UartSpi::Tx::Tx, UartSpi::Rx::Rx>();
UartSpi::Master::initialize<Board::SystemClock, 8_MHz, 0_pct>();
UartSpi::Master::initialize<Board::SystemClock, 5_MHz, 0_pct>();

while (true) {
reader.update();
Expand Down
1 change: 1 addition & 0 deletions repo.lb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def init(repo):
repo.add_filter("modm.posixify", posixify)
repo.add_filter("modm.ord", lambda letter: ord(letter[0].lower()) - ord("a"))
repo.add_filter("modm.chr", lambda num: chr(num + ord("A")))
repo.add_filter("modm.digsep", lambda num: f"{num:,}".replace(",", "'"))

# Compute the available data from modm-devices
devices = DevicesCache()
Expand Down
12 changes: 10 additions & 2 deletions src/modm/architecture/interface/peripheral.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,21 @@ class PeripheralDriver
* This method checks if the user requested baudrate is within error
* tolerance of the system achievable baudrate.
*/
template< baudrate_t available, baudrate_t requested, percent_t tolerance >
template< uint64_t available, uint64_t requested, percent_t tolerance >
static void
assertBaudrateInTolerance()
{
static_assert(modm::Tolerance::isValueInTolerance(requested, available, tolerance),
static_assert(modm::isValueInTolerance(requested, available, tolerance),
"The closest available baudrate exceeds the tolerance of the requested baudrate!");
}

template< double available, double requested, percent_t tolerance >
static void
assertDurationInTolerance()
{
static_assert(modm::isValueInTolerance(requested, available, tolerance),
"The closest available duration exceeds the tolerance of the requested duration!");
}
};

} // namespace modm
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/black_pill_f103/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct SystemClock
static constexpr uint32_t Timer4 = Apb1Timer;

static constexpr uint32_t Usb = Ahb / 1.5;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/black_pill_f411/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct SystemClock
static constexpr uint32_t Timer11 = Apb2Timer;

static constexpr uint32_t Usb = 48_MHz;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/blue_pill_f103/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct SystemClock
static constexpr uint32_t Timer4 = Apb1Timer;

static constexpr uint32_t Usb = Ahb / 1.5;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/devebox_stm32f4xx/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct SystemClock
static constexpr uint32_t Timer12 = Apb1Timer;
static constexpr uint32_t Timer13 = Apb1Timer;
static constexpr uint32_t Timer14 = Apb1Timer;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/devebox_stm32h750vb/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ struct SystemClock
static constexpr uint32_t Timer17 = Apb2Timer;

static constexpr uint32_t Usb = 48_MHz; // From PLL3Q
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/disco_f051r8/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct SystemClock
static constexpr int Usart1 = Frequency;
static constexpr int Usart2 = Frequency;
static constexpr int Spi2 = Frequency;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/disco_f072rb/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct SystemClock
static constexpr uint32_t Timer17 = Apb;

static constexpr uint32_t Usb = 48_MHz;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/disco_f100rb/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct SystemClock
static constexpr uint32_t Timer15 = Apb2Timer;
static constexpr uint32_t Timer16 = Apb2Timer;
static constexpr uint32_t Timer17 = Apb2Timer;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/disco_f303vc/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct SystemClock
static constexpr uint32_t Timer17 = Apb2Timer;

static constexpr uint32_t Usb = Ahb / 1.5;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/disco_f401vc/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct SystemClock
static constexpr uint32_t Timer11 = Apb2Timer;

static constexpr uint32_t Usb = 48_MHz;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/disco_f407vg/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct SystemClock
static constexpr uint32_t Timer14 = Apb1Timer;

static constexpr uint32_t Usb = 48_MHz;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/disco_f429zi/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct SystemClock
static constexpr uint32_t Timer14 = Apb1Timer;

static constexpr uint32_t Usb = 48_MHz;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/disco_f469ni/board.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct SystemClock
static constexpr uint32_t Timer14 = Apb1Timer;

static constexpr uint32_t Usb = 48_MHz;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/disco_f746ng/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct SystemClock
static constexpr uint32_t Timer14 = Apb1Timer;

static constexpr uint32_t Usb = 48_MHz;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/disco_f769ni/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct SystemClock
static constexpr uint32_t Timer12 = Apb1Timer;
static constexpr uint32_t Timer13 = Apb1Timer;
static constexpr uint32_t Timer14 = Apb1Timer;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/disco_l152rc/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct SystemClock
static constexpr uint32_t Timer9 = Apb2Timer;
static constexpr uint32_t Timer10 = Apb2Timer;
static constexpr uint32_t Timer11 = Apb2Timer;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/disco_l476vg/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct SystemClock
static constexpr uint32_t Usart3 = Apb1;
static constexpr uint32_t Usart4 = Apb1;
static constexpr uint32_t Usart5 = Apb1;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f031k6/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct SystemClock
static constexpr uint32_t Timer14 = Apb;
static constexpr uint32_t Timer16 = Apb;
static constexpr uint32_t Timer17 = Apb;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f042k6/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct SystemClock
static constexpr uint32_t Timer14 = Apb;
static constexpr uint32_t Timer16 = Apb;
static constexpr uint32_t Timer17 = Apb;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f072rb/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct SystemClock
static constexpr uint32_t Timer17 = Apb;

static constexpr uint32_t Usb = 48_MHz;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f091rc/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct SystemClock
static constexpr uint32_t Timer17 = Apb;

static constexpr uint32_t Usb = 48_MHz;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f103rb/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct SystemClock
static constexpr uint32_t Timer6 = Apb1Timer;
static constexpr uint32_t Timer7 = Apb1Timer;
static constexpr uint32_t Timer8 = Apb2Timer;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f303k8/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct SystemClock {
static constexpr uint32_t Timer15 = Apb2Timer;
static constexpr uint32_t Timer16 = Apb2Timer;
static constexpr uint32_t Timer17 = Apb2Timer;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f303re/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct SystemClock
static constexpr uint32_t Timer15 = Apb2Timer;
static constexpr uint32_t Timer16 = Apb2Timer;
static constexpr uint32_t Timer17 = Apb2Timer;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f334r8/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct SystemClock
static constexpr uint32_t Timer15 = Apb2Timer;
static constexpr uint32_t Timer16 = Apb2Timer;
static constexpr uint32_t Timer17 = Apb2Timer;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f401re/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct SystemClock
static constexpr uint32_t Timer9 = Apb2Timer;
static constexpr uint32_t Timer10 = Apb2Timer;
static constexpr uint32_t Timer11 = Apb2Timer;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f411re/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct SystemClock
static constexpr uint32_t Timer9 = Apb2Timer;
static constexpr uint32_t Timer10 = Apb2Timer;
static constexpr uint32_t Timer11 = Apb2Timer;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f429zi/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct SystemClock
static constexpr uint32_t Timer14 = Apb1Timer;

static constexpr uint32_t Usb = 48_MHz;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f446re/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct SystemClock
static constexpr uint32_t Timer9 = Apb2Timer;
static constexpr uint32_t Timer10 = Apb2Timer;
static constexpr uint32_t Timer11 = Apb2Timer;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f446ze/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct SystemClock
static constexpr uint32_t Timer11 = Apb2Timer;

static constexpr uint32_t Usb = 48_MHz;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f746zg/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct SystemClock
static constexpr uint32_t Timer12 = Apb1Timer;
static constexpr uint32_t Timer13 = Apb1Timer;
static constexpr uint32_t Timer14 = Apb1Timer;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down
1 change: 1 addition & 0 deletions src/modm/board/nucleo_f767zi/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct SystemClock
static constexpr uint32_t Timer12 = Apb1Timer;
static constexpr uint32_t Timer13 = Apb1Timer;
static constexpr uint32_t Timer14 = Apb1Timer;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
Expand Down