Skip to content

Commit 0871238

Browse files
authored
Merge pull request hathach#2024 from jfedor2/sie_ctrl_fix
[rp2040] Make writes to SIE_CTRL aware of concurrent access
2 parents 9771c76 + 9bf97e3 commit 0871238

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/portable/raspberrypi/rp2040/hcd_rp2040.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,11 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
562562
uint32_t flags = USB_SIE_CTRL_START_TRANS_BITS | SIE_CTRL_BASE |
563563
(ep_dir ? USB_SIE_CTRL_RECEIVE_DATA_BITS : USB_SIE_CTRL_SEND_DATA_BITS) |
564564
(need_pre(dev_addr) ? USB_SIE_CTRL_PREAMBLE_EN_BITS : 0);
565+
// START_TRANS bit on SIE_CTRL seems to exhibit the same behavior as the AVAILABLE bit
566+
// described in RP2040 Datasheet, release 2.1, section "4.1.2.5.1. Concurrent access".
567+
// We write everything except the START_TRANS bit first, then wait some cycles.
568+
usb_hw->sie_ctrl = flags & ~USB_SIE_CTRL_START_TRANS_BITS;
569+
busy_wait_at_least_cycles(12);
565570
usb_hw->sie_ctrl = flags;
566571
}else
567572
{
@@ -602,6 +607,11 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
602607
uint32_t const flags = SIE_CTRL_BASE | USB_SIE_CTRL_SEND_SETUP_BITS | USB_SIE_CTRL_START_TRANS_BITS |
603608
(need_pre(dev_addr) ? USB_SIE_CTRL_PREAMBLE_EN_BITS : 0);
604609

610+
// START_TRANS bit on SIE_CTRL seems to exhibit the same behavior as the AVAILABLE bit
611+
// described in RP2040 Datasheet, release 2.1, section "4.1.2.5.1. Concurrent access".
612+
// We write everything except the START_TRANS bit first, then wait some cycles.
613+
usb_hw->sie_ctrl = flags & ~USB_SIE_CTRL_START_TRANS_BITS;
614+
busy_wait_at_least_cycles(12);
605615
usb_hw->sie_ctrl = flags;
606616

607617
return true;

0 commit comments

Comments
 (0)