Skip to content

Commit 7d20d0b

Browse files
committed
update(port/dwc2/usb_dc_dwc2): remove __UNALIGNED_UINT32_READ and __UNALIGNED_UINT32_WRITE because buf is always align4, move first setup into enumdone intsts
Signed-off-by: sakumisu <[email protected]>
1 parent 8d7a98f commit 7d20d0b

File tree

1 file changed

+7
-60
lines changed

1 file changed

+7
-60
lines changed

port/dwc2/usb_dc_dwc2.c

Lines changed: 7 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,6 @@
77
#include "usb_dwc2_reg.h"
88
#include "usb_dwc2_param.h"
99

10-
// clang-format off
11-
#if defined ( __CC_ARM )
12-
#ifndef __UNALIGNED_UINT32_WRITE
13-
#define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val))
14-
#endif
15-
#ifndef __UNALIGNED_UINT32_READ
16-
#define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr)))
17-
#endif
18-
#elif defined (__ICCARM__)
19-
#ifndef __UNALIGNED_UINT32_WRITE
20-
#define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val))
21-
#endif
22-
#ifndef __UNALIGNED_UINT32_READ
23-
#define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr)))
24-
#endif
25-
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
26-
#ifndef __UNALIGNED_UINT32_WRITE
27-
#pragma clang diagnostic push
28-
#pragma clang diagnostic ignored "-Wpacked"
29-
/*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */
30-
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
31-
#pragma clang diagnostic pop
32-
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
33-
#endif
34-
#ifndef __UNALIGNED_UINT32_READ
35-
#pragma clang diagnostic push
36-
#pragma clang diagnostic ignored "-Wpacked"
37-
/*lint -esym(9058, T_UINT32_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_READ */
38-
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
39-
#pragma clang diagnostic pop
40-
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
41-
#endif
42-
#elif defined ( __GNUC__ )
43-
#ifndef __UNALIGNED_UINT32_WRITE
44-
#pragma GCC diagnostic push
45-
#pragma GCC diagnostic ignored "-Wpacked"
46-
#pragma GCC diagnostic ignored "-Wattributes"
47-
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
48-
#pragma GCC diagnostic pop
49-
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
50-
#endif
51-
#ifndef __UNALIGNED_UINT32_READ
52-
#pragma GCC diagnostic push
53-
#pragma GCC diagnostic ignored "-Wpacked"
54-
#pragma GCC diagnostic ignored "-Wattributes"
55-
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
56-
#pragma GCC diagnostic pop
57-
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
58-
#endif
59-
#endif
60-
// clang-format on
61-
6210
#define USBD_BASE (g_usbdev_bus[busid].reg_base)
6311

6412
#define USB_OTG_GLB ((DWC2_GlobalTypeDef *)(USBD_BASE))
@@ -351,25 +299,23 @@ static void dwc2_ep0_start_read_setup(uint8_t busid, uint8_t *psetup)
351299

352300
void dwc2_ep_write(uint8_t busid, uint8_t ep_idx, uint8_t *src, uint16_t len)
353301
{
354-
uint32_t *pSrc = (uint32_t *)src;
302+
uint32_t *psrc = (uint32_t *)src;
355303
uint32_t count32b, i;
356304

357305
count32b = ((uint32_t)len + 3U) / 4U;
358306
for (i = 0U; i < count32b; i++) {
359-
USB_OTG_FIFO((uint32_t)ep_idx) = __UNALIGNED_UINT32_READ(pSrc);
360-
pSrc++;
307+
USB_OTG_FIFO((uint32_t)ep_idx) = *psrc++;
361308
}
362309
}
363310

364311
void dwc2_ep_read(uint8_t busid, uint8_t *dest, uint16_t len)
365312
{
366-
uint32_t *pDest = (uint32_t *)dest;
313+
uint32_t *pdest = (uint32_t *)dest;
367314
uint32_t i;
368315
uint32_t count32b = ((uint32_t)len + 3U) / 4U;
369316

370317
for (i = 0U; i < count32b; i++) {
371-
__UNALIGNED_UINT32_WRITE(pDest, USB_OTG_FIFO(0U));
372-
pDest++;
318+
*pdest++ = USB_OTG_FIFO(0U);
373319
}
374320
}
375321

@@ -1181,14 +1127,15 @@ void USBD_IRQHandler(uint8_t busid)
11811127
memset(g_dwc2_udc[busid].in_ep, 0, sizeof(struct dwc2_ep_state) * 16);
11821128
memset(g_dwc2_udc[busid].out_ep, 0, sizeof(struct dwc2_ep_state) * 16);
11831129
usbd_event_reset_handler(busid);
1184-
/* Start reading setup */
1185-
dwc2_ep0_start_read_setup(busid, (uint8_t *)&g_dwc2_udc[busid].setup);
11861130
}
11871131
if (gint_status & USB_OTG_GINTSTS_ENUMDNE) {
11881132
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_ENUMDNE;
11891133
dwc2_set_turnaroundtime(busid, SystemCoreClock, dwc2_get_devspeed(busid));
11901134

11911135
USB_OTG_DEV->DCTL |= USB_OTG_DCTL_CGINAK;
1136+
1137+
/* Start reading setup */
1138+
dwc2_ep0_start_read_setup(busid, (uint8_t *)&g_dwc2_udc[busid].setup);
11921139
}
11931140
if (gint_status & USB_OTG_GINTSTS_PXFR_INCOMPISOOUT) {
11941141
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_PXFR_INCOMPISOOUT;

0 commit comments

Comments
 (0)