@@ -124,6 +124,9 @@ static void mp_machine_idle(void) {
124
124
static void alarm_sleep_callback (uint alarm_id ) {
125
125
}
126
126
127
+ // Set this to 1 to enable some debug of the interrupt that woke the device
128
+ #define DEBUG_LIGHTSLEEP 0
129
+
127
130
static void mp_machine_lightsleep (size_t n_args ,const mp_obj_t * args ) {
128
131
mp_int_t delay_ms = 0 ;
129
132
bool use_timer_alarm = false;
@@ -193,6 +196,14 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
193
196
// Disable ROSC.
194
197
rosc_hw -> ctrl = ROSC_CTRL_ENABLE_VALUE_DISABLE <<ROSC_CTRL_ENABLE_LSB ;
195
198
199
+ #if DEBUG_LIGHTSLEEP
200
+ #if PICO_RP2040
201
+ uint32_t pending_intr = 0 ;
202
+ #else
203
+ uint32_t pending_intr [2 ]= {0 };
204
+ #endif
205
+ #endif
206
+
196
207
bool alarm_armed = false;
197
208
if (n_args == 0 ) {
198
209
#if MICROPY_PY_NETWORK_CYW43
@@ -248,6 +259,15 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
248
259
// Go into low-power mode.
249
260
if (alarm_armed ) {
250
261
__wfi ();
262
+
263
+ #if DEBUG_LIGHTSLEEP
264
+ #if PICO_RP2040
265
+ pending_intr = nvic_hw -> ispr ;
266
+ #else
267
+ pending_intr [0 ]= nvic_hw -> ispr [0 ];
268
+ pending_intr [1 ]= nvic_hw -> ispr [1 ];
269
+ #endif
270
+ #endif
251
271
}
252
272
clocks_hw -> sleep_en0 = save_sleep_en0 ;
253
273
clocks_hw -> sleep_en1 = save_sleep_en1 ;
@@ -270,6 +290,19 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
270
290
}
271
291
hardware_alarm_set_callback (MICROPY_HW_LIGHTSLEEP_ALARM_NUM ,NULL );
272
292
hardware_alarm_unclaim (MICROPY_HW_LIGHTSLEEP_ALARM_NUM );
293
+
294
+ #if DEBUG_LIGHTSLEEP
295
+ // Check irq.h for the list of IRQ's
296
+ // for rp2040 00000042: TIMER_IRQ_1 woke the device as expected
297
+ // 00000020: USBCTRL_IRQ woke the device (probably early)
298
+ // For rp2350 00000000:00000002: TIMER0_IRQ_1 woke the device as expected
299
+ // 00000000:00004000: USBCTRL_IRQ woke the device (probably early)
300
+ #if PICO_RP2040
301
+ mp_printf (MP_PYTHON_PRINTER ,"lightsleep: pending_intr=%08lx\n" ,pending_intr );
302
+ #else
303
+ mp_printf (MP_PYTHON_PRINTER ,"lightsleep: pending_intr=%08lx:%08lx\n" ,pending_intr [1 ],pending_intr [0 ]);
304
+ #endif
305
+ #endif
273
306
}
274
307
}
275
308