Skip to content

Commit 6374408

Browse files
committed
Changed reset_rp2pio_statemachine to clean up any PIO interrupts.
1 parent f8eb5bc commit 6374408

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

ports/raspberrypi/common-hal/board/__init__.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,3 @@
3434

3535
// Pins aren't actually defined here. They are in the board specific directory
3636
// such as boards/arduino_zero/pins.c.
37-
38-
// routine to reset both pios
39-
void board_reset_pio() {
40-
for ( uint8_t sm = 0; sm < 4; sm++) {
41-
pio_sm_init (pio0, sm, 0, NULL);
42-
pio_sm_init (pio1, sm, 0, NULL);
43-
}
44-
pio_clear_instruction_memory(pio0);
45-
pio_clear_instruction_memory(pio1);
46-
}

ports/raspberrypi/common-hal/rp2pio/StateMachine.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "src/rp2_common/hardware_dma/include/hardware/dma.h"
3535
#include "src/rp2_common/hardware_pio/include/hardware/pio_instructions.h"
3636
#include "src/rp2040/hardware_structs/include/hardware/structs/iobank0.h"
37+
#include "src/rp2_common/hardware_irq/include/hardware/irq.h"
3738

3839
#include "lib/utils/interrupt_char.h"
3940
#include "py/obj.h"
@@ -101,6 +102,13 @@ void reset_rp2pio_statemachine(void) {
101102
_reset_statemachine(pio, j, false);
102103
}
103104
}
105+
for (uint8_t irq=PIO0_IRQ_0; irq <= PIO1_IRQ_1; irq++) {
106+
irq_handler_t int_handler = irq_get_exclusive_handler(irq);
107+
if (int_handler > 0) {
108+
irq_set_enabled (irq, false);
109+
irq_remove_handler(irq,int_handler);
110+
}
111+
}
104112
}
105113

106114
STATIC uint32_t _check_pins_free(const mcu_pin_obj_t * first_pin, uint8_t pin_count, bool exclusive_pin_use) {

shared-module/board/__init__.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
#include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h"
4646
#endif
4747

48+
#if CIRCUITPY_RP2PIO
49+
#include "bindings/rp2pio/StateMachine.h"
50+
#endif
51+
4852
#if BOARD_I2C
4953
// Statically allocate the I2C object so it can live past the end of the heap and into the next VM.
5054
// That way it can be used by built-in I2CDisplay displays and be accessible through board.I2C().
@@ -181,6 +185,6 @@ void reset_board_busses(void) {
181185
MP_STATE_VM(shared_uart_bus) = NULL;
182186
#endif
183187
#if CIRCUITPY_RP2PIO
184-
board_reset_pio();
188+
reset_rp2pio_statemachine();
185189
#endif
186190
}

shared-module/board/__init__.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@
2828
#define MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H
2929

3030
void reset_board_busses(void);
31-
void board_reset_pio(void);
3231

3332
#endif // MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H

0 commit comments

Comments
 (0)