@@ -143,8 +143,8 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
143
143
144
144
// Clear the FPU interrupt because it can prevent us from sleeping.
145
145
if (__get_FPSCR () & ~(0x9f )) {
146
- __set_FPSCR (__get_FPSCR () & ~(0x9f ));
147
- (void )__get_FPSCR ();
146
+ __set_FPSCR (__get_FPSCR () & ~(0x9f ));
147
+ (void )__get_FPSCR ();
148
148
}
149
149
150
150
// Disable RTC interrupts
@@ -161,8 +161,8 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
161
161
NVIC_EnableIRQ (RTC_IRQn );
162
162
163
163
164
- // END ATTEMPT ------------------------------
165
- }
164
+ // END ATTEMPT ------------------------------
165
+ }
166
166
if (mp_hal_is_interrupted ()) {
167
167
return mp_const_none ; // Shouldn't be given to python code because exception handling should kick in.
168
168
}
@@ -186,8 +186,8 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) {
186
186
187
187
// Clear the FPU interrupt because it can prevent us from sleeping.
188
188
if (__get_FPSCR () & ~(0x9f )) {
189
- __set_FPSCR (__get_FPSCR () & ~(0x9f ));
190
- (void )__get_FPSCR ();
189
+ __set_FPSCR (__get_FPSCR () & ~(0x9f ));
190
+ (void )__get_FPSCR ();
191
191
}
192
192
193
193
// PinAlarm (hacky way of checking if time alarm or pin alarm)
@@ -196,41 +196,50 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) {
196
196
NVIC_DisableIRQ (RTC_IRQn );
197
197
// Must disable the RTC before writing to EVCTRL and TMPCTRL
198
198
RTC -> MODE0 .CTRLA .bit .ENABLE = 0 ; // Disable the RTC
199
- while (RTC -> MODE0 .SYNCBUSY .bit .ENABLE ); // Wait for synchronization
199
+ while (RTC -> MODE0 .SYNCBUSY .bit .ENABLE ) { // Wait for synchronization
200
+ ;
201
+ }
200
202
RTC -> MODE0 .CTRLA .bit .SWRST = 1 ; // Software reset the RTC
201
- while (RTC -> MODE0 .SYNCBUSY .bit .SWRST ); // Wait for synchronization
203
+ while (RTC -> MODE0 .SYNCBUSY .bit .SWRST ) { // Wait for synchronization
204
+ ;
205
+ }
202
206
RTC -> MODE0 .CTRLA .reg = RTC_MODE0_CTRLA_PRESCALER_DIV1024 | // Set prescaler to 1024
203
- RTC_MODE0_CTRLA_MODE_COUNT32 ; // Set RTC to mode 0, 32-bit timer
207
+ RTC_MODE0_CTRLA_MODE_COUNT32 ; // Set RTC to mode 0, 32-bit timer
204
208
205
209
// TODO: map requested pin to limited selection of TAMPER pins
206
210
RTC -> MODE0 .TAMPCTRL .bit .DEBNC2 = 1 ; // Edge triggered when INn is stable for 4 CLK_RTC_DEB periods
207
211
RTC -> MODE0 .TAMPCTRL .bit .TAMLVL2 = 1 ; // rising edge
208
- //PA02 = IN2
212
+ // PA02 = IN2
209
213
RTC -> MODE0 .TAMPCTRL .bit .IN2ACT = 1 ; // WAKE on IN2 (doesn't save timestamp)
210
214
211
215
// Enable interrupts
212
216
NVIC_SetPriority (RTC_IRQn , 0 );
213
217
NVIC_EnableIRQ (RTC_IRQn );
214
218
// Set interrupts for TAMPER or overflow
215
219
RTC -> MODE0 .INTENSET .reg = RTC_MODE0_INTENSET_TAMPER ;
216
- // TimeAlarm
217
220
} else {
221
+ // TimeAlarm
218
222
// Retrieve COMP1 value before resetting RTC
219
- // Disable interrupts
220
223
NVIC_DisableIRQ (RTC_IRQn );
221
224
222
225
// Must disable the RTC before writing to EVCTRL and TMPCTRL
223
226
RTC -> MODE0 .CTRLA .bit .ENABLE = 0 ; // Disable the RTC
224
- while (RTC -> MODE0 .SYNCBUSY .bit .ENABLE ); // Wait for synchronization
227
+ while (RTC -> MODE0 .SYNCBUSY .bit .ENABLE ) { // Wait for synchronization
228
+ ;
229
+ }
225
230
226
231
RTC -> MODE0 .CTRLA .bit .SWRST = 1 ; // Software reset the RTC
227
- while (RTC -> MODE0 .SYNCBUSY .bit .SWRST ); // Wait for synchronization
232
+ while (RTC -> MODE0 .SYNCBUSY .bit .SWRST ) { // Wait for synchronization
233
+ ;
234
+ }
228
235
229
236
RTC -> MODE0 .CTRLA .reg = RTC_MODE0_CTRLA_PRESCALER_DIV1024 | // Set prescaler to 1024
230
- RTC_MODE0_CTRLA_MODE_COUNT32 ; // Set RTC to mode 0, 32-bit timer
237
+ RTC_MODE0_CTRLA_MODE_COUNT32 ; // Set RTC to mode 0, 32-bit timer
231
238
232
239
RTC -> MODE0 .COMP [1 ].reg = (_target /1024 ) * 32 ;
233
- while (RTC -> MODE0 .SYNCBUSY .reg );
240
+ while (RTC -> MODE0 .SYNCBUSY .reg ) {
241
+ ;
242
+ }
234
243
235
244
// Enable interrupts
236
245
NVIC_SetPriority (RTC_IRQn , 0 );
@@ -241,9 +250,13 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) {
241
250
// Set-up Deep Sleep Mode
242
251
// RAM retention
243
252
PM -> BKUPCFG .reg = PM_BKUPCFG_BRAMCFG (0x2 ); // No RAM retention 0x2 partial:0x1
244
- while (PM -> BKUPCFG .bit .BRAMCFG != 0x2 ); // Wait for synchronization
253
+ while (PM -> BKUPCFG .bit .BRAMCFG != 0x2 ) { // Wait for synchronization
254
+ ;
255
+ }
245
256
PM -> SLEEPCFG .reg = PM_SLEEPCFG_SLEEPMODE_BACKUP ;
246
- while (PM -> SLEEPCFG .bit .SLEEPMODE != PM_SLEEPCFG_SLEEPMODE_BACKUP_Val );
257
+ while (PM -> SLEEPCFG .bit .SLEEPMODE != PM_SLEEPCFG_SLEEPMODE_BACKUP_Val ) {
258
+ ;
259
+ }
247
260
248
261
RTC -> MODE0 .CTRLA .bit .ENABLE = 1 ; // Enable the RTC
249
262
while (RTC -> MODE0 .SYNCBUSY .bit .ENABLE ); // Wait for synchronization
0 commit comments