Cleanup PIOs and State Machines on soft reset

This commit is contained in:
root 2021-02-25 12:38:43 -06:00
parent eeb89a97b4
commit f8eb5bc275
3 changed files with 17 additions and 0 deletions

View File

@ -29,6 +29,18 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/mphal.h" #include "py/mphal.h"
#include "common-hal/microcontroller/Pin.h" #include "common-hal/microcontroller/Pin.h"
#include "src/rp2_common/hardware_pio/include/hardware/pio.h"
#include "shared-module/board/__init__.h"
// Pins aren't actually defined here. They are in the board specific directory // Pins aren't actually defined here. They are in the board specific directory
// such as boards/arduino_zero/pins.c. // such as boards/arduino_zero/pins.c.
// routine to reset both pios
void board_reset_pio() {
for ( uint8_t sm = 0; sm < 4; sm++) {
pio_sm_init (pio0, sm, 0, NULL);
pio_sm_init (pio1, sm, 0, NULL);
}
pio_clear_instruction_memory(pio0);
pio_clear_instruction_memory(pio1);
}

View File

@ -28,6 +28,7 @@
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
#include "mpconfigboard.h" #include "mpconfigboard.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-module/board/__init__.h"
#if CIRCUITPY_BUSIO #if CIRCUITPY_BUSIO
#include "shared-bindings/busio/I2C.h" #include "shared-bindings/busio/I2C.h"
@ -179,4 +180,7 @@ void reset_board_busses(void) {
#if BOARD_UART #if BOARD_UART
MP_STATE_VM(shared_uart_bus) = NULL; MP_STATE_VM(shared_uart_bus) = NULL;
#endif #endif
#if CIRCUITPY_RP2PIO
board_reset_pio();
#endif
} }

View File

@ -28,5 +28,6 @@
#define MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H #define MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H
void reset_board_busses(void); void reset_board_busses(void);
void board_reset_pio(void);
#endif // MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H #endif // MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H