From e3b7ed9ae966be1cb41165343ef30c6523ed5771 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 24 Oct 2022 18:43:21 +0700 Subject: [PATCH] use dummy for all ZLP for ip3511, fix lpc55 build with DEBUG=1 --- hw/bsp/lpc55/family.mk | 1 + src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/bsp/lpc55/family.mk b/hw/bsp/lpc55/family.mk index 1af1d076..9d6702b9 100644 --- a/hw/bsp/lpc55/family.mk +++ b/hw/bsp/lpc55/family.mk @@ -43,6 +43,7 @@ SRC_C += \ $(MCU_DIR)/drivers/fsl_power.c \ $(MCU_DIR)/drivers/fsl_reset.c \ $(SDK_DIR)/drivers/lpc_gpio/fsl_gpio.c \ + $(SDK_DIR)/drivers/common/fsl_common_arm.c \ $(SDK_DIR)/drivers/flexcomm/fsl_flexcomm.c \ $(SDK_DIR)/drivers/flexcomm/fsl_usart.c \ lib/sct_neopixel/sct_neopixel.c diff --git a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c index 7825d287..9b490c48 100644 --- a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c +++ b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c @@ -178,7 +178,9 @@ typedef struct // For example: LPC55s69 port1 Highspeed must be USB_RAM (0x40100000) // Use CFG_TUSB_MEM_SECTION to place it accordingly. CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static dcd_data_t _dcd; -CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static volatile uint8_t dummy[8] = { 0 }; // a fix for EP0 OUT ZLPs overwriting the buffer + +// Dummy buffer to fix ZLPs overwriting the buffer (probably an USB/DMA controller bug) +CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(64) static uint8_t dummy[8]; //--------------------------------------------------------------------+ // Multiple Controllers @@ -405,10 +407,14 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t to tu_memclr(&_dcd.dma[ep_id], sizeof(xfer_dma_t)); _dcd.dma[ep_id].total_bytes = total_bytes; - if (!buffer && !ep_id) // for EP0 OUT ZLPs to prevent overwrites to buffer + if (!buffer) { + // Although having no data, ZLPs can cause buffer overwritten to zeroes. + // Probably due to USB/DMA controller side effect/bug. + // Assigned buffer offset to (valid) dummy to prevent overwriting to DATABUFSTART buffer = (uint8_t*)(uint32_t)dummy; } + prepare_ep_xfer(rhport, ep_id, get_buf_offset(buffer), total_bytes); return true;