Skip to content

Commit 3314e36

Browse files
committed
drivers: udc: rpi_pico: fix RP2350 warm ep init
There was an issue that RP2350's USB controller won't start after a boot through bootloader (for example a RAM-only boot) For some reason this could be worked around by a k_usleep(10) added to the enable function, however it was discovered that endpoint setup was in the init function and not in enable function. This led to DPSRAM likely being in the wrong state, as the enable path zeroes its contents. Fixed by moving internal endpoint enable/disable into enable/disable from init/shutdown. This is done the same way in the nrf, samd, dwc2 and stm32 drivers. This also matches init sequency tinyusb does more closely. Signed-off-by: Dmitrii Sharshakov <d3dx12.xx@gmail.com>
1 parent b9bfff2 commit 3314e36

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

drivers/usb/udc/udc_rpi_pico.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,18 @@ static int udc_rpi_pico_enable(const struct device *dev)
10441044
USB_USB_PWR_VBUS_DETECT_OVERRIDE_EN_BITS, (mm_reg_t)&base->pwr);
10451045
}
10461046

1047+
if (udc_ep_enable_internal(dev, USB_CONTROL_EP_OUT,
1048+
USB_EP_TYPE_CONTROL, 64, 0)) {
1049+
LOG_ERR("Failed to enable control endpoint");
1050+
return -EIO;
1051+
}
1052+
1053+
if (udc_ep_enable_internal(dev, USB_CONTROL_EP_IN,
1054+
USB_EP_TYPE_CONTROL, 64, 0)) {
1055+
LOG_ERR("Failed to enable control endpoint");
1056+
return -EIO;
1057+
}
1058+
10471059
/* Enable an interrupt per EP0 transaction */
10481060
sys_write32(USB_SIE_CTRL_EP0_INT_1BUF_BITS, (mm_reg_t)&base->sie_ctrl);
10491061

@@ -1082,6 +1094,16 @@ static int udc_rpi_pico_disable(const struct device *dev)
10821094
{
10831095
const struct rpi_pico_config *config = dev->config;
10841096

1097+
if (udc_ep_disable_internal(dev, USB_CONTROL_EP_OUT)) {
1098+
LOG_ERR("Failed to disable control endpoint");
1099+
return -EIO;
1100+
}
1101+
1102+
if (udc_ep_disable_internal(dev, USB_CONTROL_EP_IN)) {
1103+
LOG_ERR("Failed to disable control endpoint");
1104+
return -EIO;
1105+
}
1106+
10851107
config->irq_disable_func(dev);
10861108
LOG_DBG("Disable device %p", dev);
10871109

@@ -1094,18 +1116,6 @@ static int udc_rpi_pico_init(const struct device *dev)
10941116
const struct pinctrl_dev_config *const pcfg = config->pcfg;
10951117
int err;
10961118

1097-
if (udc_ep_enable_internal(dev, USB_CONTROL_EP_OUT,
1098-
USB_EP_TYPE_CONTROL, 64, 0)) {
1099-
LOG_ERR("Failed to enable control endpoint");
1100-
return -EIO;
1101-
}
1102-
1103-
if (udc_ep_enable_internal(dev, USB_CONTROL_EP_IN,
1104-
USB_EP_TYPE_CONTROL, 64, 0)) {
1105-
LOG_ERR("Failed to enable control endpoint");
1106-
return -EIO;
1107-
}
1108-
11091119
if (pcfg != NULL) {
11101120
err = pinctrl_apply_state(pcfg, PINCTRL_STATE_DEFAULT);
11111121
if (err) {
@@ -1121,16 +1131,6 @@ static int udc_rpi_pico_shutdown(const struct device *dev)
11211131
{
11221132
const struct rpi_pico_config *config = dev->config;
11231133

1124-
if (udc_ep_disable_internal(dev, USB_CONTROL_EP_OUT)) {
1125-
LOG_ERR("Failed to disable control endpoint");
1126-
return -EIO;
1127-
}
1128-
1129-
if (udc_ep_disable_internal(dev, USB_CONTROL_EP_IN)) {
1130-
LOG_ERR("Failed to disable control endpoint");
1131-
return -EIO;
1132-
}
1133-
11341134
return clock_control_off(config->clk_dev, config->clk_sys);
11351135
}
11361136

0 commit comments

Comments
 (0)