summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/rp2/modmachine.c4
-rw-r--r--tests/ports/rp2/rp2_lightsleep.py31
-rw-r--r--tests/ports/rp2/rp2_lightsleep.py.exp2
3 files changed, 35 insertions, 2 deletions
diff --git a/ports/rp2/modmachine.c b/ports/rp2/modmachine.c
index 4eebb3d16..9cc15080c 100644
--- a/ports/rp2/modmachine.c
+++ b/ports/rp2/modmachine.c
@@ -31,7 +31,7 @@
#include "mp_usbd.h"
#include "modmachine.h"
#include "uart.h"
-#include "hardware/clocks.h"
+#include "clocks_extra.h"
#include "hardware/pll.h"
#include "hardware/structs/rosc.h"
#include "hardware/structs/scb.h"
@@ -213,7 +213,7 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
rosc_hw->ctrl = ROSC_CTRL_ENABLE_VALUE_ENABLE << ROSC_CTRL_ENABLE_LSB;
// Bring back all clocks.
- clocks_init();
+ clocks_init_optional_usb(disable_usb);
MICROPY_END_ATOMIC_SECTION(my_interrupts);
}
diff --git a/tests/ports/rp2/rp2_lightsleep.py b/tests/ports/rp2/rp2_lightsleep.py
new file mode 100644
index 000000000..3587def68
--- /dev/null
+++ b/tests/ports/rp2/rp2_lightsleep.py
@@ -0,0 +1,31 @@
+# This test is mostly intended for ensuring USB serial stays stable over
+# lightsleep, but can double as a general lightsleep test.
+#
+# In theory this should run on any port, but native USB REPL doesn't currently
+# recover automatically on all ports. On pyboard and ESP32-S3 the host needs to
+# send something to the port before it responds again. Possibly the same for other
+# ports with native USB.
+#
+# A range of sleep periods (1 to 512ms) are tested. The total nominal sleep time
+# is 10.23 seconds, but on most ports this will finish much earlier as interrupts
+# happen before each timeout expires.
+try:
+ from machine import lightsleep, Pin
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+from sys import stdout, platform
+
+try:
+ led = Pin(Pin.board.LED, Pin.OUT)
+except AttributeError:
+ led = None
+
+for n in range(100):
+ if led:
+ led.toggle()
+ stdout.write(chr(ord("a") + (n % 26)))
+ lightsleep(2 ** (n % 10))
+
+print("\nDONE")
diff --git a/tests/ports/rp2/rp2_lightsleep.py.exp b/tests/ports/rp2/rp2_lightsleep.py.exp
new file mode 100644
index 000000000..81d1c231c
--- /dev/null
+++ b/tests/ports/rp2/rp2_lightsleep.py.exp
@@ -0,0 +1,2 @@
+abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv
+DONE