Skip to content

Commit 74ee1eb

Browse files
committed
rp2/hstx: Drain FIFO after soft reset.
Has to be done in `init()` instead of `deinit()`, because there could be a DMA channel still filling the FIFO when `deinit()` gets called. Signed-off-by: Dryw Wade <dryw.wade@sparkfun.com>
1 parent 4f2c806 commit 74ee1eb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

ports/rp2/rp2_hstx.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,20 @@ static mp_obj_t rp2_hstx_unpack_ctrl(mp_obj_t value_obj, rp2_hstx_ctrl_field_t *
148148
}
149149

150150
void rp2_hstx_init(void) {
151-
// Nothing to do, can probably remove this
151+
// Check whether FIFO contains data
152+
if (hstx_fifo_hw->stat & HSTX_FIFO_STAT_LEVEL_BITS) {
153+
// Enable HSTX, wait for FIFO to drain, then disable HSTX
154+
hstx_ctrl_hw->csr = DEFAULT_HSTX_CSR | HSTX_CTRL_CSR_EN_BITS;
155+
while (hstx_fifo_hw->stat & HSTX_FIFO_STAT_LEVEL_BITS) {
156+
}
157+
hstx_ctrl_hw->csr = DEFAULT_HSTX_CSR;
158+
}
159+
160+
// Check if the WOF flag is set
161+
if (hstx_fifo_hw->stat & HSTX_FIFO_STAT_WOF_BITS) {
162+
// Clear the WOF flag
163+
hstx_fifo_hw->stat = HSTX_FIFO_STAT_WOF_BITS;
164+
}
152165
}
153166

154167
void rp2_hstx_deinit(void) {

0 commit comments

Comments
 (0)