Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear out PIOs and State Machines on RP2040 soft reset #4265

Merged
merged 6 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ports/raspberrypi/common-hal/rp2pio/StateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "src/rp2_common/hardware_dma/include/hardware/dma.h"
#include "src/rp2_common/hardware_pio/include/hardware/pio_instructions.h"
#include "src/rp2040/hardware_structs/include/hardware/structs/iobank0.h"
#include "src/rp2_common/hardware_irq/include/hardware/irq.h"

#include "lib/utils/interrupt_char.h"
#include "py/obj.h"
Expand Down Expand Up @@ -101,6 +102,13 @@ void reset_rp2pio_statemachine(void) {
_reset_statemachine(pio, j, false);
}
}
for (uint8_t irq=PIO0_IRQ_0; irq <= PIO1_IRQ_1; irq++) {
irq_handler_t int_handler = irq_get_exclusive_handler(irq);
if (int_handler > 0) {
irq_set_enabled (irq, false);
irq_remove_handler(irq,int_handler);
}
}
}

STATIC uint32_t _check_pins_free(const mcu_pin_obj_t * first_pin, uint8_t pin_count, bool exclusive_pin_use) {
Expand Down
7 changes: 7 additions & 0 deletions shared-module/board/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
#include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h"
#endif

#if CIRCUITPY_RP2PIO
#include "bindings/rp2pio/StateMachine.h"
#endif

#if BOARD_I2C
// Statically allocate the I2C object so it can live past the end of the heap and into the next VM.
// That way it can be used by built-in I2CDisplay displays and be accessible through board.I2C().
Expand Down Expand Up @@ -179,4 +183,7 @@ void reset_board_busses(void) {
#if BOARD_UART
MP_STATE_VM(shared_uart_bus) = NULL;
#endif
#if CIRCUITPY_RP2PIO
reset_rp2pio_statemachine();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this anymore because port_reset should call reset_rp2pio_statemachine. rp2pio is meant to be port-specific so it shouldn't influence any code outside of ports/raspberrypi

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it and still tested OK. Thanks!

#endif
}