[M487] Support USB device/host

pull/4950/head
ccli8 2017-08-14 15:15:31 +08:00
parent 99a8467b70
commit cacc444b73
9 changed files with 1654 additions and 36 deletions

View File

@ -57,6 +57,8 @@ typedef enum {
#include "USBEndpoints_NUC472.h"
#elif defined(TARGET_NUMAKER_PFM_M453)
#include "USBEndpoints_M453.h"
#elif defined(TARGET_M480)
#include "USBEndpoints_M480.h"
#else
#error "Unknown target type"
#endif

View File

@ -132,7 +132,7 @@ private:
bool (USBHAL::*epCallback[8 - 2])(void);
#elif defined(TARGET_STM)
PCD_HandleTypeDef hpcd;
#elif defined(TARGET_NUMAKER_PFM_NUC472)
#elif defined(TARGET_NUMAKER_PFM_NUC472) || defined(TARGET_M480)
bool (USBHAL::*epCallback[14 - 2])(void);
#else
bool (USBHAL::*epCallback[32 - 2])(void);

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,427 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined(TARGET_M480)
#include "mbed.h"
#include "USBHALHost.h"
#include "dbg.h"
#include "pinmap.h"
#define HCCA_SIZE sizeof(HCCA)
#define ED_SIZE sizeof(HCED)
#define TD_SIZE sizeof(HCTD)
#define TOTAL_SIZE (HCCA_SIZE + (MAX_ENDPOINT*ED_SIZE) + (MAX_TD*TD_SIZE))
#ifndef USBH_HcRhDescriptorA_POTPGT_Pos
#define USBH_HcRhDescriptorA_POTPGT_Pos (24)
#endif
#ifndef USBH_HcRhDescriptorA_POTPGT_Msk
#define USBH_HcRhDescriptorA_POTPGT_Msk (0xfful << USBH_HcRhDescriptorA_POTPGT_Pos)
#endif
static volatile MBED_ALIGN(256) uint8_t usb_buf[TOTAL_SIZE]; // 256 bytes aligned!
USBHALHost * USBHALHost::instHost;
USBHALHost::USBHALHost()
{
instHost = this;
memInit();
memset((void*)usb_hcca, 0, HCCA_SIZE);
for (int i = 0; i < MAX_ENDPOINT; i++) {
edBufAlloc[i] = false;
}
for (int i = 0; i < MAX_TD; i++) {
tdBufAlloc[i] = false;
}
}
void USBHALHost::init()
{
// Unlock protected registers
SYS_UnlockReg();
/* Enable IP clock */
CLK->AHBCLK |= CLK_AHBCLK_USBHCKEN_Msk | (1 << 4) | CLK_AHBCLK_HSUSBDCKEN_Msk;
/* USB Host desired input clock is 48 MHz. Set as PLL divided by 4 (192/4 = 48) */
CLK->CLKDIV0 = (CLK->CLKDIV0 & ~CLK_CLKDIV0_USBDIV_Msk) | (3 << CLK_CLKDIV0_USBDIV_Pos);
/* Enable USBD and OTG clock */
CLK->APBCLK0 |= CLK_APBCLK0_USBDCKEN_Msk | CLK_APBCLK0_OTGCKEN_Msk;
/* Configure USB to USB Host role */
SYS->USBPHY = SYS_USBPHY_HSUSBEN_Msk | SYS_USBPHY_HSUSBROLE_STD_USBH | SYS_USBPHY_USBEN_Msk | SYS_USBPHY_SBO_Msk | SYS_USBPHY_USBROLE_STD_USBH;
wait_us(20);
SYS->USBPHY |= SYS_USBPHY_HSUSBACT_Msk;
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* USB_VBUS_EN (USB 1.1 VBUS power enable pin) multi-function pin - PB.15 */
pin_function(PB_15, SYS_GPB_MFPH_PB15MFP_USB_VBUS_EN);
/* USB_VBUS_ST (USB 1.1 over-current detect pin) multi-function pin - PC.14 */
pin_function(PC_14, SYS_GPC_MFPH_PC14MFP_USB_VBUS_ST);
/* HSUSB_VBUS_EN (USB 2.0 VBUS power enable pin) multi-function pin - PB.10 */
pin_function(PB_10, SYS_GPB_MFPH_PB10MFP_HSUSB_VBUS_EN);
/* HSUSB_VBUS_ST (USB 2.0 over-current detect pin) multi-function pin - PB.11 */
pin_function(PB_11, SYS_GPB_MFPH_PB11MFP_HSUSB_VBUS_ST);
/* Configure pins for USB 1.1 port: VBUS/D+/D-/ID */
pin_function(PA_12, SYS_GPA_MFPH_PA12MFP_USB_VBUS);
pin_function(PA_13, SYS_GPA_MFPH_PA13MFP_USB_D_N);
pin_function(PA_14, SYS_GPA_MFPH_PA14MFP_USB_D_P);
pin_function(PA_15, (int) SYS_GPA_MFPH_PA15MFP_USB_OTG_ID);
SYS_LockReg();
HSUSBH->USBPCR0 = 0x160; /* enable PHY 0 */
HSUSBH->USBPCR1 = 0x520; /* enable PHY 1 */
// Overcurrent flag is low active
USBH->HcMiscControl |= USBH_HcMiscControl_OCAL_Msk;
// Disable HC interrupts
USBH->HcInterruptDisable = OR_INTR_ENABLE_MIE;
// Needed by some controllers
USBH->HcControl = 0;
// Software reset
USBH->HcCommandStatus = OR_CMD_STATUS_HCR;
while (USBH->HcCommandStatus & OR_CMD_STATUS_HCR);
// Put HC in reset state
USBH->HcControl = (USBH->HcControl & ~OR_CONTROL_HCFS) | OR_CONTROL_HC_RSET;
// HCD must wait 10ms for HC reset complete
wait_ms(100);
USBH->HcControlHeadED = 0; // Initialize Control ED list head to 0
USBH->HcBulkHeadED = 0; // Initialize Bulk ED list head to 0
USBH->HcHCCA = (uint32_t) usb_hcca;
USBH->HcFmInterval = DEFAULT_FMINTERVAL; // Frame interval = 12000 - 1
// MPS = 10,104
USBH->HcPeriodicStart = FI * 90 / 100; // 90% of frame interval
USBH->HcLSThreshold = 0x628; // Low speed threshold
// Put HC in operational state
USBH->HcControl = (USBH->HcControl & (~OR_CONTROL_HCFS)) | OR_CONTROL_HC_OPER;
// FIXME
USBH->HcRhDescriptorA = USBH->HcRhDescriptorA & ~(USBH_HcRhDescriptorA_NOCP_Msk | USBH_HcRhDescriptorA_OCPM_Msk | USBH_HcRhDescriptorA_PSM_Msk);
// Issue SetGlobalPower command
USBH->HcRhStatus = USBH_HcRhStatus_LPSC_Msk;
// Power On To Power Good Time, in 2 ms units
wait_ms(((USBH->HcRhDescriptorA & USBH_HcRhDescriptorA_POTPGT_Msk) >> USBH_HcRhDescriptorA_POTPGT_Pos) * 2);
// Clear Interrrupt Status
USBH->HcInterruptStatus |= USBH->HcInterruptStatus;
// Enable interrupts we care about
USBH->HcInterruptEnable = OR_INTR_ENABLE_MIE | OR_INTR_ENABLE_WDH | OR_INTR_ENABLE_RHSC;
NVIC_SetVector(USBH_IRQn, (uint32_t)(_usbisr));
NVIC_EnableIRQ(USBH_IRQn);
// Check for any connected devices
if (USBH->HcRhPortStatus[0] & OR_RH_PORT_CCS) {
// Device connected
wait_ms(150);
deviceConnected(0, 1, USBH->HcRhPortStatus[0] & OR_RH_PORT_LSDA);
}
// Check for any connected devices
if (USBH->HcRhPortStatus[1] & OR_RH_PORT_CCS) {
// Device connected
wait_ms(150);
deviceConnected(0, 2, USBH->HcRhPortStatus[1] & OR_RH_PORT_LSDA);
}
}
uint32_t USBHALHost::controlHeadED()
{
return USBH->HcControlHeadED;
}
uint32_t USBHALHost::bulkHeadED()
{
return USBH->HcBulkHeadED;
}
uint32_t USBHALHost::interruptHeadED()
{
// FIXME: Only support one INT ED?
return usb_hcca->IntTable[0];
}
void USBHALHost::updateBulkHeadED(uint32_t addr)
{
USBH->HcBulkHeadED = addr;
}
void USBHALHost::updateControlHeadED(uint32_t addr)
{
USBH->HcControlHeadED = addr;
}
void USBHALHost::updateInterruptHeadED(uint32_t addr)
{
// FIXME: Only support one INT ED?
usb_hcca->IntTable[0] = addr;
}
void USBHALHost::enableList(ENDPOINT_TYPE type)
{
switch(type) {
case CONTROL_ENDPOINT:
USBH->HcCommandStatus = OR_CMD_STATUS_CLF;
USBH->HcControl |= OR_CONTROL_CLE;
break;
case ISOCHRONOUS_ENDPOINT:
// FIXME
break;
case BULK_ENDPOINT:
USBH->HcCommandStatus = OR_CMD_STATUS_BLF;
USBH->HcControl |= OR_CONTROL_BLE;
break;
case INTERRUPT_ENDPOINT:
USBH->HcControl |= OR_CONTROL_PLE;
break;
}
}
bool USBHALHost::disableList(ENDPOINT_TYPE type)
{
switch(type) {
case CONTROL_ENDPOINT:
if(USBH->HcControl & OR_CONTROL_CLE) {
USBH->HcControl &= ~OR_CONTROL_CLE;
return true;
}
return false;
case ISOCHRONOUS_ENDPOINT:
// FIXME
return false;
case BULK_ENDPOINT:
if(USBH->HcControl & OR_CONTROL_BLE) {
USBH->HcControl &= ~OR_CONTROL_BLE;
return true;
}
return false;
case INTERRUPT_ENDPOINT:
if(USBH->HcControl & OR_CONTROL_PLE) {
USBH->HcControl &= ~OR_CONTROL_PLE;
return true;
}
return false;
}
return false;
}
void USBHALHost::memInit()
{
usb_hcca = (volatile HCCA *)usb_buf;
usb_edBuf = usb_buf + HCCA_SIZE;
usb_tdBuf = usb_buf + HCCA_SIZE + (MAX_ENDPOINT*ED_SIZE);
}
volatile uint8_t * USBHALHost::getED()
{
for (int i = 0; i < MAX_ENDPOINT; i++) {
if ( !edBufAlloc[i] ) {
edBufAlloc[i] = true;
return (volatile uint8_t *)(usb_edBuf + i*ED_SIZE);
}
}
perror("Could not allocate ED\r\n");
return NULL; //Could not alloc ED
}
volatile uint8_t * USBHALHost::getTD()
{
int i;
for (i = 0; i < MAX_TD; i++) {
if ( !tdBufAlloc[i] ) {
tdBufAlloc[i] = true;
return (volatile uint8_t *)(usb_tdBuf + i*TD_SIZE);
}
}
perror("Could not allocate TD\r\n");
return NULL; //Could not alloc TD
}
void USBHALHost::freeED(volatile uint8_t * ed)
{
int i;
i = (ed - usb_edBuf) / ED_SIZE;
edBufAlloc[i] = false;
}
void USBHALHost::freeTD(volatile uint8_t * td)
{
int i;
i = (td - usb_tdBuf) / TD_SIZE;
tdBufAlloc[i] = false;
}
void USBHALHost::resetRootHub()
{
// Reset port1
USBH->HcRhPortStatus[0] = OR_RH_PORT_PRS;
while (USBH->HcRhPortStatus[0] & OR_RH_PORT_PRS);
USBH->HcRhPortStatus[0] = OR_RH_PORT_PRSC;
USBH->HcRhPortStatus[1] = OR_RH_PORT_PRS;
while (USBH->HcRhPortStatus[1] & OR_RH_PORT_PRS);
USBH->HcRhPortStatus[1] = OR_RH_PORT_PRSC;
}
void USBHALHost::_usbisr(void)
{
if (instHost) {
instHost->UsbIrqhandler();
}
}
void USBHALHost::UsbIrqhandler()
{
uint32_t ints = USBH->HcInterruptStatus;
// Root hub status change interrupt
if (ints & OR_INTR_STATUS_RHSC) {
uint32_t ints_roothub = USBH->HcRhStatus;
uint32_t ints_port1 = USBH->HcRhPortStatus[0];
uint32_t ints_port2 = USBH->HcRhPortStatus[1];
// Port1: ConnectStatusChange
if (ints_port1 & OR_RH_PORT_CSC) {
if (ints_roothub & OR_RH_STATUS_DRWE) {
// When DRWE is on, Connect Status Change means a remote wakeup event.
} else {
if (ints_port1 & OR_RH_PORT_CCS) {
// Root device connected
// wait 150ms to avoid bounce
wait_ms(150);
//Hub 0 (root hub), Port 1 (count starts at 1), Low or High speed
deviceConnected(0, 1, ints_port1 & OR_RH_PORT_LSDA);
} else {
// Root device disconnected
if (!(ints & OR_INTR_STATUS_WDH)) {
usb_hcca->DoneHead = 0;
}
// wait 200ms to avoid bounce
wait_ms(200);
deviceDisconnected(0, 1, NULL, usb_hcca->DoneHead & 0xFFFFFFFE);
if (ints & OR_INTR_STATUS_WDH) {
usb_hcca->DoneHead = 0;
USBH->HcInterruptStatus = OR_INTR_STATUS_WDH;
}
}
}
USBH->HcRhPortStatus[0] = OR_RH_PORT_CSC;
}
// Port1: ConnectStatusChange
if (ints_port2 & OR_RH_PORT_CSC) {
if (ints_roothub & OR_RH_STATUS_DRWE) {
// When DRWE is on, Connect Status Change means a remote wakeup event.
} else {
if (ints_port2 & OR_RH_PORT_CCS) {
// Root device connected
// wait 150ms to avoid bounce
wait_ms(150);
//Hub 0 (root hub), Port 2 (count starts at 2), Low or High speed
deviceConnected(0, 2, ints_port2 & OR_RH_PORT_LSDA);
} else {
// Root device disconnected
if (!(ints & OR_INTR_STATUS_WDH)) {
usb_hcca->DoneHead = 0;
}
// wait 200ms to avoid bounce
wait_ms(200);
deviceDisconnected(0, 2, NULL, usb_hcca->DoneHead & 0xFFFFFFFE);
if (ints & OR_INTR_STATUS_WDH) {
usb_hcca->DoneHead = 0;
USBH->HcInterruptStatus = OR_INTR_STATUS_WDH;
}
}
}
USBH->HcRhPortStatus[1] = OR_RH_PORT_CSC;
}
// Port1: Reset completed
if (ints_port1 & OR_RH_PORT_PRSC) {
USBH->HcRhPortStatus[0] = OR_RH_PORT_PRSC;
}
// Port1: PortEnableStatusChange
if (ints_port1 & OR_RH_PORT_PESC) {
USBH->HcRhPortStatus[0] = OR_RH_PORT_PESC;
}
// Port2: PortOverCurrentIndicatorChange
if (ints_port2 & OR_RH_PORT_OCIC) {
USBH->HcRhPortStatus[1] = OR_RH_PORT_OCIC;
}
// Port2: Reset completed
if (ints_port2 & OR_RH_PORT_PRSC) {
USBH->HcRhPortStatus[1] = OR_RH_PORT_PRSC;
}
// Port2: PortEnableStatusChange
if (ints_port2 & OR_RH_PORT_PESC) {
USBH->HcRhPortStatus[1] = OR_RH_PORT_PESC;
}
USBH->HcInterruptStatus = OR_INTR_STATUS_RHSC;
}
// Writeback Done Head interrupt
if (ints & OR_INTR_STATUS_WDH) {
transferCompleted(usb_hcca->DoneHead & 0xFFFFFFFE);
USBH->HcInterruptStatus = OR_INTR_STATUS_WDH;
}
}
#endif

View File

@ -294,7 +294,7 @@ void HSUSBD_StandardRequest(void)
if ((gUsbCmd.bmRequestType & 0x80ul) == 0x80ul) { /* request data transfer direction */
/* Device to host */
switch (gUsbCmd.bRequest) {
case GET_CONFIGURATION: {
case USBD_GET_CONFIGURATION: {
/* Return current configuration setting */
HSUSBD_PrepareCtrlIn((uint8_t *)&g_hsusbd_UsbConfig, 1ul);
@ -302,14 +302,14 @@ void HSUSBD_StandardRequest(void)
HSUSBD_ENABLE_CEP_INT(HSUSBD_CEPINTEN_INTKIEN_Msk);
break;
}
case GET_DESCRIPTOR: {
case USBD_GET_DESCRIPTOR: {
if (!HSUSBD_GetDescriptor()) {
HSUSBD_CLR_CEP_INT_FLAG(HSUSBD_CEPINTSTS_INTKIF_Msk);
HSUSBD_ENABLE_CEP_INT(HSUSBD_CEPINTEN_INTKIEN_Msk);
}
break;
}
case GET_INTERFACE: {
case USBD_GET_INTERFACE: {
/* Return current interface setting */
HSUSBD_PrepareCtrlIn((uint8_t *)&g_hsusbd_UsbAltInterface, 1ul);
@ -317,7 +317,7 @@ void HSUSBD_StandardRequest(void)
HSUSBD_ENABLE_CEP_INT(HSUSBD_CEPINTEN_INTKIEN_Msk);
break;
}
case GET_STATUS: {
case USBD_GET_STATUS: {
/* Device */
if (gUsbCmd.bmRequestType == 0x80ul) {
if ((g_hsusbd_sInfo->gu8ConfigDesc[7] & 0x40ul) == 0x40ul) {
@ -350,7 +350,7 @@ void HSUSBD_StandardRequest(void)
} else {
/* Host to device */
switch (gUsbCmd.bRequest) {
case CLEAR_FEATURE: {
case USBD_CLEAR_FEATURE: {
if((gUsbCmd.wValue & 0xfful) == FEATURE_ENDPOINT_HALT) {
uint32_t epNum, i;
@ -370,7 +370,7 @@ void HSUSBD_StandardRequest(void)
HSUSBD_ENABLE_CEP_INT(HSUSBD_CEPINTEN_STSDONEIEN_Msk);
break;
}
case SET_ADDRESS: {
case USBD_SET_ADDRESS: {
g_hsusbd_UsbAddr = (uint8_t)gUsbCmd.wValue;
/* Status Stage */
HSUSBD_CLR_CEP_INT_FLAG(HSUSBD_CEPINTSTS_STSDONEIF_Msk);
@ -378,7 +378,7 @@ void HSUSBD_StandardRequest(void)
HSUSBD_ENABLE_CEP_INT(HSUSBD_CEPINTEN_STSDONEIEN_Msk);
break;
}
case SET_CONFIGURATION: {
case USBD_SET_CONFIGURATION: {
g_hsusbd_UsbConfig = (uint8_t)gUsbCmd.wValue;
g_hsusbd_Configured = (uint8_t)1ul;
/* Status stage */
@ -387,7 +387,7 @@ void HSUSBD_StandardRequest(void)
HSUSBD_ENABLE_CEP_INT(HSUSBD_CEPINTEN_STSDONEIEN_Msk);
break;
}
case SET_FEATURE: {
case USBD_SET_FEATURE: {
if ((gUsbCmd.wValue & 0x3ul) == 2ul) { /* TEST_MODE */
g_hsusbd_EnableTestMode = (uint8_t)1ul;
g_hsusbd_TestSelector = (uint8_t)(gUsbCmd.wIndex >> 8);
@ -402,7 +402,7 @@ void HSUSBD_StandardRequest(void)
HSUSBD_ENABLE_CEP_INT(HSUSBD_CEPINTEN_STSDONEIEN_Msk);
break;
}
case SET_INTERFACE: {
case USBD_SET_INTERFACE: {
g_hsusbd_UsbAltInterface = (uint8_t)gUsbCmd.wValue;
if (g_hsusbd_pfnSetInterface != NULL) {
g_hsusbd_pfnSetInterface((uint32_t)g_hsusbd_UsbAltInterface);
@ -442,11 +442,11 @@ void HSUSBD_StandardRequest(void)
void HSUSBD_UpdateDeviceState(void)
{
switch (gUsbCmd.bRequest) {
case SET_ADDRESS: {
case USBD_SET_ADDRESS: {
HSUSBD_SET_ADDR(g_hsusbd_UsbAddr);
break;
}
case SET_CONFIGURATION: {
case USBD_SET_CONFIGURATION: {
if (g_hsusbd_UsbConfig == 0ul) {
uint32_t volatile i;
/* Reset PID DATA0 */
@ -458,7 +458,7 @@ void HSUSBD_UpdateDeviceState(void)
}
break;
}
case SET_FEATURE: {
case USBD_SET_FEATURE: {
if(gUsbCmd.wValue == FEATURE_ENDPOINT_HALT) {
uint32_t idx;
idx = (uint32_t)(gUsbCmd.wIndex & 0xFul);
@ -479,7 +479,7 @@ void HSUSBD_UpdateDeviceState(void)
}
break;
}
case CLEAR_FEATURE: {
case USBD_CLEAR_FEATURE: {
if(gUsbCmd.wValue == FEATURE_ENDPOINT_HALT) {
uint32_t idx;
idx = (uint32_t)(gUsbCmd.wIndex & 0xFul);

View File

@ -117,7 +117,10 @@ extern "C"
#define SYS_USBPHY_USBROLE_STD_USBH (0x1UL << SYS_USBPHY_USBROLE_Pos) /*!< Standard USB host \hideinitializer */
#define SYS_USBPHY_USBROLE_ID_DEPH (0x2UL << SYS_USBPHY_USBROLE_Pos) /*!< ID dependent device \hideinitializer */
#define SYS_USBPHY_USBROLE_ON_THE_GO (0x3UL << SYS_USBPHY_USBROLE_Pos) /*!< On-The-Go device \hideinitializer */
#define SYS_USBPHY_HSUSBROLE_STD_USBD (0x0UL << SYS_USBPHY_HSUSBROLE_Pos) /*!< Standard USB device \hideinitializer */
#define SYS_USBPHY_HSUSBROLE_STD_USBH (0x1UL << SYS_USBPHY_HSUSBROLE_Pos) /*!< Standard USB host \hideinitializer */
#define SYS_USBPHY_HSUSBROLE_ID_DEPH (0x2UL << SYS_USBPHY_HSUSBROLE_Pos) /*!< ID dependent device \hideinitializer */
#define SYS_USBPHY_HSUSBROLE_ON_THE_GO (0x3UL << SYS_USBPHY_HSUSBROLE_Pos) /*!< On-The-Go device \hideinitializer */
/*---------------------------------------------------------------------------------------------------------*/
/* Multi-Function constant definitions. */

View File

@ -267,7 +267,7 @@ void USBD_StandardRequest(void)
if((g_usbd_SetupPacket[0] & 0x80ul) == 0x80ul) { /* request data transfer direction */
/* Device to host */
switch(g_usbd_SetupPacket[1]) {
case GET_CONFIGURATION: {
case USBD_GET_CONFIGURATION: {
/* Return current configuration setting */
/* Data stage */
addr = USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP0);
@ -278,12 +278,12 @@ void USBD_StandardRequest(void)
USBD_PrepareCtrlOut(0, 0ul);
break;
}
case GET_DESCRIPTOR: {
case USBD_GET_DESCRIPTOR: {
USBD_GetDescriptor();
USBD_PrepareCtrlOut(0, 0ul); /* For status stage */
break;
}
case GET_INTERFACE: {
case USBD_GET_INTERFACE: {
/* Return current interface setting */
/* Data stage */
addr = USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP0);
@ -294,7 +294,7 @@ void USBD_StandardRequest(void)
USBD_PrepareCtrlOut(0, 0ul);
break;
}
case GET_STATUS: {
case USBD_GET_STATUS: {
/* Device */
if(g_usbd_SetupPacket[0] == 0x80ul) {
uint8_t u8Tmp;
@ -342,7 +342,7 @@ void USBD_StandardRequest(void)
} else {
/* Host to device */
switch(g_usbd_SetupPacket[1]) {
case CLEAR_FEATURE: {
case USBD_CLEAR_FEATURE: {
if(g_usbd_SetupPacket[2] == FEATURE_ENDPOINT_HALT) {
uint32_t epNum, i;
@ -363,7 +363,7 @@ void USBD_StandardRequest(void)
USBD_SET_PAYLOAD_LEN(EP0, 0ul);
break;
}
case SET_ADDRESS: {
case USBD_SET_ADDRESS: {
g_usbd_UsbAddr = g_usbd_SetupPacket[2];
/* Status Stage */
USBD_SET_DATA1(EP0);
@ -371,7 +371,7 @@ void USBD_StandardRequest(void)
break;
}
case SET_CONFIGURATION: {
case USBD_SET_CONFIGURATION: {
g_usbd_UsbConfig = g_usbd_SetupPacket[2];
if(g_usbd_pfnSetConfigCallback) {
@ -383,7 +383,7 @@ void USBD_StandardRequest(void)
USBD_SET_PAYLOAD_LEN(EP0, 0ul);
break;
}
case SET_FEATURE: {
case USBD_SET_FEATURE: {
if( (g_usbd_SetupPacket[0] & 0xFul) == 0ul ) { /* 0: device */
if((g_usbd_SetupPacket[2] == 3ul) && (g_usbd_SetupPacket[3] == 0ul)) { /* 3: HNP enable */
OTG->CTL |= (OTG_CTL_HNPREQEN_Msk | OTG_CTL_BUSREQ_Msk);
@ -401,7 +401,7 @@ void USBD_StandardRequest(void)
break;
}
case SET_INTERFACE: {
case USBD_SET_INTERFACE: {
g_usbd_UsbAltInterface = g_usbd_SetupPacket[2];
if(g_usbd_pfnSetInterface != NULL) {
g_usbd_pfnSetInterface(g_usbd_UsbAltInterface);
@ -491,7 +491,7 @@ void USBD_CtrlIn(void)
}
} else {
/* In ACK for Set address */
if((g_usbd_SetupPacket[0] == REQ_STANDARD) && (g_usbd_SetupPacket[1] == SET_ADDRESS)) {
if((g_usbd_SetupPacket[0] == REQ_STANDARD) && (g_usbd_SetupPacket[1] == USBD_SET_ADDRESS)) {
addr = USBD_GET_ADDR();
if((addr != g_usbd_UsbAddr) && (addr == 0ul)) {
USBD_SET_ADDR(g_usbd_UsbAddr);

View File

@ -69,17 +69,17 @@ extern const S_USBD_INFO_T gsInfo;
#define REQ_VENDOR 0x40ul
/* USB Standard Request */
#define GET_STATUS 0x00ul
#define CLEAR_FEATURE 0x01ul
#define SET_FEATURE 0x03ul
#define SET_ADDRESS 0x05ul
#define GET_DESCRIPTOR 0x06ul
#define SET_DESCRIPTOR 0x07ul
#define GET_CONFIGURATION 0x08ul
#define SET_CONFIGURATION 0x09ul
#define GET_INTERFACE 0x0Aul
#define SET_INTERFACE 0x0Bul
#define SYNC_FRAME 0x0Cul
#define USBD_GET_STATUS 0x00ul
#define USBD_CLEAR_FEATURE 0x01ul
#define USBD_SET_FEATURE 0x03ul
#define USBD_SET_ADDRESS 0x05ul
#define USBD_GET_DESCRIPTOR 0x06ul
#define USBD_SET_DESCRIPTOR 0x07ul
#define USBD_GET_CONFIGURATION 0x08ul
#define USBD_SET_CONFIGURATION 0x09ul
#define USBD_GET_INTERFACE 0x0Aul
#define USBD_SET_INTERFACE 0x0Bul
#define USBD_SYNC_FRAME 0x0Cul
/* USB Descriptor Type */
#define DESC_DEVICE 0x01ul