File tree Expand file tree Collapse file tree
ports/raspberrypi/supervisor Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77#include "lib/tinyusb/src/device/usbd.h"
88#include "supervisor/background_callback.h"
9+ #include "supervisor/linker.h"
910#include "supervisor/usb.h"
1011#include "hardware/irq.h"
12+ #include "hardware/timer.h"
1113#include "pico/platform.h"
1214#include "hardware/regs/intctrl.h"
1315
1416void init_usb_hardware (void ) {
1517}
1618
19+ // Override the shared implementation with one that is safe to call from core1.
20+ // TinyUSB's tuh_task_event_ready() calls this, and usb_host polls
21+ // tuh_task_event_ready() from core1's PIO-USB frame loop (see
22+ // common-hal/usb_host/Port.c). tuh_task_event_ready() is deliberately placed in
23+ // RAM by link-rp2*.ld, and everything it calls must be RAM-resident too: on
24+ // RP2350, core1 sets an MPU region that makes flash execute-never, and on
25+ // RP2040 flash may be unavailable while core0 writes to it. time_us_32() is a
26+ // static-inline register read. >>10 yields ~1.024 ms units rather than exact
27+ // milliseconds, which is fine because TinyUSB only uses this API for relative
28+ // delay arithmetic and every use goes through this same function.
29+ uint32_t PLACE_IN_ITCM (tusb_time_millis_api )(void ) {
30+ return time_us_32 () >> 10 ;
31+ }
32+
1733static void _usb_irq_wrapper (void ) {
1834 usb_irq_handler (0 );
1935}
Original file line number Diff line number Diff line change @@ -184,7 +184,10 @@ void usb_background(void) {
184184 }
185185}
186186
187- uint32_t tusb_time_millis_api (void ) {
187+ // Ports may override this with a RAM-resident version when TinyUSB code that
188+ // calls it must not execute from flash (e.g. raspberrypi polls
189+ // tuh_task_event_ready(), which calls this, from core1).
190+ MP_WEAK uint32_t tusb_time_millis_api (void ) {
188191 return supervisor_ticks_ms32 ();
189192}
190193
You can’t perform that action at this time.
0 commit comments