Skip to content

Commit

Permalink
[stm32] add advanced initialize on iwdg
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Costa authored and salkinium committed Mar 11, 2024
1 parent 1a89fbe commit 9496060
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/modm/platform/iwdg/stm32/iwdg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ class Iwdg : public ::modm::PeripheralDriver
};

public:
static inline void
initialize(Prescaler prescaler, uint16_t reload)
{
writeKey(writeCommand);
IWDG->PR = uint32_t(prescaler);
IWDG->RLR = reload;
writeKey(0); // disable access to PR and RLR registers
}

template< class SystemClock, milliseconds_t timeout, percent_t tolerance=pct(1) >
static void
initialize()
Expand All @@ -55,10 +64,9 @@ class Iwdg : public ::modm::PeripheralDriver
SystemClock::Iwdg, frequency, 1ul << 12, 256, 4);
assertDurationInTolerance< 1.0 / result.frequency, 1.0 / frequency, tolerance >();

configure(Prescaler(result.index), result.counter - 1);
initialize(Prescaler(result.index), result.counter - 1);
}


static inline void
enable()
{
Expand All @@ -78,15 +86,6 @@ class Iwdg : public ::modm::PeripheralDriver
}

private:
static inline void
configure(Prescaler prescaler, uint16_t reload)
{
writeKey(writeCommand);
IWDG->PR = uint32_t(prescaler);
IWDG->RLR = reload;
writeKey(0); // disable access to PR and RLR registers
}

static inline void
writeKey(uint16_t key)
{
Expand Down

0 comments on commit 9496060

Please sign in to comment.