Skip to content

Commit e7361eb

Browse files
authored
Merge pull request #3365 from OpenNuvoton/nuvoton_usb
[NUC472/M453] Support USB device
2 parents 2f6f3c6 + 5fe2274 commit e7361eb

File tree

28 files changed

+1542
-55
lines changed

28 files changed

+1542
-55
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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2015-2016 Nuvoton
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#define NU_MAX_EPX_BUFSIZE 4096
17+
#define NU_EP2EPL(ep) ((ep) >> 1)
18+
#define NU_EP2EPH(ep) (((ep) >> 1) + 1)
19+
#define NU_EPL2EPH(ep) ((ep) + 1)
20+
#define NU_EPH2EPL(ep) ((ep) - 1)
21+
#define NU_EP_DIR_Pos 0
22+
#define NU_EP_DIR_Msk (1 << NU_EP_DIR_Pos)
23+
#define NU_EP_DIR_OUT 0
24+
#define NU_EP_DIR_IN 1
25+
26+
#define NU_EP_TYPE(ep) (((ep) & NU_EP_TYPE_Msk) >> NU_EP_TYPE_Pos)
27+
#define NU_EP_NUM(ep) (((ep) & NU_EP_NUM_Msk) >> NU_EP_NUM_Pos)
28+
#define NU_EP_DIR(ep) (((ep) & NU_EP_DIR_Msk) >> NU_EP_DIR_Pos)
29+
#define NU_EP_NUM_DIR(ep) ((NU_EP_NUM(ep) << 1) | NU_EP_DIR(ep))
30+
31+
#define NUMBER_OF_PHYSICAL_ENDPOINTS 8
32+
#define EP0OUT (0)
33+
#define EP0IN (1)
34+
#define EP1OUT (2)
35+
#define EP1IN (3)
36+
#define EP2OUT (4)
37+
#define EP2IN (5)
38+
#define EP3OUT (6)
39+
#define EP3IN (7)
40+
#define EP4OUT (8)
41+
#define EP4IN (9)
42+
#define EP5OUT (10)
43+
#define EP5IN (11)
44+
#define EP6OUT (12)
45+
#define EP6IN (13)
46+
47+
/* Maximum Packet sizes */
48+
#define MAX_PACKET_SIZE_EP0 64
49+
#define MAX_PACKET_SIZE_EP1 64
50+
#define MAX_PACKET_SIZE_EP2 64
51+
#define MAX_PACKET_SIZE_EP3 0x60
52+
#define MAX_PACKET_SIZE_EP4 64
53+
#define MAX_PACKET_SIZE_EP5 64
54+
#define MAX_PACKET_SIZE_EP6 64
55+
#define MAX_PACKET_SIZE_EP7 64
56+
57+
/* Generic endpoints - intended to be portable accross devices */
58+
/* and be suitable for simple USB devices. */
59+
60+
/* Bulk endpoints */
61+
#define EPBULK_OUT EP5OUT
62+
#define EPBULK_IN EP6IN
63+
#define EPBULK_OUT_callback EP5_OUT_callback
64+
#define EPBULK_IN_callback EP6_IN_callback
65+
/* Interrupt endpoints */
66+
#define EPINT_OUT EP1OUT
67+
#define EPINT_IN EP2IN
68+
#define EPINT_OUT_callback EP1_OUT_callback
69+
#define EPINT_IN_callback EP2_IN_callback
70+
/* Isochronous endpoints */
71+
#define EPISO_OUT EP3OUT
72+
#define EPISO_IN EP4IN
73+
#define EPISO_OUT_callback EP3_OUT_callback
74+
#define EPISO_IN_callback EP4_IN_callback
75+
76+
#define MAX_PACKET_SIZE_EPBULK 64
77+
#define MAX_PACKET_SIZE_EPINT 64
78+
#define MAX_PACKET_SIZE_EPISO 1023
79+
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2015-2016 Nuvoton
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#define NU_MAX_EPX_BUFSIZE 4096
17+
#define NU_EP2EPL(ep) ((ep) >> 1)
18+
#define NU_EP2EPH(ep) (((ep) >> 1) - 1)
19+
#define NU_EPX2EP(ep) ((ep == CEP) ? EP0OUT : ((ep) - EPA + EP1OUT))
20+
#define NU_EPL2EPH(ep) ((ep) - 1)
21+
#define NU_EPH2EPL(ep) ((ep) + 1)
22+
#define NU_EP_DIR_Pos 0
23+
#define NU_EP_DIR_Msk (1 << NU_EP_DIR_Pos)
24+
#define NU_EP_DIR_OUT 0
25+
#define NU_EP_DIR_IN 1
26+
27+
#define NU_EP_TYPE(ep) (((ep) & NU_EP_TYPE_Msk) >> NU_EP_TYPE_Pos)
28+
#define NU_EP_NUM(ep) (((ep) & NU_EP_NUM_Msk) >> NU_EP_NUM_Pos)
29+
#define NU_EP_DIR(ep) (((ep) & NU_EP_DIR_Msk) >> NU_EP_DIR_Pos)
30+
#define NU_EP_NUM_DIR(ep) ((NU_EP_NUM(ep) << 1) | NU_EP_DIR(ep))
31+
32+
#define NUMBER_OF_PHYSICAL_ENDPOINTS 12
33+
34+
#define EP0OUT (0)
35+
#define EP0IN (1)
36+
#define EP1OUT (2)
37+
#define EP1IN (3)
38+
#define EP2OUT (4)
39+
#define EP2IN (5)
40+
#define EP3OUT (6)
41+
#define EP3IN (7)
42+
#define EP4OUT (8)
43+
#define EP4IN (9)
44+
#define EP5OUT (10)
45+
#define EP5IN (11)
46+
#define EP6OUT (12)
47+
#define EP6IN (13)
48+
49+
/* Maximum Packet sizes */
50+
#define MAX_PACKET_SIZE_EP0 64
51+
#define MAX_PACKET_SIZE_EP1 64
52+
#define MAX_PACKET_SIZE_EP2 64
53+
#define MAX_PACKET_SIZE_EP3 0x60
54+
#define MAX_PACKET_SIZE_EP4 64
55+
#define MAX_PACKET_SIZE_EP5 64
56+
#define MAX_PACKET_SIZE_EP6 64
57+
#define MAX_PACKET_SIZE_EP7 64
58+
#define MAX_PACKET_SIZE_EP8 64
59+
#define MAX_PACKET_SIZE_EP9 64
60+
#define MAX_PACKET_SIZE_EP10 64
61+
#define MAX_PACKET_SIZE_EP11 64
62+
63+
/* Generic endpoints - intended to be portable accross devices */
64+
/* and be suitable for simple USB devices. */
65+
66+
/* Bulk endpoints */
67+
#define EPBULK_OUT EP5OUT
68+
#define EPBULK_IN EP6IN
69+
#define EPBULK_OUT_callback EP5_OUT_callback
70+
#define EPBULK_IN_callback EP6_IN_callback
71+
/* Interrupt endpoints */
72+
#define EPINT_OUT EP1OUT
73+
#define EPINT_IN EP2IN
74+
#define EPINT_OUT_callback EP1_OUT_callback
75+
#define EPINT_IN_callback EP2_IN_callback
76+
/* Isochronous endpoints */
77+
#define EPISO_OUT EP3OUT
78+
#define EPISO_IN EP4IN
79+
#define EPISO_OUT_callback EP3_OUT_callback
80+
#define EPISO_IN_callback EP4_IN_callback
81+
82+
#define MAX_PACKET_SIZE_EPBULK 64
83+
#define MAX_PACKET_SIZE_EPINT 64
84+
#define MAX_PACKET_SIZE_EPISO 1023
85+
86+
#define USBD_GET_EP_MAX_PAYLOAD(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EPAMPS + (uint32_t)((ep)*0x28))))
87+
#define USBD_GET_EP_DATA_COUNT(ep) ((*((__IO uint32_t *) ((uint32_t)&USBD->EPADATCNT + (uint32_t)((ep)*0x28)))) & 0xFFFFF)
88+
#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)
89+
#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)