Skip to content

Commit f647254

Browse files
committed
[stm32] Simplify IWDG driver by inlining functions
1 parent fdd2a9c commit f647254

File tree

3 files changed

+51
-67
lines changed

3 files changed

+51
-67
lines changed

src/modm/platform/iwdg/stm32/iwdg.cpp

-47
This file was deleted.

src/modm/platform/iwdg/stm32/iwdg.hpp

+45-16
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
#pragma once
1313
#include "../device.hpp"
1414

15+
16+
namespace modm::platform
17+
{
18+
19+
/// @ingroup modm_platform_iwdg
1520
class Iwdg
1621
{
1722
public:
1823
enum class
19-
Prescaler : uint32_t
24+
Prescaler : uint8_t
2025
{
2126
Div4 = 0,
2227
Div8 = IWDG_PR_PR_0,
@@ -29,28 +34,52 @@ class Iwdg
2934
};
3035

3136
enum class
32-
Status : uint32_t
37+
Status : uint8_t
3338
{
3439
None = 0,
3540
Prescaler = IWDG_SR_PVU,
3641
Reload = IWDG_SR_RVU,
3742
All = IWDG_SR_PVU | IWDG_SR_RVU,
3843
};
3944

40-
static void
41-
initialize(Prescaler prescaler, uint32_t reload);
42-
static void
43-
enable();
44-
static void
45-
trigger();
46-
static Status
47-
getStatus();
45+
public:
46+
static inline void
47+
initialize(Prescaler prescaler, uint32_t reload)
48+
{
49+
writeKey(writeCommand);
50+
IWDG->PR = uint32_t(prescaler);
51+
IWDG->RLR = reload;
52+
writeKey(0); // disable access to PR and RLR registers
53+
}
54+
55+
static inline void
56+
enable()
57+
{
58+
writeKey(enableCommand);
59+
}
60+
61+
static inline void
62+
trigger()
63+
{
64+
writeKey(reloadCommand);
65+
}
66+
67+
static inline Status
68+
getStatus()
69+
{
70+
return Status(IWDG->SR);
71+
}
4872

4973
private:
50-
static constexpr uint32_t reloadCommand = 0xAAAA;
51-
static constexpr uint32_t writeCommand = 0x5555;
52-
static constexpr uint32_t enableCommand = 0xCCCC;
74+
static constexpr uint16_t reloadCommand = 0xAAAA;
75+
static constexpr uint16_t writeCommand = 0x5555;
76+
static constexpr uint16_t enableCommand = 0xCCCC;
77+
78+
static inline void
79+
writeKey(uint16_t key)
80+
{
81+
IWDG->KR = key;
82+
}
83+
};
5384

54-
static void
55-
writeKey(uint32_t key);
56-
};
85+
}

src/modm/platform/iwdg/stm32/module.lb

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ def init(module):
1414
module.name = ":platform:iwdg"
1515
module.description = "Independent watchdog"
1616

17+
1718
def prepare(module, options):
1819
device = options[":target"]
19-
target = device.identifier
20-
if target["family"] in ["h7"]:
21-
# STM32H7 is not yet supported with any IWDG implementation im modm
20+
# STM32H7 is not yet supported with any IWDG implementation
21+
if device.identifier.family in ["h7"]:
2222
return False
23+
24+
module.depends(":cmsis:device")
2325
return device.has_driver("iwdg:stm32")
2426

27+
2528
def build(env):
2629
env.outbasepath = "modm/src/modm/platform/iwdg"
2730
env.copy("iwdg.hpp")
28-
env.copy("iwdg.cpp")

0 commit comments

Comments
 (0)