Skip to content

Commit f8eb5bc

Browse files
committed
Cleanup PIOs and State Machines on soft reset
1 parent eeb89a9 commit f8eb5bc

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929
#include "py/runtime.h"
3030
#include "py/mphal.h"
3131
#include "common-hal/microcontroller/Pin.h"
32+
#include "src/rp2_common/hardware_pio/include/hardware/pio.h"
33+
#include "shared-module/board/__init__.h"
3234

3335
// Pins aren't actually defined here. They are in the board specific directory
3436
// 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+
}

shared-module/board/__init__.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "supervisor/shared/translate.h"
2929
#include "mpconfigboard.h"
3030
#include "py/runtime.h"
31+
#include "shared-module/board/__init__.h"
3132

3233
#if CIRCUITPY_BUSIO
3334
#include "shared-bindings/busio/I2C.h"
@@ -179,4 +180,7 @@ void reset_board_busses(void) {
179180
#if BOARD_UART
180181
MP_STATE_VM(shared_uart_bus) = NULL;
181182
#endif
183+
#if CIRCUITPY_RP2PIO
184+
board_reset_pio();
185+
#endif
182186
}

shared-module/board/__init__.h

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

3030
void reset_board_busses(void);
31+
void board_reset_pio(void);
3132

3233
#endif // MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H

0 commit comments

Comments
 (0)