Skip to content

Commit 1e982ff

Browse files
mniestrojfabiobaltieri
authored andcommitted
drivers: usb_dc_rpi: create thread and connect IRQ during init
So far thread was created as part of usb_dc_attach() by k_thread_create(). This means that if following function were executed: * usb_enable() * usb_disable() * usb_enable() then k_thread_create() was called second time. This results in undefined behavior. Fix above issue by moving k_thread_create() invocation to function called during system initialization. While at it, move IRQ_CONNECT() and irq_enable() invocations to init as well. Signed-off-by: Marcin Niestroj <[email protected]>
1 parent e4480d6 commit 1e982ff

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

drivers/usb/device/usb_dc_rpi_pico.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ struct cb_msg {
6666
};
6767

6868
K_MSGQ_DEFINE(usb_dc_msgq, sizeof(struct cb_msg), 10, 4);
69-
static void udc_rpi_thread_main(void *arg1, void *unused1, void *unused2);
7069

7170
static struct udc_rpi_ep_state *udc_rpi_get_ep_state(uint8_t ep)
7271
{
@@ -299,14 +298,6 @@ static int udc_rpi_init(void)
299298
udc_rpi_init_endpoint(i);
300299
}
301300

302-
k_thread_create(&thread, thread_stack,
303-
USBD_THREAD_STACK_SIZE,
304-
udc_rpi_thread_main, NULL, NULL, NULL,
305-
K_PRIO_COOP(2), 0, K_NO_WAIT);
306-
307-
IRQ_CONNECT(USB_IRQ, USB_IRQ_PRI, udc_rpi_isr, 0, 0);
308-
irq_enable(USB_IRQ);
309-
310301
/* Present full speed device by enabling pull up on DP */
311302
hw_set_alias(usb_hw)->sie_ctrl = USB_SIE_CTRL_PULLUP_EN_BITS;
312303

@@ -747,3 +738,20 @@ static void udc_rpi_thread_main(void *arg1, void *unused1, void *unused2)
747738
}
748739
}
749740
}
741+
742+
static int usb_rpi_init(const struct device *dev)
743+
{
744+
ARG_UNUSED(dev);
745+
746+
k_thread_create(&thread, thread_stack,
747+
USBD_THREAD_STACK_SIZE,
748+
udc_rpi_thread_main, NULL, NULL, NULL,
749+
K_PRIO_COOP(2), 0, K_NO_WAIT);
750+
751+
IRQ_CONNECT(USB_IRQ, USB_IRQ_PRI, udc_rpi_isr, 0, 0);
752+
irq_enable(USB_IRQ);
753+
754+
return 0;
755+
}
756+
757+
SYS_INIT(usb_rpi_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);

0 commit comments

Comments
 (0)