Skip to content

Commit

Permalink
[stm32] Simplify IWDG driver by inlining functions
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Jan 28, 2024
1 parent c47088f commit 43fed11
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 67 deletions.
47 changes: 0 additions & 47 deletions src/modm/platform/iwdg/stm32/iwdg.cpp

This file was deleted.

61 changes: 45 additions & 16 deletions src/modm/platform/iwdg/stm32/iwdg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
#pragma once
#include "../device.hpp"


namespace modm::platform
{

/// @ingroup modm_platform_iwdg
class Iwdg
{
public:
enum class
Prescaler : uint32_t
Prescaler : uint8_t
{
Div4 = 0,
Div8 = IWDG_PR_PR_0,
Expand All @@ -29,28 +34,52 @@ class Iwdg
};

enum class
Status : uint32_t
Status : uint8_t
{
None = 0,
Prescaler = IWDG_SR_PVU,
Reload = IWDG_SR_RVU,
All = IWDG_SR_PVU | IWDG_SR_RVU,
};

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

static inline void
enable()
{
writeKey(enableCommand);
}

static inline void
trigger()
{
writeKey(reloadCommand);
}

static inline Status
getStatus()
{
return Status(IWDG->SR);
}

private:
static constexpr uint32_t reloadCommand = 0xAAAA;
static constexpr uint32_t writeCommand = 0x5555;
static constexpr uint32_t enableCommand = 0xCCCC;
static constexpr uint16_t reloadCommand = 0xAAAA;
static constexpr uint16_t writeCommand = 0x5555;
static constexpr uint16_t enableCommand = 0xCCCC;

static inline void
writeKey(uint16_t key)
{
IWDG->KR = key;
}
};

static void
writeKey(uint32_t key);
};
}
10 changes: 6 additions & 4 deletions src/modm/platform/iwdg/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ def init(module):
module.name = ":platform:iwdg"
module.description = "Independent watchdog"


def prepare(module, options):
device = options[":target"]
target = device.identifier
if target["family"] in ["h7"]:
# STM32H7 is not yet supported with any IWDG implementation im modm
# STM32H7 is not yet supported with any IWDG implementation
if device.identifier.family in ["h7"]:
return False

module.depends(":cmsis:device")
return device.has_driver("iwdg:stm32")


def build(env):
env.outbasepath = "modm/src/modm/platform/iwdg"
env.copy("iwdg.hpp")
env.copy("iwdg.cpp")

0 comments on commit 43fed11

Please sign in to comment.