From 76053315d93b93229d4f8f44dd002e34e283781c Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Thu, 26 Aug 2021 00:51:33 -0400 Subject: [PATCH] fix some usb bugs now it can enumerate --- os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c | 9 +++++---- os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.h | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c b/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c index 4e8f6a02..72e9e842 100644 --- a/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c +++ b/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c @@ -215,7 +215,7 @@ uint32_t usb_prepare_out_ep_buffer(USBDriver *usbp, usbep_t ep, uint8_t buffer_i buf_ctrl |= USB_BUFFER_BUFFER0_LAST; } /* PID */ - buf_ctrl |= iesp->next_pid ? USB_BUFFER_BUFFER1_DATA_PID : USB_BUFFER_BUFFER0_DATA_PID; + buf_ctrl |= iesp->next_pid ? USB_BUFFER_BUFFER0_DATA_PID : 0; iesp->next_pid ^= 1U; buf_ctrl |= USB_BUFFER_BUFFER0_AVAILABLE | @@ -274,7 +274,7 @@ static uint32_t usb_prepare_in_ep_buffer(USBDriver *usbp, usbep_t ep, uint8_t bu buf_len = epcp->in_maxsize < iesp->txsize - iesp->txlast ? epcp->in_maxsize : iesp->txsize - iesp->txlast; - if (buf_len > 0) { + if (buf_len >= 0) { iesp->txlast += buf_len; if (iesp->txsize <= iesp->txlast) { @@ -282,7 +282,7 @@ static uint32_t usb_prepare_in_ep_buffer(USBDriver *usbp, usbep_t ep, uint8_t bu buf_ctrl |= USB_BUFFER_BUFFER0_LAST; } /* PID */ - buf_ctrl |= iesp->next_pid ? USB_BUFFER_BUFFER1_DATA_PID : USB_BUFFER_BUFFER0_DATA_PID; + buf_ctrl |= iesp->next_pid ? USB_BUFFER_BUFFER0_DATA_PID : 0; iesp->next_pid ^= 1U; /* Copy data into hardware buffer */ @@ -342,7 +342,7 @@ static void usb_prepare_in_ep(USBDriver *usbp, usbep_t ep) { EP_CTRL(ep).IN = ep_ctrl; } - BUF_CTRL(ep).IN |= buf_ctrl; + BUF_CTRL(ep).IN = buf_ctrl; } /** @@ -429,6 +429,7 @@ OSAL_IRQ_HANDLER(RP_USBCTRL_IRQ_HANDLER) { cmd_send(CMD_SETUP, 0); #endif USB->CLR.SIESTATUS = USB_SIE_STATUS_SETUP_REC; + usbp->epc[0]->in_state->next_pid = 1U; _usb_isr_invoke_setup_cb(usbp, 0); reset_ep0(usbp); diff --git a/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.h b/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.h index 25374d87..3de27e64 100644 --- a/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.h +++ b/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.h @@ -50,12 +50,12 @@ /** * @brief Address ack handling */ -#define USB_SET_ADDRESS_ACK_HANDLING USB_SET_ADDRESS_ACK_HW +#define USB_SET_ADDRESS_ACK_HANDLING USB_SET_ADDRESS_ACK_SW /** * @brief This device requires the address change after the status packet. */ -#define USB_SET_ADDRESS_MODE USB_EARLY_SET_ADDRESS +#define USB_SET_ADDRESS_MODE USB_LATE_SET_ADDRESS /*===========================================================================*/ /* Driver data structures and types. */