@@ -162,6 +162,9 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
162
162
}
163
163
164
164
clock_stop (clk_adc );
165
+ #if PICO_RP2350
166
+ clock_stop (clk_hstx );
167
+ #endif
165
168
166
169
// CLK_REF = XOSC
167
170
clock_configure (clk_ref ,CLOCKS_CLK_REF_CTRL_SRC_VALUE_XOSC_CLKSRC ,0 ,xosc_hz ,xosc_hz );
@@ -170,7 +173,9 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
170
173
clock_configure (clk_sys ,CLOCKS_CLK_SYS_CTRL_SRC_VALUE_CLK_REF ,0 ,xosc_hz ,xosc_hz );
171
174
172
175
// CLK_RTC = XOSC / 256
176
+ #if PICO_RP2040
173
177
clock_configure (clk_rtc ,0 ,CLOCKS_CLK_RTC_CTRL_AUXSRC_VALUE_XOSC_CLKSRC ,xosc_hz ,xosc_hz /256 );
178
+ #endif
174
179
175
180
// CLK_PERI = CLK_SYS
176
181
clock_configure (clk_peri ,0 ,CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLK_SYS ,xosc_hz ,xosc_hz );
@@ -190,38 +195,63 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
190
195
#endif
191
196
xosc_dormant ();
192
197
}else {
193
- uint32_t sleep_en0 = clocks_hw -> sleep_en0 ;
194
- uint32_t sleep_en1 = clocks_hw -> sleep_en1 ;
195
198
bool timer3_enabled = irq_is_enabled (3 );
196
199
197
- clocks_hw -> sleep_en0 = CLOCKS_SLEEP_EN0_CLK_RTC_RTC_BITS ;
200
+ const uint32_t alarm_num = 3 ;
201
+ const uint32_t irq_num = TIMER_ALARM_IRQ_NUM (timer_hw ,alarm_num );
198
202
if (use_timer_alarm ) {
199
203
// Make sure ALARM3/IRQ3 is enabled on _this_ core
200
- timer_hw -> inte |=1 <<3 ;
201
204
if (!timer3_enabled ) {
202
- irq_set_enabled (3 , true);
205
+ irq_set_enabled (irq_num , true);
203
206
}
207
+ hw_set_bits (& timer_hw -> inte ,1u <<alarm_num );
204
208
// Use timer alarm to wake.
209
+ clocks_hw -> sleep_en0 = 0x0 ;
210
+ #if PICO_RP2040
205
211
clocks_hw -> sleep_en1 = CLOCKS_SLEEP_EN1_CLK_SYS_TIMER_BITS ;
206
- timer_hw -> alarm [3 ]= timer_hw -> timerawl + delay_ms * 1000 ;
212
+ #elif PICO_RP2350
213
+ clocks_hw -> sleep_en1 = CLOCKS_SLEEP_EN1_CLK_REF_TICKS_BITS |CLOCKS_SLEEP_EN1_CLK_SYS_TIMER0_BITS ;
214
+ #else
215
+ #error Unknown processor
216
+ #endif
217
+ timer_hw -> intr = 1u <<alarm_num ;// clear any IRQ
218
+ timer_hw -> alarm [alarm_num ]= timer_hw -> timerawl + delay_ms * 1000 ;
207
219
}else {
208
220
// TODO: Use RTC alarm to wake.
209
- clocks_hw -> sleep_en1 = 0 ;
221
+ clocks_hw -> sleep_en0 = 0x0 ;
222
+ clocks_hw -> sleep_en1 = 0x0 ;
210
223
}
211
224
212
225
if (!disable_usb ) {
213
226
clocks_hw -> sleep_en0 |=CLOCKS_SLEEP_EN0_CLK_SYS_PLL_USB_BITS ;
227
+ #if PICO_RP2040
214
228
clocks_hw -> sleep_en1 |=CLOCKS_SLEEP_EN1_CLK_USB_USBCTRL_BITS ;
229
+ #elif PICO_RP2350
230
+ clocks_hw -> sleep_en1 |=CLOCKS_SLEEP_EN1_CLK_SYS_USBCTRL_BITS ;
231
+ #else
232
+ #error Unknown processor
233
+ #endif
215
234
}
216
235
236
+ #if PICO_ARM
237
+ // Configure SLEEPDEEP bits on Cortex-M CPUs.
238
+ #if PICO_RP2040
217
239
scb_hw -> scr |=M0PLUS_SCR_SLEEPDEEP_BITS ;
240
+ #elif PICO_RP2350
241
+ scb_hw -> scr |=M33_SCR_SLEEPDEEP_BITS ;
242
+ #else
243
+ #error Unknown processor
244
+ #endif
245
+ #endif
246
+
247
+ // Go into low-power mode.
218
248
__wfi ();
219
- scb_hw -> scr &= ~ M0PLUS_SCR_SLEEPDEEP_BITS ;
249
+
220
250
if (!timer3_enabled ) {
221
- irq_set_enabled (3 , false);
251
+ irq_set_enabled (irq_num , false);
222
252
}
223
- clocks_hw -> sleep_en0 = sleep_en0 ;
224
- clocks_hw -> sleep_en1 = sleep_en1 ;
253
+ clocks_hw -> sleep_en0 |= ~( 0u ) ;
254
+ clocks_hw -> sleep_en1 |= ~( 0u ) ;
225
255
}
226
256
227
257
// Enable ROSC.