Skip to content

Commit

Permalink
adequate IWDG driver
Browse files Browse the repository at this point in the history
  • Loading branch information
victorandrehc committed May 3, 2023
1 parent 187ad38 commit b1b96b6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/nucleo_f072rb/independend_watchdog/project.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<library>
<extends>modm:nucleo-f072rb</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f072rb/idwg_blink</option>
<option name="modm:build:build.path">../../../build/nucleo_f072rb/independend_watchdog</option>
</options>
<modules>
<module>modm:build:scons</module>
Expand Down
7 changes: 4 additions & 3 deletions src/modm/platform/iwdg/stm32/iwdg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@
void
Iwdg::initialize(Iwdg::Prescaler prescaler, uint32_t reload)
{
writeKey(_write);
writeKey(writeCommand);
IWDG->PR = (IWDG->PR & ~static_cast<uint32_t>(Iwdg::Prescaler::All)) |
static_cast<uint32_t>(prescaler);
IWDG->RLR = (IWDG->RLR & ~IWDG_RLR_RL) | (reload << IWDG_RLR_RL_Pos);
writeKey(0); // disable access to PR and RLR registers
}

void
Iwdg::enable()
{
writeKey(_enable);
writeKey(enableCommand);
}

void
Iwdg::trigger()
{
writeKey(_reload);
writeKey(reloadCommand);
}

void
Expand Down
12 changes: 7 additions & 5 deletions src/modm/platform/iwdg/stm32/iwdg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
class Iwdg
{
public:
enum class Prescaler : uint32_t
enum class
Prescaler : uint32_t
{
Div4 = 0,
Div8 = IWDG_PR_PR_0,
Expand All @@ -27,7 +28,8 @@ class Iwdg
All = IWDG_PR_PR_2 | IWDG_PR_PR_1 | IWDG_PR_PR_0,
};

enum class Status : uint32_t
enum class
Status : uint32_t
{
None = 0,
Prescaler = IWDG_SR_PVU,
Expand All @@ -45,9 +47,9 @@ class Iwdg
getStatus();

private:
static const auto _reload = static_cast<uint32_t>(0xAAAA);
static const auto _write = static_cast<uint32_t>(0x5555);
static const auto _enable = static_cast<uint32_t>(0xCCCC);
static constexpr uint32_t reloadCommand = 0xAAAA;
static constexpr uint32_t writeCommand = 0x5555;
static constexpr uint32_t enableCommand = 0xCCCC;

static void
writeKey(uint32_t key);
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/iwdg/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def prepare(module, options):
if target["family"] in ["h7"]:
# STM32h75 is not yet supported with any IWDG implementation im modm
return False
return options[":target"].identifier.platform == "stm32"
return device.has_driver("iwdg:stm32")

def build(env):
env.outbasepath = "modm/src/modm/platform/iwdg"
Expand Down

0 comments on commit b1b96b6

Please sign in to comment.