Skip to content

Commit 0f44de4

Browse files
committed
re-apply local changes
1 parent 3988c50 commit 0f44de4

File tree

5 files changed

+51
-7
lines changed

5 files changed

+51
-7
lines changed

system/GD32F30x_firmware/GD32F30x_usbd_library/device/Include/usbd_core.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ struct _usb_dev
181181

182182
__IO uint8_t cur_status;
183183
__IO uint8_t backup_status;
184+
__IO uint8_t nreset;
185+
__IO uint8_t nsusp;
186+
__IO uint8_t nresume;
187+
__IO uint8_t nsuspsusp;
188+
__IO uint8_t nerror;
184189

185190
usb_pm pm;
186191
#ifdef LPM_ENABLED
@@ -219,6 +224,7 @@ struct _usb_handler
219224
void (*suspend) (void);
220225
void (*suspend_leave) (void);
221226
void (*resume) (usb_dev *udev);
227+
void (*err) (uint8_t len);
222228

223229
void (*ep_reset) (usb_dev *udev);
224230
void (*ep_setup) (usb_dev *udev, uint8_t buf_kind, uint32_t buf_addr, const usb_desc_ep *ep_desc);

system/GD32F30x_firmware/GD32F30x_usbd_library/device/Source/usbd_enum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ static usb_reqsta _usb_std_getdescriptor (usb_dev *udev, usb_req *req)
456456
break;
457457

458458
case USB_DESCTYPE_STR:
459-
if (desc_index < STR_IDX_MAX) {
459+
if (desc_index < USB_STRING_COUNT) {
460460
transc->xfer_buf = std_desc_get[desc_type - 1U](udev, desc_index, &transc->xfer_len);
461461
}
462462
break;

system/GD32F30x_firmware/GD32F30x_usbd_library/device/Source/usbd_transc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void _usb_setup_transc (usb_dev *udev, uint8_t ep_num)
5959
uint16_t count = udev->drv_handler->ep_read((uint8_t *)(&udev->control.req), 0U, (uint8_t)EP_BUF_SNG);
6060

6161
if (count != USB_SETUP_PACKET_LEN) {
62+
udev->drv_handler->err(count);
6263
usb_stall_transc(udev);
6364

6465
return;

system/GD32F30x_firmware/GD32F30x_usbd_library/usbd/Source/usbd_lld_core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ static void usbd_suspend (void);
7575
static void usbd_leave_suspend (void);
7676
static uint16_t usbd_ep_status (usb_dev *udev, uint8_t ep_addr);
7777

78+
void usbd_err(uint8_t len) { (void)len; }
79+
7880
struct _usb_handler usbd_drv_handler =
7981
{
8082
.dp_pullup = usbd_dp_pullup,
@@ -83,6 +85,7 @@ struct _usb_handler usbd_drv_handler =
8385
.suspend = usbd_suspend,
8486
.suspend_leave = usbd_leave_suspend,
8587
.resume = usbd_resume,
88+
.err = usbd_err,
8689
.set_addr = usbd_address_set,
8790
.ep_reset = usbd_ep_reset,
8891
.ep_disable = usbd_ep_disable,
@@ -158,7 +161,7 @@ static void usbd_core_reset (void)
158161
#endif /* LPM_ENABLED */
159162

160163
/* enable all interrupts mask bits */
161-
USBD_CTL |= CTL_STIE | CTL_WKUPIE | CTL_SPSIE | CTL_SOFIE | CTL_ESOFIE | CTL_RSTIE;
164+
USBD_CTL |= CTL_STIE | CTL_ERRIE | CTL_WKUPIE | CTL_SPSIE | CTL_SOFIE | CTL_ESOFIE | CTL_RSTIE;
162165
}
163166

164167
/*!

system/GD32F30x_firmware/GD32F30x_usbd_library/usbd/Source/usbd_lld_int.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,15 @@ void usbd_isr (void)
164164
}
165165
}
166166

167+
if (INTF_ERRIF & int_flag) {
168+
udev->drv_handler->err(0xff);
169+
udev->nerror++;
170+
CLR(ERRIF);
171+
}
167172
if (INTF_WKUPIF & int_flag) {
168-
/* clear wakeup interrupt flag in INTF */
169-
CLR(WKUPIF);
170-
171173
/* restore the old cur_status */
172174
udev->cur_status = udev->backup_status;
175+
udev->nresume++;
173176

174177
#ifdef LPM_ENABLED
175178
if ((0U == udev->pm.remote_wakeup_on) && (0U == udev->lpm.L1_resume)) {
@@ -187,6 +190,9 @@ void usbd_isr (void)
187190
resume_mcu(udev);
188191
}
189192
#endif /* LPM_ENABLED */
193+
194+
/* clear wakeup interrupt flag in INTF */
195+
CLR(WKUPIF);
190196
}
191197

192198
if (INTF_SPSIF & int_flag) {
@@ -234,6 +240,7 @@ void usbd_isr (void)
234240
CLR(RSTIF);
235241

236242
udev->drv_handler->ep_reset(udev);
243+
udev->nreset++;
237244
}
238245

239246
#ifdef LPM_ENABLED
@@ -261,8 +268,35 @@ void usbd_isr (void)
261268
*/
262269
static void usbd_int_suspend (usb_dev *udev)
263270
{
264-
/* store the device current status */
265-
udev->backup_status = udev->cur_status;
271+
/* store the device current status, but only if not already suspended */
272+
/*
273+
* During remote wakeup, the suspend interrupt can fire while already
274+
* suspended, corrupting backup_status if this check isn't done.
275+
*
276+
* Details:
277+
*
278+
* usbd_remote_wakeup_active() calls resume_mcu(), which is a wrapper
279+
* around usbd_leave_suspend(), which clears SETSPS. Clearing SETSPS
280+
* re-enables ESOF detection, and also the SPSIF interrupt. ESOF
281+
* detection and the SPSIF interrupt don't respect USB line states, so
282+
* they can activate during a remote wakeup scenario. The remote wakeup
283+
* process relies on this to count the 15ms duration for sending the
284+
* remote wakeup signal upstream.
285+
*
286+
* The SPSIF handling code defers calling usbd_int_suspend() while
287+
* RSREQ is set (during the remote wakeup signaling), but once that
288+
* countdown is over, the suspend interrupt will fire again while
289+
* the the upstream port is driving a resume signal downstream
290+
* (typically for another 5ms). It might actually be necessary to
291+
* call the suspend handler during remote wakeup, because WKUPIF
292+
* detection might only work if SETSPS is set.
293+
*/
294+
if (udev->cur_status != USBD_SUSPENDED) {
295+
udev->backup_status = udev->cur_status;
296+
} else {
297+
udev->nsuspsusp++;
298+
}
299+
udev->nsusp++;
266300

267301
/* set device in suspended state */
268302
udev->cur_status = (uint8_t)USBD_SUSPENDED;

0 commit comments

Comments
 (0)