Skip to content

M487: Support USB device/host #4950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions features/unsupported/USBDevice/USBDevice/USBEndpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ typedef enum {
#include "USBEndpoints_Maxim.h"
#elif defined(TARGET_EFM32GG_STK3700) || defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32HG_STK3400)
#include "USBEndpoints_EFM32.h"
#elif defined(TARGET_NUMAKER_PFM_NUC472)
#elif defined(TARGET_NUC472)
#include "USBEndpoints_NUC472.h"
#elif defined(TARGET_NUMAKER_PFM_M453)
#elif defined(TARGET_M451)
#include "USBEndpoints_M453.h"
#elif defined(TARGET_M480)
#include "USBEndpoints_M480.h"
#else
#error "Unknown target type"
#endif
Expand Down
10 changes: 5 additions & 5 deletions features/unsupported/USBDevice/USBDevice/USBHAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ class USBHAL {
virtual void suspendStateChanged(unsigned int suspended){};
virtual void SOF(int frameNumber){};

#if defined(TARGET_NUMAKER_PFM_NUC472) || defined(TARGET_NUMAKER_PFM_M453)
// NUC472/M453 USB doesn't support configuration of the same EP number for IN/OUT simultaneously.
#if defined(TARGET_NUC472) || defined(TARGET_M451)
// NUC472/M451 USB doesn't support configuration of the same EP number for IN/OUT simultaneously.
virtual bool EP1_OUT_callback(){return false;};
virtual bool EP2_IN_callback(){return false;};
virtual bool EP3_OUT_callback(){return false;};
virtual bool EP4_IN_callback(){return false;};
virtual bool EP5_OUT_callback(){return false;};
virtual bool EP6_IN_callback(){return false;};
#if ! (defined(TARGET_NUMAKER_PFM_M453))
#if ! (defined(TARGET_M451))
virtual bool EP7_OUT_callback(){return false;};
virtual bool EP8_IN_callback(){return false;};
virtual bool EP9_OUT_callback(){return false;};
Expand Down Expand Up @@ -128,11 +128,11 @@ class USBHAL {

#if defined(TARGET_LPC11UXX) || defined(TARGET_LPC11U6X) || defined(TARGET_LPC1347) || defined(TARGET_LPC1549)
bool (USBHAL::*epCallback[10 - 2])(void);
#elif (defined(TARGET_STM32F4) && !defined(USB_STM_HAL)) || defined(TARGET_NUMAKER_PFM_M453)
#elif (defined(TARGET_STM32F4) && !defined(USB_STM_HAL)) || defined(TARGET_M451)
bool (USBHAL::*epCallback[8 - 2])(void);
#elif defined(TARGET_STM)
PCD_HandleTypeDef hpcd;
#elif defined(TARGET_NUMAKER_PFM_NUC472)
#elif defined(TARGET_NUC472) || defined(TARGET_M480)
bool (USBHAL::*epCallback[14 - 2])(void);
#else
bool (USBHAL::*epCallback[32 - 2])(void);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#if defined(TARGET_NUMAKER_PFM_M453)
#if defined(TARGET_M451)

#include "USBHAL.h"
#include "M451Series.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

#if (MBED_CONF_TARGET_USB_DEVICE_HSUSBD == 0)
#define NU_MAX_EPX_BUFSIZE 4096
#else
#define NU_MAX_EPX_BUFSIZE 4096
#endif

#define NU_EP2EPL(ep) ((ep) >> 1)

#if (MBED_CONF_TARGET_USB_DEVICE_HSUSBD == 0)
#define NU_EP2EPH(ep) (((ep) >> 1) + 1)
#define NU_EPL2EPH(ep) ((ep) + 1)
#define NU_EPH2EPL(ep) ((ep) - 1)
#define NUMBER_OF_PHYSICAL_ENDPOINTS 8
#else
#define NU_EP2EPH(ep) (((ep) >> 1) - 1)
#define NU_EPX2EP(ep) ((ep == CEP) ? EP0OUT : ((ep) - EPA + EP1OUT))
#define NU_EPL2EPH(ep) ((ep) - 1)
#define NU_EPH2EPL(ep) ((ep) + 1)
#define NUMBER_OF_PHYSICAL_ENDPOINTS 12
#endif

#define NU_EP_DIR_Pos 0
#define NU_EP_DIR_Msk (1 << NU_EP_DIR_Pos)
#define NU_EP_DIR_OUT 0
#define NU_EP_DIR_IN 1

#define NU_EP_TYPE(ep) (((ep) & NU_EP_TYPE_Msk) >> NU_EP_TYPE_Pos)
#define NU_EP_NUM(ep) (((ep) & NU_EP_NUM_Msk) >> NU_EP_NUM_Pos)
#define NU_EP_DIR(ep) (((ep) & NU_EP_DIR_Msk) >> NU_EP_DIR_Pos)
#define NU_EP_NUM_DIR(ep) ((NU_EP_NUM(ep) << 1) | NU_EP_DIR(ep))

#define EP0OUT (0)
#define EP0IN (1)
#define EP1OUT (2)
#define EP1IN (3)
#define EP2OUT (4)
#define EP2IN (5)
#define EP3OUT (6)
#define EP3IN (7)
#define EP4OUT (8)
#define EP4IN (9)
#define EP5OUT (10)
#define EP5IN (11)
#define EP6OUT (12)
#define EP6IN (13)

/* Maximum Packet sizes */
#define MAX_PACKET_SIZE_EP0 64
#define MAX_PACKET_SIZE_EP1 64
#define MAX_PACKET_SIZE_EP2 64
#define MAX_PACKET_SIZE_EP3 0x60
#define MAX_PACKET_SIZE_EP4 64
#define MAX_PACKET_SIZE_EP5 64
#define MAX_PACKET_SIZE_EP6 64
#define MAX_PACKET_SIZE_EP7 64

#if (MBED_CONF_TARGET_USB_DEVICE_HSUSBD == 1)
#define MAX_PACKET_SIZE_EP8 64
#define MAX_PACKET_SIZE_EP9 64
#define MAX_PACKET_SIZE_EP10 64
#define MAX_PACKET_SIZE_EP11 64
#endif

/* Generic endpoints - intended to be portable accross devices */
/* and be suitable for simple USB devices. */

/* Bulk endpoints */
#define EPBULK_OUT EP5OUT
#define EPBULK_IN EP6IN
#define EPBULK_OUT_callback EP5_OUT_callback
#define EPBULK_IN_callback EP6_IN_callback
/* Interrupt endpoints */
#define EPINT_OUT EP1OUT
#define EPINT_IN EP2IN
#define EPINT_OUT_callback EP1_OUT_callback
#define EPINT_IN_callback EP2_IN_callback
/* Isochronous endpoints */
#define EPISO_OUT EP3OUT
#define EPISO_IN EP4IN
#define EPISO_OUT_callback EP3_OUT_callback
#define EPISO_IN_callback EP4_IN_callback

#define MAX_PACKET_SIZE_EPBULK 64
#define MAX_PACKET_SIZE_EPINT 64
#define MAX_PACKET_SIZE_EPISO 1023

#if (MBED_CONF_TARGET_USB_DEVICE_HSUSBD == 1)
#define HSUSBD_GET_EP_MAX_PAYLOAD(ep) HSUSBD->EP[ep].EPMPS
#define HSUSBD_GET_EP_DATA_COUNT(ep) (HSUSBD->EP[ep].EPDATCNT & 0xFFFFF)
#define HSUSBD_SET_EP_SHORT_PACKET(ep) HSUSBD->EP[ep].EPRSPCTL = ((HSUSBD->EP[ep].EPRSPCTL & 0x10) | 0x40)
#define HSUSBD_GET_EP_INT_EN(ep) HSUSBD->EP[ep].EPINTEN
#endif
Loading