diff --git a/cores/rp2040/Bootsel.cpp b/cores/rp2040/Bootsel.cpp index 63a2717..a9e5959 100644 --- a/cores/rp2040/Bootsel.cpp +++ b/cores/rp2040/Bootsel.cpp @@ -26,7 +26,8 @@ static bool __no_inline_not_in_flash_func(get_bootsel_button)() { // Must disable interrupts, as interrupt handlers may be in flash, and we // are about to temporarily disable flash access! - uint32_t flags = save_and_disable_interrupts(); + noInterrupts(); + rp2040.idleOtherCore(); // Set chip select to Hi-Z hw_write_masked(&ioqspi_hw->io[CS_PIN_INDEX].ctrl, @@ -46,7 +47,8 @@ static bool __no_inline_not_in_flash_func(get_bootsel_button)() { GPIO_OVERRIDE_NORMAL << IO_QSPI_GPIO_QSPI_SS_CTRL_OEOVER_LSB, IO_QSPI_GPIO_QSPI_SS_CTRL_OEOVER_BITS); - restore_interrupts(flags); + interrupts(); + rp2040.resumeOtherCore(); return button_state; } diff --git a/cores/rp2040/RP2040.h b/cores/rp2040/RP2040.h index a958777..3d79338 100644 --- a/cores/rp2040/RP2040.h +++ b/cores/rp2040/RP2040.h @@ -23,6 +23,7 @@ #include #include #include +#include class _MFIFO { public: @@ -132,7 +133,6 @@ public: extern RP2040 rp2040; // Wrapper class for PIO programs, abstracting common operations out -// TODO - Make dualcore safe // TODO - Add unload/destructor class PIOProgram { public: @@ -140,6 +140,8 @@ public: // Possibly load into a PIO and allocate a SM bool prepare(PIO *pio, int *sm, int *offset) { + extern mutex_t _pioMutex; + CoreMutex m(&_pioMutex); // Is there an open slot to run in, first? if (!_findFreeSM(pio, sm)) return false; // Is it loaded on that PIO? diff --git a/cores/rp2040/main.cpp b/cores/rp2040/main.cpp index 4b34dab..27fd1a2 100644 --- a/cores/rp2040/main.cpp +++ b/cores/rp2040/main.cpp @@ -26,6 +26,9 @@ RP2040 rp2040; volatile bool _MFIFO::_otherIdled = false; +auto_init_mutex(_pioMutex); + + extern void setup(); extern void loop();