Skip to content

Commit 12413e9

Browse files
committed
stm32/powerctrlboot: Fix config of systick IRQ priority on F0/L0/WB MCU.
Prior to this commit the systick IRQ priority was set at lowest priority on F0/L0/WB MCUs, because it was left at the default and never configured. This commit ensures the priority is configured and sets it to the highest priority.
1 parent 8f9e2e3 commit 12413e9

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

ports/stm32/irq.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ MP_DECLARE_CONST_FUN_OBJ_0(pyb_irq_stats_obj);
120120

121121
#if __CORTEX_M == 0
122122

123-
//#def IRQ_PRI_SYSTICK 0
123+
#define IRQ_PRI_SYSTICK 0
124124
#define IRQ_PRI_UART 1
125125
#define IRQ_PRI_SDIO 1
126126
#define IRQ_PRI_DMA 1
@@ -136,7 +136,7 @@ MP_DECLARE_CONST_FUN_OBJ_0(pyb_irq_stats_obj);
136136

137137
#else
138138

139-
//#def IRQ_PRI_SYSTICK NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, 0, 0)
139+
#define IRQ_PRI_SYSTICK NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, 0, 0)
140140

141141
// The UARTs have no FIFOs, so if they don't get serviced quickly then characters
142142
// get dropped. The handling for each character only consumes about 0.5 usec

ports/stm32/powerctrlboot.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
#include "py/mphal.h"
2828
#include "powerctrl.h"
2929

30+
static inline void powerctrl_config_systick(void) {
31+
// Configure SYSTICK to run at 1kHz (1ms interval)
32+
SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
33+
SysTick_Config(HAL_RCC_GetHCLKFreq() / 1000);
34+
NVIC_SetPriority(SysTick_IRQn, IRQ_PRI_SYSTICK);
35+
}
36+
3037
#if defined(STM32F0)
3138

3239
void SystemClock_Config(void) {
@@ -88,9 +95,7 @@ void SystemClock_Config(void) {
8895
}
8996

9097
SystemCoreClockUpdate();
91-
92-
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
93-
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
98+
powerctrl_config_systick();
9499
}
95100

96101
#elif defined(STM32L0)
@@ -122,9 +127,7 @@ void SystemClock_Config(void) {
122127
}
123128

124129
SystemCoreClockUpdate();
125-
126-
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
127-
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
130+
powerctrl_config_systick();
128131

129132
#if MICROPY_HW_ENABLE_RNG || MICROPY_HW_ENABLE_USB
130133
// Enable the 48MHz internal oscillator
@@ -189,9 +192,7 @@ void SystemClock_Config(void) {
189192
RCC->CCIPR = 2 << RCC_CCIPR_CLK48SEL_Pos;
190193

191194
SystemCoreClockUpdate();
192-
193-
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
194-
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
195+
powerctrl_config_systick();
195196
}
196197

197198
#endif

0 commit comments

Comments
 (0)