Skip to content

Commit 49d9775

Browse files
committed
feat(port/rp2040): update rp2040 host driver, use irq_add_shared_handler to register irq handler
Signed-off-by: sakumisu <1203593632@qq.com>
1 parent 5573472 commit 49d9775

File tree

3 files changed

+823
-5
lines changed

3 files changed

+823
-5
lines changed

cherryusb.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ if(CONFIG_CHERRYUSB_HOST)
272272
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "kinetis_mcx")
273273
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/kinetis/usb_hc_kinetis.c)
274274
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/kinetis/usb_glue_mcx.c)
275+
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "rp2040")
276+
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/rp2040/usb_hc_rp2040.c)
275277
endif()
276278
endif()
277279

port/rp2040/usb_dc_rp2040.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct rp2040_udc {
4848
struct usb_setup_packet setup; /*!< Setup package that may be used in interrupt processing (outside the protocol stack) */
4949
} g_rp2040_udc;
5050

51+
void rp2040_usbd_irq(void);
52+
5153
/**
5254
* @brief Take a buffer pointer located in the USB RAM and return as an offset of the RAM.
5355
*
@@ -73,7 +75,10 @@ void usb_setup_endpoint(const struct rp2040_ep_state *ep)
7375

7476
// Get the data buffer as an offset of the USB controller's DPRAM
7577
uint32_t dpram_offset = usb_buffer_offset(ep->data_buffer);
76-
uint32_t reg = EP_CTRL_ENABLE_BITS | EP_CTRL_INTERRUPT_PER_BUFFER | (ep->ep_type << EP_CTRL_BUFFER_TYPE_LSB) | dpram_offset;
78+
uint32_t reg = EP_CTRL_ENABLE_BITS |
79+
EP_CTRL_INTERRUPT_PER_BUFFER |
80+
(ep->ep_type << EP_CTRL_BUFFER_TYPE_LSB) |
81+
dpram_offset;
7782
*ep->endpoint_control = reg;
7883
}
7984

@@ -144,6 +149,11 @@ int usb_dc_init(uint8_t busid)
144149
next_buffer_ptr += 64;
145150
}
146151

152+
// Remove shared irq if it was previously added so as not to fill up shared irq slots
153+
irq_remove_handler(USBCTRL_IRQ, rp2040_usbd_irq);
154+
155+
irq_add_shared_handler(USBCTRL_IRQ, rp2040_usbd_irq, PICO_SHARED_IRQ_HANDLER_HIGHEST_ORDER_PRIORITY);
156+
147157
// Reset usb controller
148158
reset_unreset_block_num_wait_blocking(RESET_USBCTRL);
149159

@@ -181,6 +191,9 @@ int usb_dc_init(uint8_t busid)
181191
int usb_dc_deinit(uint8_t busid)
182192
{
183193
irq_set_enabled(USBCTRL_IRQ, false);
194+
// Remove shared irq if it was previously added so as not to fill up shared irq slots
195+
irq_remove_handler(USBCTRL_IRQ, rp2040_usbd_irq);
196+
184197
usb_hw_clear->sie_ctrl = USB_SIE_CTRL_PULLUP_EN_BITS;
185198
memset(&g_rp2040_udc, 0, sizeof(struct rp2040_udc));
186199

@@ -330,7 +343,6 @@ int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t
330343

331344
if (data_len == 0) {
332345
usb_start_transfer(&g_rp2040_udc.out_ep[ep_idx], NULL, 0);
333-
return 0;
334346
} else {
335347
/*!< Not zlp */
336348
data_len = MIN(data_len, g_rp2040_udc.out_ep[ep_idx].ep_mps);
@@ -461,8 +473,7 @@ static void usb_handle_buff_done(uint8_t ep_num, bool in)
461473
*/
462474
static void usb_handle_buff_status(void)
463475
{
464-
uint32_t buffers = usb_hw->buf_status;
465-
uint32_t remaining_buffers = buffers;
476+
uint32_t remaining_buffers = usb_hw->buf_status;
466477

467478
uint32_t bit = 1u;
468479
for (uint8_t i = 0; remaining_buffers && i < USB_NUM_ENDPOINTS * 2; i++) {
@@ -571,7 +582,7 @@ void USBD_IRQHandler(uint8_t busid)
571582
}
572583
}
573584

574-
void isr_usbctrl(void)
585+
void rp2040_usbd_irq(void)
575586
{
576587
USBD_IRQHandler(0);
577588
}

0 commit comments

Comments
 (0)