From c4900e1da0595b381ceb540db8eae569a3f2a143 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 29 Apr 2023 15:11:34 -0400 Subject: [PATCH] can2040: Disable tx state machine before resetting it It seems that if a single write to the PIO ctrl register both disables and resets a state machine then the PIO may actually execute an instruction. Explicitly disable the state machine in one ctrl register write and then reset the state machine in a subsequent write. Signed-off-by: Kevin O'Connor --- src/can2040.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/can2040.c b/src/can2040.c index 9eef0d4..727353a 100644 --- a/src/can2040.c +++ b/src/can2040.c @@ -247,6 +247,7 @@ static void pio_tx_reset(struct can2040 *cd) { pio_hw_t *pio_hw = cd->pio_hw; + pio_hw->ctrl = 0x07 << PIO_CTRL_SM_ENABLE_LSB; pio_hw->ctrl = ((0x07 << PIO_CTRL_SM_ENABLE_LSB) | (0x08 << PIO_CTRL_SM_RESTART_LSB)); pio_hw->irq = (SI_MATCHED | SI_ACKDONE) >> 8; // clear PIO irq flags @@ -255,9 +256,6 @@ pio_tx_reset(struct can2040 *cd) sm->shiftctrl = 0; sm->shiftctrl = (PIO_SM0_SHIFTCTRL_FJOIN_TX_BITS | PIO_SM0_SHIFTCTRL_AUTOPULL_BITS); - // Must reset again after clearing fifo - pio_hw->ctrl = ((0x07 << PIO_CTRL_SM_ENABLE_LSB) - | (0x08 << PIO_CTRL_SM_RESTART_LSB)); } // Queue a message for transmission on PIO "tx" state machine