Skip to content

Commit fe42785

Browse files
committed
dummy buffer only on EP0 OUT ZLPs
1 parent 3f45f37 commit fe42785

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ typedef struct
178178
// For example: LPC55s69 port1 Highspeed must be USB_RAM (0x40100000)
179179
// Use CFG_TUSB_MEM_SECTION to place it accordingly.
180180
CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static dcd_data_t _dcd;
181-
CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static volatile uint8_t dummy[64]; // TODO temp fix to prevent accidental overwrite due to ep[][].buffer_xx.offset being 0
181+
CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static volatile uint8_t dummy[8] = { 0 }; // a fix for EP0 OUT ZLPs overwriting the buffer
182182

183183
//--------------------------------------------------------------------+
184184
// Multiple Controllers
@@ -244,16 +244,7 @@ static void prepare_setup_packet(uint8_t rhport)
244244

245245
static void edpt_reset(uint8_t rhport, uint8_t ep_id)
246246
{
247-
const uint32_t offset = get_buf_offset((void*)(uint32_t)dummy);
248247
tu_memclr(&_dcd.ep[ep_id], sizeof(_dcd.ep[ep_id]));
249-
if (_dcd_controller[rhport].max_speed == TUSB_SPEED_FULL )
250-
{
251-
_dcd.ep[ep_id][0].buffer_fs.offset = _dcd.ep[ep_id][1].buffer_fs.offset = offset;
252-
}
253-
else
254-
{
255-
_dcd.ep[ep_id][0].buffer_hs.offset = _dcd.ep[ep_id][1].buffer_hs.offset = offset;
256-
}
257248
}
258249

259250
static void edpt_reset_all(uint8_t rhport)
@@ -413,7 +404,11 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t to
413404
tu_memclr(&_dcd.dma[ep_id], sizeof(xfer_dma_t));
414405
_dcd.dma[ep_id].total_bytes = total_bytes;
415406

416-
prepare_ep_xfer(rhport, ep_id, buffer ? get_buf_offset(buffer) : get_buf_offset((void*)(uint32_t)dummy), total_bytes);
407+
if (!buffer && !ep_id) // for EP0 OUT ZLPs to prevent overwrites to buffer
408+
{
409+
buffer = (uint8_t*)(uint32_t)dummy;
410+
}
411+
prepare_ep_xfer(rhport, ep_id, get_buf_offset(buffer), total_bytes);
417412

418413
return true;
419414
}
@@ -426,8 +421,8 @@ static void bus_reset(uint8_t rhport)
426421
tu_memclr(&_dcd, sizeof(dcd_data_t));
427422
edpt_reset_all(rhport);
428423

429-
// disable all non-control endpoints on bus reset
430-
for(uint8_t ep_id = 2; ep_id < 2*MAX_EP_PAIRS; ep_id++)
424+
// disable all endpoints as epecified by LPC55S69 UM Table 778
425+
for(uint8_t ep_id = 0; ep_id < 2*MAX_EP_PAIRS; ep_id++)
431426
{
432427
_dcd.ep[ep_id][0].disable = _dcd.ep[ep_id][1].disable = 1;
433428
}

0 commit comments

Comments
 (0)