Skip to content

Commit 97e2122

Browse files
committed
[stm32] Use register map query to initialize platform
1 parent de5f0db commit 97e2122

File tree

2 files changed

+13
-62
lines changed

2 files changed

+13
-62
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@ def prepare(module, options):
3939
default="sram")
4040
)
4141

42-
module.depends(":platform:cortex-m")
42+
module.depends(":platform:cortex-m", ":cmsis:device")
4343
return True
4444

4545

4646
def build(env):
4747
target = env[":target"].identifier
4848
env.substitutions = {
4949
"target": target,
50-
"vector_table_location": env.get(":platform:core:vector_table_location", "rom")
50+
"vector_table_location": env.get(":platform:core:vector_table_location", "rom"),
51+
"regs": env.query(":cmsis:device:registers"),
5152
}
5253
env.outbasepath = "modm/src/modm/platform/core"
5354
# startup helper code

src/modm/platform/core/stm32/startup_platform.c.in

Lines changed: 10 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,75 +28,25 @@
2828
void
2929
__modm_initialize_platform(void)
3030
{
31+
3132
// Enable SYSCFG
32-
%% if target.family in ["c0", "g0"]
33-
RCC->APBENR2 |= RCC_APBENR2_SYSCFGEN; __DSB();
34-
%% elif target.family == "f0"
35-
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGCOMPEN; __DSB();
36-
%% elif target.family == "f1"
37-
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; __DSB();
38-
%% elif target.family == "h7"
39-
RCC->APB4ENR |= RCC_APB4ENR_SYSCFGEN; __DSB();
40-
%% elif target.family == "u5"
41-
RCC->APB3ENR |= RCC_APB3ENR_SYSCFGEN; __DSB();
42-
%% else
43-
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; __DSB();
44-
%% endif
33+
{{regs.set("RCC", "APB\d?ENR\d?", "SYSCFG.*?EN|AFIOEN")}}
4534

4635
// Enable power to backup domain
47-
%% if target.family == "f1"
48-
RCC->APB1ENR |= RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN; __DSB();
49-
%% elif target.family in ["f0", "f2", "f3", "f4", "f7", "l0", "l1"]
50-
RCC->APB1ENR |= RCC_APB1ENR_PWREN; __DSB();
51-
%% elif target.family in ["c0", "g0", "u0"]
52-
RCC->APBENR1 |= RCC_APBENR1_PWREN; __DSB();
53-
%% elif target.family in ["g4", "l4", "l5"]
54-
RCC->APB1ENR1 |= RCC_APB1ENR1_PWREN; __DSB();
55-
%% elif target.family == "u5"
56-
RCC->AHB3ENR |= RCC_AHB3ENR_PWREN; __DSB();
57-
%% endif
36+
{{regs.set("RCC", "A[HP]B\d?ENR\d?", "(?:PWR|BKP)EN")}} __DSB();
37+
{{regs.set("PWR", ".*?", "DBP")}}
5838

59-
%% if target.family in ["f0", "f1", "f2", "f3", "f4", "l0", "l1"]
60-
PWR->CR |= PWR_CR_DBP;
61-
%% elif target.family in ["f7", "g0", "g4", "h7", "l4", "l5", "u0", "wb", "wl"]
62-
PWR->CR1 |= PWR_CR1_DBP;
63-
%% elif target.family == "h5"
64-
PWR->DBPCR |= PWR_DBPCR_DBP;
65-
%% elif target.family in ["u5", "wba"]
66-
PWR->DBPR |= PWR_DBPR_DBP;
67-
%% endif
39+
// Enable internal memories
40+
{{regs.set("RCC", "A[HP]B\d?ENR\d?", "(?:BKPS?|DTCM|CCMDATA)RAM\d?EN")}}
6841

69-
%% if target.family == "f4"
70-
// Only the more powerful F4 targets have CCM or Backup SRAM
71-
#ifdef RCC_AHB1ENR_CCMDATARAMEN
72-
// Enable Core Coupled Memory (CCM) and backup SRAM (BKPSRAM)
73-
RCC->AHB1ENR |= RCC_AHB1ENR_CCMDATARAMEN | RCC_AHB1ENR_BKPSRAMEN;
74-
#endif
75-
%% elif target.family == "f7"
42+
%% if regs.search("RCC_DCKCFGR2_.*?")
7643
// Reset from DFU settings to reset values.
7744
RCC->DCKCFGR2 = 0;
78-
// Enable Data Tighly Coupled Memory (DTCM) and backup SRAM (BKPSRAM)
79-
RCC->AHB1ENR |= RCC_AHB1ENR_DTCMRAMEN | RCC_AHB1ENR_BKPSRAMEN;
80-
%% elif target.family == "h7"
81-
// Enable all SRAMs
82-
%% if target.name[0].isnumeric()
83-
RCC->AHB2ENR |= RCC_AHB2ENR_SRAM1EN | RCC_AHB2ENR_SRAM2EN;
84-
%% else
85-
RCC->AHB2ENR |= RCC_AHB2ENR_AHBSRAM1EN | RCC_AHB2ENR_AHBSRAM2EN;
86-
%% endif
87-
RCC->AHB4ENR |= RCC_AHB4ENR_BKPRAMEN;
88-
%% elif target.family in ["g4", "l4", "l5"]
89-
#ifdef PWR_CR2_IOSV
90-
// Enable VDDIO2
91-
PWR->CR2 |= PWR_CR2_IOSV;
92-
#endif
93-
%% elif target.family == "u5"
94-
// Enable power for VDDIO2 and USB
95-
PWR->SVMCR |= PWR_SVMCR_ASV | PWR_SVMCR_IO2SV | PWR_SVMCR_USV;
96-
// Enable Backup SRAM (BKPSRAM)
97-
RCC->AHB1ENR |= RCC_AHB1ENR_BKPSRAMEN;
9845
%% endif
9946

47+
// Enable VDDIO voltages
48+
{{regs.set("PWR|RCC", "CR2|SVMCR", ".*?SV")}}
49+
10050
%% if vector_table_location == "ram"
10151
__DSB();
10252
// Remap SRAM to 0x0 for vector table relocation without VTOR register

0 commit comments

Comments
 (0)