Skip to content

Commit

Permalink
can2040: Disable tx state machine before resetting it
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
KevinOConnor committed Apr 29, 2023
1 parent 52450e1 commit c4900e1
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/can2040.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c4900e1

Please sign in to comment.