@@ -147,9 +147,10 @@ __attribute__((used, naked)) void Reset_Handler(void) {
147
147
__enable_irq ();
148
148
main ();
149
149
}
150
-
151
150
#endif //end H7 specific code
152
151
152
+ // Low power clock variables
153
+ static volatile uint32_t systick_ms ;
153
154
static RTC_HandleTypeDef _hrtc ;
154
155
155
156
#if BOARD_HAS_LOW_SPEED_CRYSTAL
@@ -159,7 +160,7 @@ static uint32_t rtc_clock_frequency = LSI_VALUE;
159
160
#endif
160
161
161
162
safe_mode_t port_init (void ) {
162
- HAL_Init ();
163
+ HAL_Init (); // Turns on SysTick
163
164
__HAL_RCC_SYSCFG_CLK_ENABLE ();
164
165
165
166
#if (CPY_STM32F4 )
@@ -182,13 +183,38 @@ safe_mode_t port_init(void) {
182
183
HAL_RTC_Init (& _hrtc );
183
184
HAL_NVIC_EnableIRQ (RTC_Alarm_IRQn );
184
185
186
+ // Turn off SysTick
187
+ SysTick -> CTRL = 0 ;
188
+
185
189
return NO_SAFE_MODE ;
186
190
}
187
191
192
+ void HAL_Delay (uint32_t delay_ms ) {
193
+ if (SysTick -> CTRL != 0 ) {
194
+ // SysTick is on, so use it
195
+ uint32_t tickstart = systick_ms ;
196
+ while (systick_ms - tickstart < delay_ms ) {
197
+ }
198
+ } else {
199
+ mp_hal_delay_ms (delay_ms );
200
+ }
201
+ }
202
+
203
+ uint32_t HAL_GetTick () {
204
+ if (SysTick -> CTRL != 0 ) {
205
+ return systick_ms ;
206
+ } else {
207
+ uint8_t subticks ;
208
+ uint32_t result = (uint32_t )port_get_raw_ticks (& subticks );
209
+ return result ;
210
+ }
211
+ }
212
+
213
+
188
214
void SysTick_Handler (void ) {
215
+ systick_ms += 1 ;
189
216
// Read the CTRL register to clear the SysTick interrupt.
190
217
SysTick -> CTRL ;
191
- HAL_IncTick ();
192
218
}
193
219
194
220
void reset_port (void ) {
0 commit comments