mirror of https://github.com/ARMmbed/mbed-os.git
TARGET_STM : USB FS device support on ST HAL
parent
182c311fbd
commit
26bd467995
|
@ -0,0 +1,325 @@
|
|||
/* Copyright (c) 2010-2011 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#if (defined (USB_STM_HAL) && defined(TARGET_STM32F4)) \
|
||||
|| defined(TARGET_STM32F2) || defined (TARGET_STM32F7) || defined (TARGET_STM32F3) || defined (TARGET_STM32L4)
|
||||
|
||||
#include "USBHAL.h"
|
||||
#include "pinmap.h"
|
||||
/* mbed endpoint definition to hal definition */
|
||||
#define EP_ADDR(ep) (((ep) >> 1)|((ep) & 1) << 7)
|
||||
/* from hal definition to mbed definition */
|
||||
#define ADDR_EPIN(ep) (((ep) << 1) | 1)
|
||||
#define ADDR_EPOUT(ep) (((ep) << 1))
|
||||
/* id to detect if rx buffer is used or not */
|
||||
|
||||
#include "USBHAL_STM_TARGET.h"
|
||||
|
||||
|
||||
/* this call at device reception completion on a Out Enpoint */
|
||||
void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||
{
|
||||
USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
|
||||
USBHAL *obj= priv->inst;
|
||||
uint8_t endpoint = ADDR_EPOUT(epnum);
|
||||
priv->epComplete[endpoint] = 1;
|
||||
/* -2 endpoint 0 In out are not in call back list */
|
||||
if (epnum) {
|
||||
bool (USBHAL::*func)(void) = priv->epCallback[endpoint-2];
|
||||
(obj->*func)();
|
||||
} else {
|
||||
void (USBHAL::*func)(void) = priv->ep0_out;
|
||||
(obj->*func)();
|
||||
}
|
||||
}
|
||||
|
||||
/* this is call at device transmission completion on In endpoint */
|
||||
void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||
{
|
||||
USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
|
||||
USBHAL *obj= priv->inst;
|
||||
uint8_t endpoint = ADDR_EPIN(epnum);
|
||||
priv->epComplete[endpoint] = 1;
|
||||
/* -2 endpoint 0 In out are not in call back list */
|
||||
if (epnum) {
|
||||
bool (USBHAL::*func)(void) = priv->epCallback[endpoint-2];
|
||||
(obj->*func)();
|
||||
} else {
|
||||
void (USBHAL::*func)(void) = priv->ep0_in;
|
||||
(obj->*func)();
|
||||
}
|
||||
}
|
||||
/* This is call at device set up reception */
|
||||
void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
|
||||
USBHAL *obj= priv->inst;
|
||||
void (USBHAL::*func)(void)=priv->ep0_setup;
|
||||
void (USBHAL::*func1)(void)=priv->ep0_read;
|
||||
(obj->*func)();
|
||||
(obj->*func1)();
|
||||
}
|
||||
|
||||
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
|
||||
USBHAL *obj= priv->inst;
|
||||
void (USBHAL::*func)(unsigned int suspended) = priv->suspend_change;
|
||||
(obj->*func)(1);
|
||||
}
|
||||
|
||||
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
|
||||
USBHAL *obj= priv->inst;
|
||||
void (USBHAL::*func)(unsigned int suspended) = priv->suspend_change;
|
||||
(obj->*func)(0);
|
||||
}
|
||||
|
||||
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
|
||||
USBHAL *obj= priv->inst;
|
||||
void (USBHAL::*func)(unsigned int suspended) = priv->connect_change;
|
||||
(obj->*func)(1);
|
||||
}
|
||||
|
||||
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
|
||||
USBHAL *obj= priv->inst;
|
||||
void (USBHAL::*func)(unsigned int suspended) = priv->connect_change;
|
||||
(obj->*func)(0);
|
||||
}
|
||||
|
||||
void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
|
||||
USBHAL *obj= priv->inst;
|
||||
unsigned int i;
|
||||
for(i=0;i<hpcd->Init.dev_endpoints;i++) {
|
||||
priv->epComplete[2*i]=0;
|
||||
HAL_PCD_EP_Close(hpcd,EP_ADDR(2*i));
|
||||
HAL_PCD_EP_Flush(hpcd,EP_ADDR(2*i));
|
||||
priv->epComplete[2*i+1]=0;
|
||||
HAL_PCD_EP_Close(hpcd,EP_ADDR(2*i+1));
|
||||
HAL_PCD_EP_Flush(hpcd,EP_ADDR(2*i+1));
|
||||
|
||||
}
|
||||
void (USBHAL::*func)(void)=priv->bus_reset;
|
||||
bool (USBHAL::*ep_realise)(uint8_t endpoint, uint32_t maxPacket, uint32_t flags) = priv->ep_realise;
|
||||
(obj->*func)();
|
||||
(obj->*ep_realise)(EP0IN, MAX_PACKET_SIZE_EP0,0);
|
||||
(obj->*ep_realise)(EP0OUT, MAX_PACKET_SIZE_EP0,0);
|
||||
}
|
||||
|
||||
|
||||
/* hal pcd handler , used for STM32 HAL PCD Layer */
|
||||
|
||||
uint32_t USBHAL::endpointReadcore(uint8_t endpoint, uint8_t *buffer) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
USBHAL::~USBHAL(void) {
|
||||
USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData);
|
||||
HAL_PCD_DeInit(&hpcd);
|
||||
delete HALPriv;
|
||||
}
|
||||
|
||||
void USBHAL::connect(void) {
|
||||
NVIC_EnableIRQ(USBHAL_IRQn);
|
||||
}
|
||||
|
||||
void USBHAL::disconnect(void) {
|
||||
NVIC_DisableIRQ(USBHAL_IRQn);
|
||||
}
|
||||
|
||||
void USBHAL::configureDevice(void) {
|
||||
// Not needed
|
||||
}
|
||||
|
||||
void USBHAL::unconfigureDevice(void) {
|
||||
// Not needed
|
||||
}
|
||||
|
||||
void USBHAL::setAddress(uint8_t address) {
|
||||
HAL_PCD_SetAddress(&hpcd, address);
|
||||
EP0write(0, 0);
|
||||
}
|
||||
|
||||
bool USBHAL::realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t flags) {
|
||||
uint32_t epIndex = EP_ADDR(endpoint);
|
||||
uint32_t type;
|
||||
uint32_t len;
|
||||
HAL_StatusTypeDef ret;
|
||||
switch (endpoint) {
|
||||
case EP0IN:
|
||||
case EP0OUT:
|
||||
type = 0;
|
||||
break;
|
||||
case EPISO_IN:
|
||||
case EPISO_OUT:
|
||||
type = 1;
|
||||
break;
|
||||
case EPBULK_IN:
|
||||
case EPBULK_OUT:
|
||||
type = 2;
|
||||
break;
|
||||
case EPINT_IN:
|
||||
case EPINT_OUT:
|
||||
type = 3;
|
||||
break;
|
||||
}
|
||||
if (maxPacket > MAXTRANSFER_SIZE) return false;
|
||||
if (epIndex & 0x80) {
|
||||
len = HAL_PCDEx_GetTxFiFo(&hpcd,epIndex & 0x7f);
|
||||
MBED_ASSERT(len >= maxPacket);
|
||||
}
|
||||
ret = HAL_PCD_EP_Open(&hpcd, epIndex, maxPacket, type);
|
||||
MBED_ASSERT(ret!=HAL_BUSY);
|
||||
return (ret == HAL_OK) ? true:false;
|
||||
}
|
||||
|
||||
// read setup packet
|
||||
void USBHAL::EP0setup(uint8_t *buffer) {
|
||||
memcpy(buffer, hpcd.Setup, MAX_PACKET_SIZE_SETUP);
|
||||
memset(hpcd.Setup,0,MAX_PACKET_SIZE_SETUP);
|
||||
}
|
||||
|
||||
void USBHAL::EP0readStage(void) {
|
||||
}
|
||||
|
||||
void USBHAL::EP0read(void) {
|
||||
USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)hpcd.pData;
|
||||
uint32_t epIndex = EP_ADDR(EP0OUT);
|
||||
uint8_t *pBuf = (uint8_t *)HALPriv->pBufRx0;
|
||||
HAL_StatusTypeDef ret;
|
||||
HALPriv->epComplete[EP0OUT] = 2;
|
||||
ret = HAL_PCD_EP_Receive(&hpcd, epIndex, pBuf, MAX_PACKET_SIZE_EP0 );
|
||||
MBED_ASSERT(ret!=HAL_BUSY);
|
||||
|
||||
}
|
||||
|
||||
uint32_t USBHAL::EP0getReadResult(uint8_t *buffer) {
|
||||
USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)hpcd.pData;
|
||||
uint32_t length = (uint32_t) HAL_PCD_EP_GetRxCount(&hpcd, 0);
|
||||
HALPriv->epComplete[EP0OUT] = 0;
|
||||
if (length) {
|
||||
uint8_t *buff = (uint8_t *)HALPriv->pBufRx0;
|
||||
memcpy(buffer, buff, length);
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
void USBHAL::EP0write(uint8_t *buffer, uint32_t size) {
|
||||
/* check that endpoint maximum size is not exceeding TX fifo */
|
||||
MBED_ASSERT(hpcd.IN_ep[0].maxpacket >= size);
|
||||
endpointWrite(EP0IN, buffer, size);
|
||||
}
|
||||
|
||||
void USBHAL::EP0getWriteResult(void) {
|
||||
|
||||
}
|
||||
|
||||
void USBHAL::EP0stall(void) {
|
||||
stallEndpoint(EP0IN);
|
||||
}
|
||||
|
||||
EP_STATUS USBHAL::endpointRead(uint8_t endpoint, uint32_t maximumSize) {
|
||||
USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData);
|
||||
uint32_t epIndex = EP_ADDR(endpoint);
|
||||
uint8_t* pBuf = (uint8_t *)HALPriv->pBufRx;
|
||||
HAL_StatusTypeDef ret;
|
||||
// clean reception end flag before requesting reception
|
||||
HALPriv->epComplete[endpoint] = 2;
|
||||
ret = HAL_PCD_EP_Receive(&hpcd, epIndex, pBuf, maximumSize);
|
||||
MBED_ASSERT(ret!=HAL_BUSY);
|
||||
return EP_PENDING;
|
||||
}
|
||||
|
||||
EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t * buffer, uint32_t *bytesRead) {
|
||||
USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData);
|
||||
if (HALPriv->epComplete[endpoint]==0) {
|
||||
/* no reception possible !!! */
|
||||
bytesRead = 0;
|
||||
return EP_COMPLETED;
|
||||
}else if ((HALPriv->epComplete[endpoint]!=1))
|
||||
return EP_PENDING;
|
||||
uint32_t epIndex = EP_ADDR(endpoint);
|
||||
uint8_t *buff = (uint8_t *)HALPriv->pBufRx;
|
||||
uint32_t length = (uint32_t) HAL_PCD_EP_GetRxCount(&hpcd, epIndex);
|
||||
memcpy(buffer, buff, length);
|
||||
*bytesRead = length;
|
||||
HALPriv->epComplete[endpoint]= 0;
|
||||
return EP_COMPLETED;
|
||||
}
|
||||
|
||||
EP_STATUS USBHAL::endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size) {
|
||||
USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData);
|
||||
uint32_t epIndex = EP_ADDR(endpoint);
|
||||
HAL_StatusTypeDef ret;
|
||||
// clean transmission end flag before requesting transmission
|
||||
HALPriv->epComplete[endpoint] = 2;
|
||||
ret = HAL_PCD_EP_Transmit(&hpcd, epIndex, data, size);
|
||||
MBED_ASSERT(ret!=HAL_BUSY);
|
||||
// update the status
|
||||
if (ret != HAL_OK) return EP_INVALID;
|
||||
// fix me return is too simple
|
||||
return EP_PENDING;
|
||||
}
|
||||
|
||||
EP_STATUS USBHAL::endpointWriteResult(uint8_t endpoint) {
|
||||
USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData);
|
||||
if (HALPriv->epComplete[endpoint] == 1)
|
||||
return EP_COMPLETED;
|
||||
return EP_PENDING;
|
||||
}
|
||||
|
||||
void USBHAL::stallEndpoint(uint8_t endpoint) {
|
||||
USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData);
|
||||
HAL_StatusTypeDef ret;
|
||||
HALPriv->epComplete[endpoint] = 0;
|
||||
ret = HAL_PCD_EP_SetStall(&hpcd, EP_ADDR(endpoint));
|
||||
MBED_ASSERT(ret!=HAL_BUSY);
|
||||
}
|
||||
|
||||
void USBHAL::unstallEndpoint(uint8_t endpoint) {
|
||||
HAL_StatusTypeDef ret;
|
||||
ret = HAL_PCD_EP_ClrStall(&hpcd, EP_ADDR(endpoint));
|
||||
MBED_ASSERT(ret!=HAL_BUSY);
|
||||
|
||||
}
|
||||
|
||||
bool USBHAL::getEndpointStallState(uint8_t endpoint) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void USBHAL::remoteWakeup(void) {
|
||||
}
|
||||
|
||||
|
||||
void USBHAL::_usbisr(void) {
|
||||
instance->usbisr();
|
||||
}
|
||||
|
||||
|
||||
void USBHAL::usbisr(void) {
|
||||
|
||||
HAL_PCD_IRQHandler(&instance->hpcd);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
/* Copyright (c) 2016 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef USBHAL_STM32F303ZE_H
|
||||
#define USBHAL_STM32F303ZE_H
|
||||
#define USBHAL_IRQn USB_LP_CAN_RX0_IRQn
|
||||
/* must be multiple of 4 bytes */
|
||||
#define NB_ENDPOINT 8
|
||||
#define MAXTRANSFER_SIZE 0x200
|
||||
#define FIFO_USB_RAM_SIZE (MAXTRANSFER_SIZE+MAX_PACKET_SIZE_EP0+MAX_PACKET_SIZE_EP1+MAX_PACKET_SIZE_EP2+MAX_PACKET_SIZE_EP3)
|
||||
#if (FIFO_USB_RAM_SIZE > 0x500)
|
||||
#error "FIFO dimensioning incorrect"
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
USBHAL *inst;
|
||||
void (USBHAL::*bus_reset)(void);
|
||||
void (USBHAL::*sof)(int frame);
|
||||
void (USBHAL::*connect_change)(unsigned int connected);
|
||||
void (USBHAL::*suspend_change)(unsigned int suspended);
|
||||
void (USBHAL::*ep0_setup)(void);
|
||||
void (USBHAL::*ep0_in)(void);
|
||||
void (USBHAL::*ep0_out)(void);
|
||||
void (USBHAL::*ep0_read)(void);
|
||||
bool (USBHAL::*ep_realise)(uint8_t endpoint, uint32_t maxPacket, uint32_t flags);
|
||||
bool (USBHAL::*epCallback[6])(void);
|
||||
uint8_t epComplete[2*NB_ENDPOINT];
|
||||
/* memorize dummy buffer used for reception */
|
||||
uint32_t pBufRx[MAXTRANSFER_SIZE>>2];
|
||||
uint32_t pBufRx0[MAX_PACKET_SIZE_EP0>>2];
|
||||
gpio_t usb_switch;
|
||||
}USBHAL_Private_t;
|
||||
|
||||
uint32_t HAL_PCDEx_GetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo)
|
||||
{
|
||||
return 1024;
|
||||
}
|
||||
|
||||
void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state){
|
||||
USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
|
||||
gpio_write(&(priv->usb_switch),state);
|
||||
}
|
||||
|
||||
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) {
|
||||
USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
|
||||
USBHAL *obj= priv->inst;
|
||||
uint32_t sofnum = (hpcd->Instance->FNR) & USB_FNR_FN;
|
||||
void (USBHAL::*func)(int frame) = priv->sof;
|
||||
/* fix me call with same frame number */
|
||||
(obj->*func)(sofnum);
|
||||
}
|
||||
|
||||
USBHAL * USBHAL::instance;
|
||||
|
||||
USBHAL::USBHAL(void) {
|
||||
/* init parameter */
|
||||
USBHAL_Private_t *HALPriv = new(USBHAL_Private_t);
|
||||
hpcd.Instance = USB;
|
||||
/* initialized Init to zero (constructor does not zero initialized the
|
||||
* area */
|
||||
/* initialized all field of init including 0 field */
|
||||
/* constructor does not fill with zero */
|
||||
memset(&hpcd.Init, 0, sizeof(hpcd.Init));
|
||||
hpcd.Init.dev_endpoints = NB_ENDPOINT;
|
||||
hpcd.Init.ep0_mps = MAX_PACKET_SIZE_EP0;
|
||||
hpcd.Init.phy_itface = PCD_PHY_EMBEDDED;
|
||||
hpcd.Init.Sof_enable = 1;
|
||||
hpcd.Init.speed = PCD_SPEED_FULL;
|
||||
/* pass instance for usage inside call back */
|
||||
HALPriv->inst = this;
|
||||
HALPriv->bus_reset = &USBHAL::busReset;
|
||||
HALPriv->suspend_change = &USBHAL::suspendStateChanged;
|
||||
HALPriv->connect_change = &USBHAL::connectStateChanged;
|
||||
HALPriv->sof = &USBHAL::SOF;
|
||||
HALPriv->ep0_setup = &USBHAL::EP0setupCallback;
|
||||
HALPriv->ep_realise = &USBHAL::realiseEndpoint;
|
||||
HALPriv->ep0_in = &USBHAL::EP0in;
|
||||
HALPriv->ep0_out = &USBHAL::EP0out;
|
||||
HALPriv->ep0_read = &USBHAL::EP0read;
|
||||
hpcd.pData = (void*)HALPriv;
|
||||
HALPriv->epCallback[0] = &USBHAL::EP1_OUT_callback;
|
||||
HALPriv->epCallback[1] = &USBHAL::EP1_IN_callback;
|
||||
HALPriv->epCallback[2] = &USBHAL::EP2_OUT_callback;
|
||||
HALPriv->epCallback[3] = &USBHAL::EP2_IN_callback;
|
||||
HALPriv->epCallback[4] = &USBHAL::EP3_OUT_callback;
|
||||
HALPriv->epCallback[5] = &USBHAL::EP3_IN_callback;
|
||||
instance = this;
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/* Configure USB DM pin. This is optional, and maintained only for user guidance. */
|
||||
pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF14_USB));
|
||||
pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF14_USB));
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
gpio_init_out(&HALPriv->usb_switch,PG_6);
|
||||
/* Enable USB Clock */
|
||||
__HAL_RCC_USB_CLK_ENABLE();
|
||||
/* Enable SYSCFG Clock */
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
hpcd.State = HAL_PCD_STATE_RESET;
|
||||
HAL_PCD_Init(&hpcd);
|
||||
/* hardcoded size of FIFO according definition*/
|
||||
HAL_PCDEx_PMAConfig(&hpcd , 0x00 , PCD_SNG_BUF, 0x30);
|
||||
HAL_PCDEx_PMAConfig(&hpcd , 0x80 , PCD_SNG_BUF, 0x70);
|
||||
#if 1
|
||||
HAL_PCDEx_PMAConfig(&hpcd , 0x3, PCD_DBL_BUF, 0x018000b0);
|
||||
#else
|
||||
HAL_PCDEx_PMAConfig(&hpcd , 0x3, PCD_SNG_BUF, 0x180);
|
||||
#endif
|
||||
HAL_PCDEx_PMAConfig(&hpcd , 0x83, PCD_SNG_BUF, 0xb0);
|
||||
NVIC_SetVector(USBHAL_IRQn,(uint32_t)&_usbisr);
|
||||
NVIC_SetPriority(USBHAL_IRQn, 1);
|
||||
HAL_PCD_Start(&hpcd);
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,145 @@
|
|||
/* Copyright (c) 2016 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef USBHAL_STM32L476VG
|
||||
#define USBHAL_STM32L476VG
|
||||
|
||||
#define USBHAL_IRQn OTG_FS_IRQn
|
||||
|
||||
|
||||
#define NB_ENDPOINT 4
|
||||
/* must be multiple of 4 bytes */
|
||||
#define MAXTRANSFER_SIZE 0x200
|
||||
#define FIFO_USB_RAM_SIZE (MAXTRANSFER_SIZE+MAX_PACKET_SIZE_EP0+MAX_PACKET_SIZE_EP1+MAX_PACKET_SIZE_EP2+MAX_PACKET_SIZE_EP3)
|
||||
#if (FIFO_USB_RAM_SIZE > 0x500)
|
||||
#error "FIFO dimensioning incorrect"
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
USBHAL *inst;
|
||||
void (USBHAL::*bus_reset)(void);
|
||||
void (USBHAL::*sof)(int frame);
|
||||
void (USBHAL::*connect_change)(unsigned int connected);
|
||||
void (USBHAL::*suspend_change)(unsigned int suspended);
|
||||
void (USBHAL::*ep0_setup)(void);
|
||||
void (USBHAL::*ep0_in)(void);
|
||||
void (USBHAL::*ep0_out)(void);
|
||||
void (USBHAL::*ep0_read)(void);
|
||||
bool (USBHAL::*ep_realise)(uint8_t endpoint, uint32_t maxPacket, uint32_t flags);
|
||||
bool (USBHAL::*epCallback[2*NB_ENDPOINT-2])(void);
|
||||
uint8_t epComplete[8];
|
||||
/* memorize dummy buffer used for reception */
|
||||
uint32_t pBufRx[MAXTRANSFER_SIZE>>2];
|
||||
uint32_t pBufRx0[MAX_PACKET_SIZE_EP0>>2];
|
||||
}USBHAL_Private_t;
|
||||
|
||||
uint32_t HAL_PCDEx_GetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo)
|
||||
{
|
||||
uint32_t len;
|
||||
if (fifo == 0) len = hpcd->Instance->DIEPTXF0_HNPTXFSIZ>>16;
|
||||
else
|
||||
len = hpcd->Instance->DIEPTXF[fifo - 1] >> 16;
|
||||
return len*4;
|
||||
}
|
||||
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) {
|
||||
USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
|
||||
USBHAL *obj= priv->inst;
|
||||
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||
uint32_t sofnum = (USBx_DEVICE->DSTS & USB_OTG_DSTS_FNSOF) >> 8;
|
||||
void (USBHAL::*func)(int frame) = priv->sof;
|
||||
/* fix me call with same frame number */
|
||||
(obj->*func)(sofnum);
|
||||
}
|
||||
|
||||
USBHAL * USBHAL::instance;
|
||||
|
||||
USBHAL::USBHAL(void) {
|
||||
/* init parameter */
|
||||
USBHAL_Private_t *HALPriv = new(USBHAL_Private_t);
|
||||
/* initialized all field of init including 0 field */
|
||||
/* constructor does not fill with zero */
|
||||
hpcd.Instance = USB_OTG_FS;
|
||||
/* initialized all field of init including 0 field */
|
||||
/* constructor does not fill with zero */
|
||||
memset(&hpcd.Init, 0, sizeof(hpcd.Init));
|
||||
hpcd.Init.dev_endpoints = NB_ENDPOINT;
|
||||
hpcd.Init.ep0_mps = MAX_PACKET_SIZE_EP0;
|
||||
hpcd.Init.phy_itface = PCD_PHY_EMBEDDED;
|
||||
hpcd.Init.Sof_enable = 1;
|
||||
hpcd.Init.speed = PCD_SPEED_FULL;
|
||||
/* pass instance for usage inside call back */
|
||||
HALPriv->inst = this;
|
||||
HALPriv->bus_reset = &USBHAL::busReset;
|
||||
HALPriv->suspend_change = &USBHAL::suspendStateChanged;
|
||||
HALPriv->connect_change = &USBHAL::connectStateChanged;
|
||||
HALPriv->sof = &USBHAL::SOF;
|
||||
HALPriv->ep0_setup = &USBHAL::EP0setupCallback;
|
||||
HALPriv->ep_realise = &USBHAL::realiseEndpoint;
|
||||
HALPriv->ep0_in = &USBHAL::EP0in;
|
||||
HALPriv->ep0_out = &USBHAL::EP0out;
|
||||
HALPriv->ep0_read = &USBHAL::EP0read;
|
||||
hpcd.pData = (void*)HALPriv;
|
||||
HALPriv->epCallback[0] = &USBHAL::EP1_OUT_callback;
|
||||
HALPriv->epCallback[1] = &USBHAL::EP1_IN_callback;
|
||||
HALPriv->epCallback[2] = &USBHAL::EP2_OUT_callback;
|
||||
HALPriv->epCallback[3] = &USBHAL::EP2_IN_callback;
|
||||
HALPriv->epCallback[4] = &USBHAL::EP3_OUT_callback;
|
||||
HALPriv->epCallback[5] = &USBHAL::EP3_IN_callback;
|
||||
instance = this;
|
||||
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
|
||||
HAL_PWREx_EnableVddUSB();
|
||||
/* Configure USB VBUS GPIO */
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
|
||||
/* Configure USB FS GPIOs */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
/* Configure DM DP Pins */
|
||||
pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
|
||||
pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
|
||||
|
||||
/* Configure VBUS Pin */
|
||||
pin_function(PC_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
|
||||
|
||||
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
||||
|
||||
hpcd.State = HAL_PCD_STATE_RESET;
|
||||
|
||||
HAL_PCD_Init(&hpcd);
|
||||
/* 1.25kbytes */
|
||||
/* min value 16 (= 16 x 4 bytes) */
|
||||
/* max value 256 (= 1K bytes ) */
|
||||
/* maximum sum is 0x140 */
|
||||
HAL_PCDEx_SetRxFiFo(&hpcd, (MAXTRANSFER_SIZE/4));
|
||||
/* bulk/int 64 bytes in FS */
|
||||
HAL_PCDEx_SetTxFiFo(&hpcd, 0, (MAX_PACKET_SIZE_EP0/4)+1);
|
||||
/* bulk/int bytes in FS */
|
||||
HAL_PCDEx_SetTxFiFo(&hpcd, 1, (MAX_PACKET_SIZE_EP1/4));
|
||||
HAL_PCDEx_SetTxFiFo(&hpcd, 2, (MAX_PACKET_SIZE_EP2/4));
|
||||
/* ISOchronous */
|
||||
HAL_PCDEx_SetTxFiFo(&hpcd, 3, (MAX_PACKET_SIZE_EP3/4));
|
||||
|
||||
NVIC_SetVector(USBHAL_IRQn,(uint32_t)&_usbisr);
|
||||
NVIC_SetPriority( USBHAL_IRQn, 1);
|
||||
|
||||
HAL_PCD_Start(&hpcd);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,133 @@
|
|||
/* Copyright (c) 2016 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef USBHAL_STM32_144_64
|
||||
#define USBHAL_STM32_144_64
|
||||
|
||||
#define USBHAL_IRQn OTG_FS_IRQn
|
||||
/* must be multiple of 4 bytes */
|
||||
#define NB_ENDPOINT 4
|
||||
#define MAXTRANSFER_SIZE 0x200
|
||||
#define FIFO_USB_RAM_SIZE (MAXTRANSFER_SIZE+MAX_PACKET_SIZE_EP0+MAX_PACKET_SIZE_EP1+MAX_PACKET_SIZE_EP2+MAX_PACKET_SIZE_EP3)
|
||||
#if (FIFO_USB_RAM_SIZE > 0x500)
|
||||
#error "FIFO dimensioning incorrect"
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
USBHAL *inst;
|
||||
void (USBHAL::*bus_reset)(void);
|
||||
void (USBHAL::*sof)(int frame);
|
||||
void (USBHAL::*connect_change)(unsigned int connected);
|
||||
void (USBHAL::*suspend_change)(unsigned int suspended);
|
||||
void (USBHAL::*ep0_setup)(void);
|
||||
void (USBHAL::*ep0_in)(void);
|
||||
void (USBHAL::*ep0_out)(void);
|
||||
void (USBHAL::*ep0_read)(void);
|
||||
bool (USBHAL::*ep_realise)(uint8_t endpoint, uint32_t maxPacket, uint32_t flags);
|
||||
bool (USBHAL::*epCallback[2*NB_ENDPOINT-2])(void);
|
||||
/* memorize dummy buffer used for reception */
|
||||
uint32_t pBufRx[MAXTRANSFER_SIZE>>2];
|
||||
uint32_t pBufRx0[MAX_PACKET_SIZE_EP0>>2];
|
||||
uint8_t epComplete[2*NB_ENDPOINT];
|
||||
}USBHAL_Private_t;
|
||||
|
||||
uint32_t HAL_PCDEx_GetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo)
|
||||
{
|
||||
uint32_t len;
|
||||
if (fifo == 0) len = hpcd->Instance->DIEPTXF0_HNPTXFSIZ>>16;
|
||||
else
|
||||
len = hpcd->Instance->DIEPTXF[fifo - 1] >> 16;
|
||||
return len*4;
|
||||
}
|
||||
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
|
||||
USBHAL *obj= priv->inst;
|
||||
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||
uint32_t sofnum = (USBx_DEVICE->DSTS & USB_OTG_DSTS_FNSOF) >> 8;
|
||||
void (USBHAL::*func)(int frame) = priv->sof;
|
||||
/* fix me call with same frame number */
|
||||
(obj->*func)(sofnum);
|
||||
}
|
||||
|
||||
|
||||
USBHAL * USBHAL::instance;
|
||||
|
||||
USBHAL::USBHAL(void) {
|
||||
/* init parameter */
|
||||
USBHAL_Private_t *HALPriv = new(USBHAL_Private_t);
|
||||
hpcd.Instance = USB_OTG_FS;
|
||||
memset(&hpcd.Init, 0, sizeof(hpcd.Init));
|
||||
hpcd.Init.dev_endpoints = NB_ENDPOINT;
|
||||
hpcd.Init.ep0_mps = MAX_PACKET_SIZE_EP0;
|
||||
hpcd.Init.phy_itface = PCD_PHY_EMBEDDED;
|
||||
hpcd.Init.Sof_enable = 1;
|
||||
|
||||
hpcd.Init.speed = PCD_SPEED_FULL;
|
||||
//hpcd.Init.vbus_sensing_enable = 0;
|
||||
//hpcd.Init.lpm_enable = 0;
|
||||
/* pass instance for usage inside call back */
|
||||
HALPriv->inst = this;
|
||||
HALPriv->bus_reset = &USBHAL::busReset;
|
||||
HALPriv->suspend_change = &USBHAL::suspendStateChanged;
|
||||
HALPriv->connect_change = &USBHAL::connectStateChanged;
|
||||
HALPriv->sof = &USBHAL::SOF;
|
||||
HALPriv->ep0_setup = &USBHAL::EP0setupCallback;
|
||||
HALPriv->ep_realise = &USBHAL::realiseEndpoint;
|
||||
HALPriv->ep0_in = &USBHAL::EP0in;
|
||||
HALPriv->ep0_out = &USBHAL::EP0out;
|
||||
HALPriv->ep0_read = &USBHAL::EP0read;
|
||||
hpcd.pData = (void*)HALPriv;
|
||||
HALPriv->epCallback[0] = &USBHAL::EP1_OUT_callback;
|
||||
HALPriv->epCallback[1] = &USBHAL::EP1_IN_callback;
|
||||
HALPriv->epCallback[2] = &USBHAL::EP2_OUT_callback;
|
||||
HALPriv->epCallback[3] = &USBHAL::EP2_IN_callback;
|
||||
HALPriv->epCallback[4] = &USBHAL::EP3_OUT_callback;
|
||||
HALPriv->epCallback[5] = &USBHAL::EP3_IN_callback;
|
||||
instance = this;
|
||||
// Enable power and clocking
|
||||
/* board 144 pin all similar */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
pin_function(PA_8, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
|
||||
pin_function(PA_9, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF10_OTG_FS));
|
||||
pin_function(PA_10, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS));
|
||||
pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
|
||||
pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
|
||||
|
||||
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
hpcd.State = HAL_PCD_STATE_RESET;
|
||||
HAL_PCD_Init(&hpcd);
|
||||
/* 1.25kbytes */
|
||||
/* min value 16 (= 16 x 4 bytes) */
|
||||
/* max value 256 (= 1K bytes ) */
|
||||
/* maximum sum is 0x140 */
|
||||
HAL_PCDEx_SetRxFiFo(&hpcd, (MAXTRANSFER_SIZE/4));
|
||||
/* bulk/int 64 bytes in FS */
|
||||
HAL_PCDEx_SetTxFiFo(&hpcd, 0, (MAX_PACKET_SIZE_EP0/4)+1);
|
||||
/* bulk/int bytes in FS */
|
||||
HAL_PCDEx_SetTxFiFo(&hpcd, 1, (MAX_PACKET_SIZE_EP1/4));
|
||||
HAL_PCDEx_SetTxFiFo(&hpcd, 2, (MAX_PACKET_SIZE_EP2/4));
|
||||
/* ISOchronous */
|
||||
HAL_PCDEx_SetTxFiFo(&hpcd, 3, (MAX_PACKET_SIZE_EP3/4));
|
||||
NVIC_SetVector(USBHAL_IRQn, (uint32_t)&_usbisr);
|
||||
NVIC_SetPriority(USBHAL_IRQn, 1);
|
||||
HAL_PCD_Start(&hpcd);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/* Copyright (c) 2016 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifdef TARGET_STM32F303ZE
|
||||
#include "USBHAL_STM32F303ZE.h"
|
||||
#endif
|
||||
#if defined(TARGET_STM32F429ZI) || defined(TARGET_STM32F446ZE) || defined(TARGET_STM32F207ZG) \
|
||||
|| defined(TARGET_STM32F767ZI) || defined (TARGET_STM32F746ZG) || defined(TARGET_STM32F411RE) \
|
||||
|| defined(TARGET_STM32F407VG) || defined(TARGET_STM32F401RE)
|
||||
#include "USBHAL_STM_144_64pins.h"
|
||||
#endif
|
||||
#ifdef TARGET_STM32L476VG
|
||||
#include "USBHAL_STM32L476VG.h"
|
||||
#endif
|
|
@ -43,8 +43,10 @@ typedef enum {
|
|||
#include "USBEndpoints_LPC11U.h"
|
||||
#elif defined(TARGET_KL25Z) | defined(TARGET_KL26Z) | defined(TARGET_KL27Z) | defined(TARGET_KL43Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D50M) | defined(TARGET_K64F) | defined(TARGET_K22F) | defined(TARGET_TEENSY3_1)
|
||||
#include "USBEndpoints_KL25Z.h"
|
||||
#elif defined (TARGET_STM32F4)
|
||||
#elif !defined(USB_STM_HAL) && defined(TARGET_STM32F4)
|
||||
#include "USBEndpoints_STM32F4.h"
|
||||
#elif defined (TARGET_STM32F4) || defined (TARGET_STM32F2) || defined (TARGET_STM32F7) || defined (TARGET_STM32F3) || defined(TARGET_STM32L4)
|
||||
#include "USBEndpoints_STM32.h"
|
||||
#elif defined (TARGET_RZ_A1H) || defined (TARGET_VK_RZ_A1H)
|
||||
#include "USBEndpoints_RZ_A1H.h"
|
||||
#elif defined(TARGET_Maxim)
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/* Copyright (c) 2010-2011 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#define NUMBER_OF_LOGICAL_ENDPOINTS (4)
|
||||
#define NUMBER_OF_PHYSICAL_ENDPOINTS (NUMBER_OF_LOGICAL_ENDPOINTS * 2)
|
||||
|
||||
/* Define physical endpoint numbers */
|
||||
|
||||
/* Endpoint No. Type(s) MaxPacket DoubleBuffer */
|
||||
/* ---------------- ------------ ---------- --- */
|
||||
#define EP0OUT (0) /* Control 64 No */
|
||||
#define EP0IN (1) /* Control 64 No */
|
||||
#define EP1OUT (2) /* Int/Bulk/Iso 64/64/1023 Yes */
|
||||
#define EP1IN (3) /* Int/Bulk/Iso 64/64/1023 Yes */
|
||||
#define EP2OUT (4) /* Int/Bulk/Iso 64/64/1023 Yes */
|
||||
#define EP2IN (5) /* Int/Bulk/Iso 64/64/1023 Yes */
|
||||
#define EP3OUT (6) /* Int/Bulk/Iso 64/64/1023 Yes */
|
||||
#define EP3IN (7) /* Int/Bulk/Iso 64/64/1023 Yes */
|
||||
|
||||
/* Maximum Packet sizes */
|
||||
#define MAX_PACKET_SIZE_SETUP (48)
|
||||
#define MAX_PACKET_SIZE_EP0 (64)
|
||||
#define MAX_PACKET_SIZE_EP1 (64) /* Int/Bulk */
|
||||
#define MAX_PACKET_SIZE_EP2 (64) /* Int/Bulk */
|
||||
#define MAX_PACKET_SIZE_EP3 (200) /* Int/Bulk/iso (44100 stereo 16 bits) */
|
||||
|
||||
#define MAX_PACKET_SIZE_EP1_ISO (1023) /* Isochronous */
|
||||
#define MAX_PACKET_SIZE_EP2_ISO (1023) /* Isochronous */
|
||||
#define MAX_PACKET_SIZE_EP3_ISO (1023) /* Isochronous */
|
||||
|
||||
/* Generic endpoints - intended to be portable accross devices */
|
||||
/* and be suitable for simple USB devices. */
|
||||
|
||||
/* Bulk endpoint */
|
||||
#define EPBULK_OUT (EP2OUT)
|
||||
#define EPBULK_IN (EP2IN)
|
||||
#define EPBULK_OUT_callback EP2_OUT_callback
|
||||
#define EPBULK_IN_callback EP2_IN_callback
|
||||
/* Interrupt endpoint */
|
||||
#define EPINT_OUT (EP1OUT)
|
||||
#define EPINT_IN (EP1IN)
|
||||
#define EPINT_OUT_callback EP1_OUT_callback
|
||||
#define EPINT_IN_callback EP1_IN_callback
|
||||
/* Isochronous endpoint */
|
||||
#define EPISO_OUT (EP3OUT)
|
||||
#define EPISO_IN (EP3IN)
|
||||
#define EPISO_OUT_callback EP3_OUT_callback
|
||||
#define EPISO_IN_callback EP3_IN_callback
|
||||
|
||||
#define MAX_PACKET_SIZE_EPBULK (MAX_PACKET_SIZE_EP2)
|
||||
#define MAX_PACKET_SIZE_EPINT (MAX_PACKET_SIZE_EP1)
|
||||
#define MAX_PACKET_SIZE_EPISO (MAX_PACKET_SIZE_EP3_ISO)
|
|
@ -110,8 +110,10 @@ private:
|
|||
|
||||
#if defined(TARGET_LPC11UXX) || defined(TARGET_LPC11U6X) || defined(TARGET_LPC1347) || defined(TARGET_LPC1549)
|
||||
bool (USBHAL::*epCallback[10 - 2])(void);
|
||||
#elif defined(TARGET_STM32F4)
|
||||
bool (USBHAL::*epCallback[8 - 2])(void);
|
||||
#elif defined(TARGET_STM32F4) && !defined(USB_STM_HAL)
|
||||
bool (USBHAL::*epCallback[8 - 2])(void);
|
||||
#elif defined(TARGET_STM32F4) || defined(TARGET_STM32F3) || defined (TARGET_STM32F2)|| defined(TARGET_STM32L4) || defined(TARGET_STM32F7)
|
||||
PCD_HandleTypeDef hpcd;
|
||||
#else
|
||||
bool (USBHAL::*epCallback[32 - 2])(void);
|
||||
#endif
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#if defined(TARGET_STM32F4)
|
||||
#if defined(TARGET_STM32F4) && !defined(USB_STM_HAL)
|
||||
|
||||
#include "USBHAL.h"
|
||||
#include "USBRegs_STM32.h"
|
||||
|
|
Loading…
Reference in New Issue