![]() |
M471M/R1/S BSP V3.01.000
The Board Support Package for M4521
|
Macros | |
#define | Maximum(a, b) ((a)>(b) ? (a) : (b)) |
Compare two input numbers and return maximum one. More... | |
#define | Minimum(a, b) ((a)<(b) ? (a) : (b)) |
Compare two input numbers and return minimum one. More... | |
#define | USBD_ENABLE_USB() ((uint32_t)(USBD->ATTR |= (USBD_USB_EN|USBD_PHY_EN))) |
Enable USB. More... | |
#define | USBD_DISABLE_USB() ((uint32_t)(USBD->ATTR &= ~USBD_USB_EN)) |
Disable USB. More... | |
#define | USBD_ENABLE_PHY() ((uint32_t)(USBD->ATTR |= USBD_PHY_EN)) |
Enable USB PHY. More... | |
#define | USBD_DISABLE_PHY() ((uint32_t)(USBD->ATTR &= ~USBD_PHY_EN)) |
Disable USB PHY. More... | |
#define | USBD_SET_SE0() ((uint32_t)(USBD->SE0 |= USBD_DRVSE0)) |
Enable SE0. Force USB PHY transceiver to drive SE0. More... | |
#define | USBD_CLR_SE0() ((uint32_t)(USBD->SE0 &= ~USBD_DRVSE0)) |
Disable SE0. More... | |
#define | USBD_SET_ADDR(addr) (USBD->FADDR = (addr)) |
Set USB device address. More... | |
#define | USBD_GET_ADDR() ((uint32_t)(USBD->FADDR)) |
Get USB device address. More... | |
#define | USBD_ENABLE_INT(intr) (USBD->INTEN |= (intr)) |
Enable USB interrupt function. More... | |
#define | USBD_GET_INT_FLAG() ((uint32_t)(USBD->INTSTS)) |
Get interrupt status. More... | |
#define | USBD_CLR_INT_FLAG(flag) (USBD->INTSTS = (flag)) |
Clear USB interrupt flag. More... | |
#define | USBD_GET_EP_FLAG() ((uint32_t)(USBD->EPSTS)) |
Get endpoint status. More... | |
#define | USBD_GET_BUS_STATE() ((uint32_t)(USBD->ATTR & 0xf)) |
Get USB bus state. More... | |
#define | USBD_IS_ATTACHED() ((uint32_t)(USBD->VBUSDET & USBD_VBUSDET_VBUSDET_Msk)) |
Check cable connection state. More... | |
#define | USBD_STOP_TRANSACTION(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) |= USBD_CFGP_CLRRDY_Msk) |
Stop USB transaction of the specified endpoint ID. More... | |
#define | USBD_SET_DATA1(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) |= USBD_CFG_DSQSYNC_Msk) |
Set USB DATA1 PID for the specified endpoint ID. More... | |
#define | USBD_SET_DATA0(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) &= (~USBD_CFG_DSQSYNC_Msk)) |
Set USB DATA0 PID for the specified endpoint ID. More... | |
#define | USBD_SET_PAYLOAD_LEN(ep, size) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4))) = (size)) |
Set USB payload size (IN data) More... | |
#define | USBD_GET_PAYLOAD_LEN(ep) ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4)))) |
Get USB payload size (OUT data) More... | |
#define | USBD_CONFIG_EP(ep, config) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) = (config)) |
Configure endpoint. More... | |
#define | USBD_SET_EP_BUF_ADDR(ep, offset) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4))) = (offset)) |
Set USB endpoint buffer. More... | |
#define | USBD_GET_EP_BUF_ADDR(ep) ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4)))) |
Get the offset of the specified USB endpoint buffer. More... | |
#define | USBD_SET_EP_STALL(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) |= USBD_CFGP_SSTALL_Msk) |
Set USB endpoint stall state. More... | |
#define | USBD_CLR_EP_STALL(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) &= ~USBD_CFGP_SSTALL_Msk) |
Clear USB endpoint stall state. More... | |
#define | USBD_GET_EP_STALL(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) & USBD_CFGP_SSTALL_Msk) |
Get USB endpoint stall state. More... | |
Typedefs | |
typedef void(* | VENDOR_REQ) (void) |
typedef void(* | CLASS_REQ) (void) |
typedef void(* | SET_INTERFACE_REQ) (void) |
typedef void(* | SET_CONFIG_CB) (void) |
Functions | |
static __INLINE void | USBD_MemCopy (uint8_t *dest, uint8_t *src, int32_t size) |
To support byte access between USB SRAM and system SRAM. More... | |
static __INLINE void | USBD_SetStall (uint8_t epnum) |
Set USB endpoint stall state. More... | |
static __INLINE void | USBD_ClearStall (uint8_t epnum) |
Clear USB endpoint stall state. More... | |
static __INLINE uint32_t | USBD_GetStall (uint8_t epnum) |
Get USB endpoint stall state. More... | |
void | USBD_Open (const S_USBD_INFO_T *param, CLASS_REQ pfnClassReq, SET_INTERFACE_REQ pfnSetInterface) |
This function makes USBD module to be ready to use. More... | |
void | USBD_Start (void) |
This function makes USB host to recognize the device. More... | |
void | USBD_GetSetupPacket (uint8_t *buf) |
Get the received SETUP packet. More... | |
void | USBD_ProcessSetupPacket (void) |
Process SETUP packet. More... | |
void | USBD_StandardRequest (void) |
Process standard request. More... | |
void | USBD_PrepareCtrlIn (uint8_t *pu8Buf, uint32_t u32Size) |
Prepare the first Control IN pipe. More... | |
void | USBD_CtrlIn (void) |
Repeat Control IN pipe. More... | |
void | USBD_PrepareCtrlOut (uint8_t *pu8Buf, uint32_t u32Size) |
Prepare the first Control OUT pipe. More... | |
void | USBD_CtrlOut (void) |
Repeat Control OUT pipe. More... | |
void | USBD_SwReset (void) |
Reset software flags. More... | |
void | USBD_SetVendorRequest (VENDOR_REQ pfnVendorReq) |
USBD Set Vendor Request. More... | |
void | USBD_SetConfigCallback (SET_CONFIG_CB pfnSetConfigCallback) |
The callback function which called when get SET CONFIGURATION request. More... | |
void | USBD_LockEpStall (uint32_t u32EpBitmap) |
EP stall lock function to avoid stall clear by USB SET FEATURE request. More... | |
void | USBD_GetDescriptor (void) |
Process GetDescriptor request. More... | |
Variables | |
const uint8_t * | s_usbd_info::gu8DevDesc |
const uint8_t * | s_usbd_info::gu8ConfigDesc |
const uint8_t ** | s_usbd_info::gu8StringDesc |
const uint8_t ** | s_usbd_info::gu8HidReportDesc |
const uint32_t * | s_usbd_info::gu32HidReportSize |
const uint32_t * | s_usbd_info::gu32ConfigHidDescIdx |
volatile uint8_t | g_usbd_RemoteWakeupEn |
uint8_t | g_usbd_SetupPacket [8] = {0} |
volatile uint8_t | g_usbd_RemoteWakeupEn = 0 |
const S_USBD_INFO_T * | g_usbd_sInfo |
VENDOR_REQ | g_usbd_pfnVendorRequest = NULL |
CLASS_REQ | g_usbd_pfnClassRequest = NULL |
SET_INTERFACE_REQ | g_usbd_pfnSetInterface = NULL |
SET_CONFIG_CB | g_usbd_pfnSetConfigCallback = NULL |
uint32_t | g_u32EpStallLock = 0 |
#define Maximum | ( | a, | |
b | |||
) | ((a)>(b) ? (a) : (b)) |
#define Minimum | ( | a, | |
b | |||
) | ((a)<(b) ? (a) : (b)) |
#define USBD_CLR_EP_STALL | ( | ep | ) | (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) &= ~USBD_CFGP_SSTALL_Msk) |
#define USBD_CLR_INT_FLAG | ( | flag | ) | (USBD->INTSTS = (flag)) |
Clear USB interrupt flag.
[in] | flag | The combination of the specified interrupt flags. Each bit corresponds to a interrupt source. This parameter decides which interrupt flags will be cleared. (USBD_INTSTS_WAKEUP, USBD_INTSTS_FLDET, USBD_INTSTS_BUS, USBD_INTSTS_USB) |
Clear USB related interrupt flags specified by flag parameter.
#define USBD_CLR_SE0 | ( | ) | ((uint32_t)(USBD->SE0 &= ~USBD_DRVSE0)) |
#define USBD_CONFIG_EP | ( | ep, | |
config | |||
) | (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) = (config)) |
Configure endpoint.
[in] | ep | The USB endpoint ID. M471M/R1/S supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
[in] | config | The USB configuration. |
This macro will write config parameter to USB_CFGx register of specified endpoint ID.
#define USBD_DISABLE_PHY | ( | ) | ((uint32_t)(USBD->ATTR &= ~USBD_PHY_EN)) |
#define USBD_DISABLE_USB | ( | ) | ((uint32_t)(USBD->ATTR &= ~USBD_USB_EN)) |
#define USBD_ENABLE_INT | ( | intr | ) | (USBD->INTEN |= (intr)) |
Enable USB interrupt function.
[in] | intr | The combination of the specified interrupt enable bits. Each bit corresponds to a interrupt enable bit. This parameter decides which interrupts will be enabled. (USBD_INT_WAKEUP, USBD_INT_FLDET, USBD_INT_USB, USBD_INT_BUS) |
Enable USB related interrupt functions specified by intr parameter.
#define USBD_ENABLE_PHY | ( | ) | ((uint32_t)(USBD->ATTR |= USBD_PHY_EN)) |
#define USBD_ENABLE_USB | ( | ) | ((uint32_t)(USBD->ATTR |= (USBD_USB_EN|USBD_PHY_EN))) |
#define USBD_GET_ADDR | ( | ) | ((uint32_t)(USBD->FADDR)) |
#define USBD_GET_BUS_STATE | ( | ) | ((uint32_t)(USBD->ATTR & 0xf)) |
Get USB bus state.
None |
Return USB_ATTR[3:0] for USB bus events.
#define USBD_GET_EP_BUF_ADDR | ( | ep | ) | ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4)))) |
Get the offset of the specified USB endpoint buffer.
[in] | ep | The USB endpoint ID. M471M/R1/S supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
This macro will return the SRAM offset of the specified endpoint ID.
#define USBD_GET_EP_FLAG | ( | ) | ((uint32_t)(USBD->EPSTS)) |
#define USBD_GET_EP_STALL | ( | ep | ) | (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) & USBD_CFGP_SSTALL_Msk) |
Get USB endpoint stall state.
[in] | ep | The USB endpoint ID. M471M/R1/S supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
0 | USB endpoint is not stalled. |
Others | USB endpoint is stalled. |
Get USB endpoint stall state of the specified endpoint ID.
#define USBD_GET_INT_FLAG | ( | ) | ((uint32_t)(USBD->INTSTS)) |
#define USBD_GET_PAYLOAD_LEN | ( | ep | ) | ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4)))) |
#define USBD_IS_ATTACHED | ( | ) | ((uint32_t)(USBD->VBUSDET & USBD_VBUSDET_VBUSDET_Msk)) |
#define USBD_SET_ADDR | ( | addr | ) | (USBD->FADDR = (addr)) |
#define USBD_SET_DATA0 | ( | ep | ) | (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) &= (~USBD_CFG_DSQSYNC_Msk)) |
Set USB DATA0 PID for the specified endpoint ID.
[in] | ep | The USB endpoint ID. M471M/R1/S supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
Clear DSQ_SYNC bit of USB_CFGx register to specify the DATA0 PID for the following IN token transaction. Base on this setting, hardware will toggle PID between DATA0 and DATA1 automatically for IN token transactions.
#define USBD_SET_DATA1 | ( | ep | ) | (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) |= USBD_CFG_DSQSYNC_Msk) |
Set USB DATA1 PID for the specified endpoint ID.
[in] | ep | The USB endpoint ID. M471M/R1/S supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
Set DSQ_SYNC bit of USB_CFGx register to specify the DATA1 PID for the following IN token transaction. Base on this setting, hardware will toggle PID between DATA0 and DATA1 automatically for IN token transactions.
#define USBD_SET_EP_BUF_ADDR | ( | ep, | |
offset | |||
) | (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4))) = (offset)) |
#define USBD_SET_EP_STALL | ( | ep | ) | (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) |= USBD_CFGP_SSTALL_Msk) |
Set USB endpoint stall state.
[in] | ep | The USB endpoint ID. M471M/R1/S supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
Set USB endpoint stall state for the specified endpoint ID. Endpoint will respond STALL token automatically.
#define USBD_SET_PAYLOAD_LEN | ( | ep, | |
size | |||
) | (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4))) = (size)) |
Set USB payload size (IN data)
[in] | ep | The USB endpoint ID. M471M/R1/S supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
[in] | size | The transfer length. |
This macro will write the transfer length to USB_MXPLDx register for IN data transaction.
#define USBD_SET_SE0 | ( | ) | ((uint32_t)(USBD->SE0 |= USBD_DRVSE0)) |
#define USBD_STOP_TRANSACTION | ( | ep | ) | (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) |= USBD_CFGP_CLRRDY_Msk) |
Stop USB transaction of the specified endpoint ID.
[in] | ep | The USB endpoint ID. M471M/R1/S supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
Write 1 to CLRRDY bit of USB_CFGPx register to stop USB transaction of the specified endpoint ID.
typedef void(* CLASS_REQ) (void) |
typedef void(* SET_CONFIG_CB) (void) |
typedef void(* SET_INTERFACE_REQ) (void) |
typedef void(* VENDOR_REQ) (void) |
|
static |
void USBD_CtrlIn | ( | void | ) |
void USBD_CtrlOut | ( | void | ) |
void USBD_GetDescriptor | ( | void | ) |
void USBD_GetSetupPacket | ( | uint8_t * | buf | ) |
|
static |
void USBD_LockEpStall | ( | uint32_t | u32EpBitmap | ) |
EP stall lock function to avoid stall clear by USB SET FEATURE request.
[in] | u32EpBitmap | Use bitmap to select which endpoints will be locked |
This function is used to lock relative endpoint to avoid stall clear by SET FEATURE requst. If ep stall locked, user needs to reset USB device or re-configure device to clear it.
|
static |
To support byte access between USB SRAM and system SRAM.
[in] | dest | Destination pointer. |
[in] | src | Source pointer. |
[in] | size | Byte count. |
This function will copy the number of data specified by size and src parameters to the address specified by dest parameter.
Definition at line 520 of file usbd.h.
void USBD_Open | ( | const S_USBD_INFO_T * | param, |
CLASS_REQ | pfnClassReq, | ||
SET_INTERFACE_REQ | pfnSetInterface | ||
) |
This function makes USBD module to be ready to use.
[in] | param | The structure of USBD information. |
[in] | pfnClassReq | USB Class request callback function. |
[in] | pfnSetInterface | USB Set Interface request callback function. |
This function will enable USB controller, USB PHY transceiver and pull-up resistor of USB_D+ pin. USB PHY will drive SE0 to bus.
void USBD_PrepareCtrlIn | ( | uint8_t * | pu8Buf, |
uint32_t | u32Size | ||
) |
Prepare the first Control IN pipe.
[in] | pu8Buf | The pointer of data sent to USB host. |
[in] | u32Size | The IN transfer size. |
Prepare data for Control IN transfer.
Definition at line 525 of file usbd.c.
void USBD_PrepareCtrlOut | ( | uint8_t * | pu8Buf, |
uint32_t | u32Size | ||
) |
void USBD_ProcessSetupPacket | ( | void | ) |
void USBD_SetConfigCallback | ( | SET_CONFIG_CB | pfnSetConfigCallback | ) |
The callback function which called when get SET CONFIGURATION request.
[in] | pfnSetConfigCallback | Callback function pointer for SET CONFIGURATION request |
This function is used to set the callback function which will be called at SET CONFIGURATION request.
|
static |
void USBD_SetVendorRequest | ( | VENDOR_REQ | pfnVendorReq | ) |
void USBD_StandardRequest | ( | void | ) |
void USBD_Start | ( | void | ) |
void USBD_SwReset | ( | void | ) |
uint32_t g_u32EpStallLock = 0 |
SET_CONFIG_CB g_usbd_pfnSetConfigCallback = NULL |
SET_INTERFACE_REQ g_usbd_pfnSetInterface = NULL |
VENDOR_REQ g_usbd_pfnVendorRequest = NULL |
|
extern |
volatile uint8_t g_usbd_RemoteWakeupEn = 0 |
const S_USBD_INFO_T* g_usbd_sInfo |
const uint32_t* s_usbd_info::gu32ConfigHidDescIdx |
const uint32_t* s_usbd_info::gu32HidReportSize |
const uint8_t* s_usbd_info::gu8ConfigDesc |
const uint8_t* s_usbd_info::gu8DevDesc |
const uint8_t** s_usbd_info::gu8HidReportDesc |