Skip to content

Commit 9e9f331

Browse files
authored
Merge pull request #1434 from Skyler84/rp2040-hcd-bulk
Rp2040 hcd bulk
2 parents 28f49c0 + d2c9b8b commit 9e9f331

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed

src/common/tusb_types.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,20 @@ TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_edpt_packet_size(tusb_desc_endpo
513513
return tu_le16toh(desc_ep->wMaxPacketSize) & TU_GENMASK(10, 0);
514514
}
515515

516+
#if CFG_TUSB_DEBUG
517+
TU_ATTR_ALWAYS_INLINE static inline const char *tu_edpt_dir_str(tusb_dir_t dir)
518+
{
519+
static const char *str[] = {"out", "in"};
520+
return str[dir];
521+
}
522+
523+
TU_ATTR_ALWAYS_INLINE static inline const char *tu_edpt_type_str(tusb_xfer_type_t t)
524+
{
525+
static const char *str[] = {"control", "isochronous", "bulk", "interrupt"};
526+
return str[t];
527+
}
528+
#endif
529+
516530
//--------------------------------------------------------------------+
517531
// Descriptor helper
518532
//--------------------------------------------------------------------+

src/portable/raspberrypi/rp2040/hcd_rp2040.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,25 @@ static void __tusb_irq_path_func(hw_handle_buff_status)(void)
138138
_handle_buff_status_bit(bit, ep);
139139
}
140140

141-
// Check interrupt endpoints
141+
// Check "interrupt" (asynchronous) endpoints for both IN and OUT
142142
for (uint i = 1; i <= USB_HOST_INTERRUPT_ENDPOINTS && remaining_buffers; i++)
143143
{
144-
// EPX is bit 0
145-
// IEP1 is bit 2
146-
// IEP2 is bit 4
147-
// IEP3 is bit 6
144+
// EPX is bit 0 & 1
145+
// IEP1 IN is bit 2
146+
// IEP1 OUT is bit 3
147+
// IEP2 IN is bit 4
148+
// IEP2 OUT is bit 5
149+
// IEP3 IN is bit 6
150+
// IEP3 OUT is bit 7
148151
// etc
149-
bit = 1 << (i*2);
150-
151-
if (remaining_buffers & bit)
152+
for(uint j = 0; j < 2; j++)
152153
{
153-
remaining_buffers &= ~bit;
154-
_handle_buff_status_bit(bit, &ep_pool[i]);
154+
bit = 1 << (i*2+j);
155+
if (remaining_buffers & bit)
156+
{
157+
remaining_buffers &= ~bit;
158+
_handle_buff_status_bit(bit, &ep_pool[i]);
159+
}
155160
}
156161
}
157162

@@ -273,10 +278,12 @@ static struct hw_endpoint *_hw_endpoint_allocate(uint8_t transfer_type)
273278
{
274279
struct hw_endpoint *ep = NULL;
275280

276-
if (transfer_type == TUSB_XFER_INTERRUPT)
281+
if (transfer_type != TUSB_XFER_CONTROL)
277282
{
283+
// Note: even though datasheet name these "Interrupt" endpoints. These are actually
284+
// "Asynchronous" endpoints and can be used for other type such as: Bulk (ISO need confirmation)
278285
ep = _next_free_interrupt_ep();
279-
pico_info("Allocate interrupt ep %d\n", ep->interrupt_num);
286+
pico_info("Allocate %s ep %d\n", tu_edpt_type_str(transfer_type), ep->interrupt_num);
280287
assert(ep);
281288
ep->buffer_control = &usbh_dpram->int_ep_buffer_ctrl[ep->interrupt_num].ctrl;
282289
ep->endpoint_control = &usbh_dpram->int_ep_ctrl[ep->interrupt_num].ctrl;
@@ -337,13 +344,13 @@ static void _hw_endpoint_init(struct hw_endpoint *ep, uint8_t dev_addr, uint8_t
337344
pico_trace("endpoint control (0x%p) <- 0x%x\n", ep->endpoint_control, ep_reg);
338345
ep->configured = true;
339346

340-
if (bmInterval)
347+
if (ep != &epx)
341348
{
342-
// This is an interrupt endpoint
343-
// so need to set up interrupt endpoint address control register with:
344-
// device address
345-
// endpoint number / direction
346-
// preamble
349+
// Endpoint has its own addr_endp and interrupt bits to be setup!
350+
// This is an interrupt/async endpoint. so need to set up ADDR_ENDP register with:
351+
// - device address
352+
// - endpoint number / direction
353+
// - preamble
347354
uint32_t reg = (uint32_t) (dev_addr | (num << USB_ADDR_ENDP1_ENDPOINT_LSB));
348355

349356
if (dir == TUSB_DIR_OUT)
@@ -523,6 +530,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
523530

524531
// Get appropriate ep. Either EPX or interrupt endpoint
525532
struct hw_endpoint *ep = get_dev_ep(dev_addr, ep_addr);
533+
526534
TU_ASSERT(ep);
527535

528536
// EP should be inactive

0 commit comments

Comments
 (0)