Skip to content

Commit 7f4881f

Browse files
committed
[NUC472/M453] Support USB device
1 parent 1fd2402 commit 7f4881f

File tree

10 files changed

+1411
-54
lines changed

10 files changed

+1411
-54
lines changed

features/unsupported/USBDevice/USBDevice/USBEndpoints.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ typedef enum {
5353
#include "USBEndpoints_Maxim.h"
5454
#elif defined(TARGET_EFM32GG_STK3700) || defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32HG_STK3400)
5555
#include "USBEndpoints_EFM32.h"
56+
#elif defined(TARGET_NUMAKER_PFM_NUC472)
57+
#include "USBEndpoints_NUC472.h"
58+
#elif defined(TARGET_NUMAKER_PFM_M453)
59+
#include "USBEndpoints_M453.h"
5660
#else
5761
#error "Unknown target type"
5862
#endif
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
#define NU_MAX_EPX_BUFSIZE 4096
3+
#define NU_EP2EPL(ep) ((ep) >> 1)
4+
#define NU_EP2EPH(ep) (((ep) >> 1) + 1)
5+
#define NU_EPL2EPH(ep) ((ep) + 1)
6+
#define NU_EPH2EPL(ep) ((ep) - 1)
7+
#define NU_EP_DIR_Pos 0
8+
#define NU_EP_DIR_Msk (1 << NU_EP_DIR_Pos)
9+
#define NU_EP_DIR_OUT 0
10+
#define NU_EP_DIR_IN 1
11+
12+
#define NU_EP_TYPE(ep) (((ep) & NU_EP_TYPE_Msk) >> NU_EP_TYPE_Pos)
13+
#define NU_EP_NUM(ep) (((ep) & NU_EP_NUM_Msk) >> NU_EP_NUM_Pos)
14+
#define NU_EP_DIR(ep) (((ep) & NU_EP_DIR_Msk) >> NU_EP_DIR_Pos)
15+
#define NU_EP_NUM_DIR(ep) ((NU_EP_NUM(ep) << 1) | NU_EP_DIR(ep))
16+
17+
#define NUMBER_OF_PHYSICAL_ENDPOINTS 8
18+
#define EP0OUT (0)
19+
#define EP0IN (1)
20+
#define EP1OUT (2)
21+
#define EP1IN (3)
22+
#define EP2OUT (4)
23+
#define EP2IN (5)
24+
#define EP3OUT (6)
25+
#define EP3IN (7)
26+
#define EP4OUT (8)
27+
#define EP4IN (9)
28+
#define EP5OUT (10)
29+
#define EP5IN (11)
30+
#define EP6OUT (12)
31+
#define EP6IN (13)
32+
33+
/* Maximum Packet sizes */
34+
#define MAX_PACKET_SIZE_EP0 64
35+
#define MAX_PACKET_SIZE_EP1 64
36+
#define MAX_PACKET_SIZE_EP2 64
37+
#define MAX_PACKET_SIZE_EP3 0x60
38+
#define MAX_PACKET_SIZE_EP4 64
39+
#define MAX_PACKET_SIZE_EP5 64
40+
#define MAX_PACKET_SIZE_EP6 64
41+
#define MAX_PACKET_SIZE_EP7 64
42+
43+
/* Generic endpoints - intended to be portable accross devices */
44+
/* and be suitable for simple USB devices. */
45+
46+
/* Bulk endpoints */
47+
#define EPBULK_OUT EP5OUT
48+
#define EPBULK_IN EP6IN
49+
#define EPBULK_OUT_callback EP5_OUT_callback
50+
#define EPBULK_IN_callback EP6_IN_callback
51+
/* Interrupt endpoints */
52+
#define EPINT_OUT EP1OUT
53+
#define EPINT_IN EP2IN
54+
#define EPINT_OUT_callback EP1_OUT_callback
55+
#define EPINT_IN_callback EP2_IN_callback
56+
/* Isochronous endpoints */
57+
#define EPISO_OUT EP3OUT
58+
#define EPISO_IN EP4IN
59+
#define EPISO_OUT_callback EP3_OUT_callback
60+
#define EPISO_IN_callback EP4_IN_callback
61+
62+
#define MAX_PACKET_SIZE_EPBULK 64
63+
#define MAX_PACKET_SIZE_EPINT 64
64+
#define MAX_PACKET_SIZE_EPISO 1023
65+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
#define NU_MAX_EPX_BUFSIZE 4096
3+
#define NU_EP2EPL(ep) ((ep) >> 1)
4+
#define NU_EP2EPH(ep) (((ep) >> 1) - 1)
5+
#define NU_EPX2EP(ep) ((ep == CEP) ? EP0OUT : ((ep) - EPA + EP1OUT))
6+
#define NU_EPL2EPH(ep) ((ep) - 1)
7+
#define NU_EPH2EPL(ep) ((ep) + 1)
8+
#define NU_EP_DIR_Pos 0
9+
#define NU_EP_DIR_Msk (1 << NU_EP_DIR_Pos)
10+
#define NU_EP_DIR_OUT 0
11+
#define NU_EP_DIR_IN 1
12+
13+
#define NU_EP_TYPE(ep) (((ep) & NU_EP_TYPE_Msk) >> NU_EP_TYPE_Pos)
14+
#define NU_EP_NUM(ep) (((ep) & NU_EP_NUM_Msk) >> NU_EP_NUM_Pos)
15+
#define NU_EP_DIR(ep) (((ep) & NU_EP_DIR_Msk) >> NU_EP_DIR_Pos)
16+
#define NU_EP_NUM_DIR(ep) ((NU_EP_NUM(ep) << 1) | NU_EP_DIR(ep))
17+
18+
#define NUMBER_OF_PHYSICAL_ENDPOINTS 12
19+
20+
#define EP0OUT (0)
21+
#define EP0IN (1)
22+
#define EP1OUT (2)
23+
#define EP1IN (3)
24+
#define EP2OUT (4)
25+
#define EP2IN (5)
26+
#define EP3OUT (6)
27+
#define EP3IN (7)
28+
#define EP4OUT (8)
29+
#define EP4IN (9)
30+
#define EP5OUT (10)
31+
#define EP5IN (11)
32+
#define EP6OUT (12)
33+
#define EP6IN (13)
34+
35+
/* Maximum Packet sizes */
36+
#define MAX_PACKET_SIZE_EP0 64
37+
#define MAX_PACKET_SIZE_EP1 64
38+
#define MAX_PACKET_SIZE_EP2 64
39+
#define MAX_PACKET_SIZE_EP3 0x60
40+
#define MAX_PACKET_SIZE_EP4 64
41+
#define MAX_PACKET_SIZE_EP5 64
42+
#define MAX_PACKET_SIZE_EP6 64
43+
#define MAX_PACKET_SIZE_EP7 64
44+
#define MAX_PACKET_SIZE_EP8 64
45+
#define MAX_PACKET_SIZE_EP9 64
46+
#define MAX_PACKET_SIZE_EP10 64
47+
#define MAX_PACKET_SIZE_EP11 64
48+
49+
/* Generic endpoints - intended to be portable accross devices */
50+
/* and be suitable for simple USB devices. */
51+
52+
/* Bulk endpoints */
53+
#define EPBULK_OUT EP5OUT
54+
#define EPBULK_IN EP6IN
55+
#define EPBULK_OUT_callback EP5_OUT_callback
56+
#define EPBULK_IN_callback EP6_IN_callback
57+
/* Interrupt endpoints */
58+
#define EPINT_OUT EP1OUT
59+
#define EPINT_IN EP2IN
60+
#define EPINT_OUT_callback EP1_OUT_callback
61+
#define EPINT_IN_callback EP2_IN_callback
62+
/* Isochronous endpoints */
63+
#define EPISO_OUT EP3OUT
64+
#define EPISO_IN EP4IN
65+
#define EPISO_OUT_callback EP3_OUT_callback
66+
#define EPISO_IN_callback EP4_IN_callback
67+
68+
#define MAX_PACKET_SIZE_EPBULK 64
69+
#define MAX_PACKET_SIZE_EPINT 64
70+
#define MAX_PACKET_SIZE_EPISO 1023
71+
72+
#define USBD_GET_EP_MAX_PAYLOAD(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EPAMPS + (uint32_t)((ep)*0x28))))
73+
#define USBD_GET_EP_DATA_COUNT(ep) ((*((__IO uint32_t *) ((uint32_t)&USBD->EPADATCNT + (uint32_t)((ep)*0x28)))) & 0xFFFFF)
74+
#define USBD_SET_EP_SHORT_PACKET(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EPARSPCTL + (uint32_t)((ep)*0x28))) = (*((__IO uint32_t *) ((uint32_t)&USBD->EPARSPCTL + (uint32_t)((ep)*0x28)))) & 0x10 | 0x40)
75+
#define USBD_GET_EP_INT_EN(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EPAINTEN + (uint32_t)((ep)*0x28))))

features/unsupported/USBDevice/USBDevice/USBHAL.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ class USBHAL {
6868
virtual void suspendStateChanged(unsigned int suspended){};
6969
virtual void SOF(int frameNumber){};
7070

71+
#if defined(TARGET_NUMAKER_PFM_NUC472) || defined(TARGET_NUMAKER_PFM_M453)
72+
// NUC472/M453 USB doesn't support configuration of the same EP number for IN/OUT simultaneously.
73+
virtual bool EP1_OUT_callback(){return false;};
74+
virtual bool EP2_IN_callback(){return false;};
75+
virtual bool EP3_OUT_callback(){return false;};
76+
virtual bool EP4_IN_callback(){return false;};
77+
virtual bool EP5_OUT_callback(){return false;};
78+
virtual bool EP6_IN_callback(){return false;};
79+
#if ! (defined(TARGET_NUMAKER_PFM_M453))
80+
virtual bool EP7_OUT_callback(){return false;};
81+
virtual bool EP8_IN_callback(){return false;};
82+
virtual bool EP9_OUT_callback(){return false;};
83+
virtual bool EP10_IN_callback(){return false;};
84+
virtual bool EP11_OUT_callback(){return false;};
85+
virtual bool EP12_IN_callback(){return false;};
86+
#endif
87+
#else
7188
virtual bool EP1_OUT_callback(){return false;};
7289
virtual bool EP1_IN_callback(){return false;};
7390
virtual bool EP2_OUT_callback(){return false;};
@@ -102,6 +119,7 @@ class USBHAL {
102119
virtual bool EP15_IN_callback(){return false;};
103120
#endif
104121
#endif
122+
#endif
105123

106124
private:
107125
void usbisr(void);
@@ -110,10 +128,12 @@ class USBHAL {
110128

111129
#if defined(TARGET_LPC11UXX) || defined(TARGET_LPC11U6X) || defined(TARGET_LPC1347) || defined(TARGET_LPC1549)
112130
bool (USBHAL::*epCallback[10 - 2])(void);
113-
#elif defined(TARGET_STM32F4) && !defined(USB_STM_HAL)
131+
#elif (defined(TARGET_STM32F4) && !defined(USB_STM_HAL)) || defined(TARGET_NUMAKER_PFM_M453)
114132
bool (USBHAL::*epCallback[8 - 2])(void);
115133
#elif defined(TARGET_STM32F4) || defined(TARGET_STM32F3) || defined (TARGET_STM32F2)|| defined(TARGET_STM32L4) || defined(TARGET_STM32F7)
116134
PCD_HandleTypeDef hpcd;
135+
#elif defined(TARGET_NUMAKER_PFM_NUC472)
136+
bool (USBHAL::*epCallback[14 - 2])(void);
117137
#else
118138
bool (USBHAL::*epCallback[32 - 2])(void);
119139
#endif

0 commit comments

Comments
 (0)