mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
LP-512 F3 USB-FS Device: Add support for new usb peripheral in STM32F303xD and STM32F303xE
This commit is contained in:
parent
f1bfc71727
commit
b87c8f4e3a
@ -48,7 +48,7 @@ typedef enum _CONTROL_STATE
|
||||
|
||||
typedef struct OneDescriptor
|
||||
{
|
||||
uint8_t *Descriptor;
|
||||
const uint8_t *Descriptor;
|
||||
uint16_t Descriptor_Size;
|
||||
}
|
||||
ONE_DESCRIPTOR, *PONE_DESCRIPTOR;
|
||||
@ -182,9 +182,9 @@ typedef struct _DEVICE_PROP
|
||||
|
||||
RESULT (*Class_Get_Interface_Setting)(uint8_t Interface, uint8_t AlternateSetting);
|
||||
|
||||
uint8_t* (*GetDeviceDescriptor)(uint16_t Length);
|
||||
uint8_t* (*GetConfigDescriptor)(uint16_t Length);
|
||||
uint8_t* (*GetStringDescriptor)(uint16_t Length);
|
||||
const uint8_t* (*GetDeviceDescriptor)(uint16_t Length);
|
||||
const uint8_t* (*GetConfigDescriptor)(uint16_t Length);
|
||||
const uint8_t* (*GetStringDescriptor)(uint16_t Length);
|
||||
|
||||
/* This field is not used in current library version. It is kept only for
|
||||
compatibility with previous versions */
|
||||
@ -234,13 +234,13 @@ uint8_t In0_Process(void);
|
||||
RESULT Standard_SetEndPointFeature(void);
|
||||
RESULT Standard_SetDeviceFeature(void);
|
||||
|
||||
uint8_t *Standard_GetConfiguration(uint16_t Length);
|
||||
const uint8_t *Standard_GetConfiguration(uint16_t Length);
|
||||
RESULT Standard_SetConfiguration(void);
|
||||
uint8_t *Standard_GetInterface(uint16_t Length);
|
||||
const uint8_t *Standard_GetInterface(uint16_t Length);
|
||||
RESULT Standard_SetInterface(void);
|
||||
uint8_t *Standard_GetDescriptorData(uint16_t Length, PONE_DESCRIPTOR pDesc);
|
||||
|
||||
uint8_t *Standard_GetStatus(uint16_t Length);
|
||||
const uint8_t *Standard_GetStatus(uint16_t Length);
|
||||
RESULT Standard_ClearFeature(void);
|
||||
void SetDeviceAddress(uint8_t);
|
||||
void NOP_Process(void);
|
||||
|
@ -31,7 +31,7 @@
|
||||
#define __USB_LIB_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "hw_config.h"
|
||||
#include "stm32f30x.h"
|
||||
#include "usb_type.h"
|
||||
#include "usb_regs.h"
|
||||
#include "usb_def.h"
|
||||
|
@ -30,6 +30,22 @@
|
||||
#ifndef __USB_REGS_H
|
||||
#define __USB_REGS_H
|
||||
|
||||
#if defined(STM32F303xC) || \
|
||||
defined(STM32F303x8) || defined(STM32F334x8) || \
|
||||
defined(STM32F301x8) || \
|
||||
defined(STM32F373xC) || defined(STM32F378xx) || \
|
||||
defined(STM32F302xC)
|
||||
#define __USB_PMA_1x16
|
||||
typedef uint32_t usb_pma_t;
|
||||
#endif /* STM32F303xC || */
|
||||
/* STM32F303x8 || STM32F334x8 || */
|
||||
/* STM32F301x8 || */
|
||||
/* STM32F373xC || STM32F378xx */
|
||||
#if defined(STM32F302xE) || defined(STM32F303xD) || defined(STM32F303xE)
|
||||
#define __USB_PMA_2x16
|
||||
typedef uint16_t usb_pma_t;
|
||||
#endif /* STM32F302xE || STM32F303xD || STM32F303xE */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef enum _EP_DBUF_DIR
|
||||
@ -448,11 +464,18 @@ enum EP_BUF_NUM
|
||||
*******************************************************************************/
|
||||
#define _GetEPAddress(bEpNum) ((uint8_t)(_GetENDPOINT(bEpNum) & EPADDR_FIELD))
|
||||
|
||||
#define _pEPTxAddr(bEpNum) ((uint32_t *)((_GetBTABLE()+bEpNum*8 )*2 + PMAAddr))
|
||||
#define _pEPTxCount(bEpNum) ((uint32_t *)((_GetBTABLE()+bEpNum*8+2)*2 + PMAAddr))
|
||||
#define _pEPRxAddr(bEpNum) ((uint32_t *)((_GetBTABLE()+bEpNum*8+4)*2 + PMAAddr))
|
||||
#define _pEPRxCount(bEpNum) ((uint32_t *)((_GetBTABLE()+bEpNum*8+6)*2 + PMAAddr))
|
||||
|
||||
#ifdef __USB_PMA_1x16
|
||||
#define _pEPTxAddr(bEpNum) ((usb_pma_t *)((_GetBTABLE()+bEpNum*8 )*2 + PMAAddr))
|
||||
#define _pEPTxCount(bEpNum) ((usb_pma_t *)((_GetBTABLE()+bEpNum*8+2)*2 + PMAAddr))
|
||||
#define _pEPRxAddr(bEpNum) ((usb_pma_t *)((_GetBTABLE()+bEpNum*8+4)*2 + PMAAddr))
|
||||
#define _pEPRxCount(bEpNum) ((usb_pma_t *)((_GetBTABLE()+bEpNum*8+6)*2 + PMAAddr))
|
||||
#endif /* __USB_PMA_1x16 */
|
||||
#ifdef __USB_PMA_2x16
|
||||
#define _pEPTxAddr(bEpNum) ((usb_pma_t *)((_GetBTABLE()+bEpNum*8 ) + PMAAddr))
|
||||
#define _pEPTxCount(bEpNum) ((usb_pma_t *)((_GetBTABLE()+bEpNum*8+2) + PMAAddr))
|
||||
#define _pEPRxAddr(bEpNum) ((usb_pma_t *)((_GetBTABLE()+bEpNum*8+4) + PMAAddr))
|
||||
#define _pEPRxCount(bEpNum) ((usb_pma_t *)((_GetBTABLE()+bEpNum*8+6) + PMAAddr))
|
||||
#endif /* __USB_PMA_2x16 */
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPTxAddr / SetEPRxAddr.
|
||||
* Description : sets address of the tx/rx buffer.
|
||||
@ -486,14 +509,14 @@ enum EP_BUF_NUM
|
||||
wNBlocks = wCount >> 5;\
|
||||
if((wCount & 0x1f) == 0)\
|
||||
wNBlocks--;\
|
||||
*pdwReg = (uint32_t)((wNBlocks << 10) | 0x8000);\
|
||||
*pdwReg = (usb_pma_t)((wNBlocks << 10) | 0x8000);\
|
||||
}/* _BlocksOf32 */
|
||||
|
||||
#define _BlocksOf2(dwReg,wCount,wNBlocks) {\
|
||||
wNBlocks = wCount >> 1;\
|
||||
if((wCount & 0x1) != 0)\
|
||||
wNBlocks++;\
|
||||
*pdwReg = (uint32_t)(wNBlocks << 10);\
|
||||
*pdwReg = (usb_pma_t)(wNBlocks << 10);\
|
||||
}/* _BlocksOf2 */
|
||||
|
||||
#define _SetEPCountRxReg(dwReg,wCount) {\
|
||||
@ -505,7 +528,7 @@ enum EP_BUF_NUM
|
||||
|
||||
|
||||
#define _SetEPRxDblBuf0Count(bEpNum,wCount) {\
|
||||
uint32_t *pdwReg = _pEPTxCount(bEpNum); \
|
||||
usb_pma_t *pdwReg = _pEPTxCount(bEpNum); \
|
||||
_SetEPCountRxReg(pdwReg, wCount);\
|
||||
}
|
||||
/*******************************************************************************
|
||||
@ -518,7 +541,7 @@ enum EP_BUF_NUM
|
||||
*******************************************************************************/
|
||||
#define _SetEPTxCount(bEpNum,wCount) (*_pEPTxCount(bEpNum) = wCount)
|
||||
#define _SetEPRxCount(bEpNum,wCount) {\
|
||||
uint32_t *pdwReg = _pEPRxCount(bEpNum); \
|
||||
usb_pma_t *pdwReg = _pEPRxCount(bEpNum); \
|
||||
_SetEPCountRxReg(pdwReg, wCount);\
|
||||
}
|
||||
/*******************************************************************************
|
||||
@ -582,7 +605,7 @@ enum EP_BUF_NUM
|
||||
{_SetEPRxDblBuf0Count(bEpNum,wCount);} \
|
||||
else if(bDir == EP_DBUF_IN)\
|
||||
/* IN endpoint */ \
|
||||
*_pEPTxCount(bEpNum) = (uint32_t)wCount; \
|
||||
*_pEPTxCount(bEpNum) = (usb_pma_t)wCount; \
|
||||
} /* SetEPDblBuf0Count*/
|
||||
|
||||
#define _SetEPDblBuf1Count(bEpNum, bDir, wCount) { \
|
||||
@ -591,7 +614,7 @@ enum EP_BUF_NUM
|
||||
{_SetEPRxCount(bEpNum,wCount);}\
|
||||
else if(bDir == EP_DBUF_IN)\
|
||||
/* IN endpoint */\
|
||||
*_pEPRxCount(bEpNum) = (uint32_t)wCount; \
|
||||
*_pEPRxCount(bEpNum) = (usb_pma_t)wCount; \
|
||||
} /* SetEPDblBuf1Count */
|
||||
|
||||
#define _SetEPDblBuffCount(bEpNum, bDir, wCount) {\
|
||||
|
@ -39,11 +39,13 @@
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
#if !defined(FALSE) && !defined(TRUE)
|
||||
typedef enum
|
||||
{
|
||||
FALSE = 0, TRUE = !FALSE
|
||||
}
|
||||
bool;
|
||||
usb_fs_device_driver_bool;
|
||||
#endif
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
@ -50,7 +50,7 @@
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
uint16_t_uint8_t StatusInfo;
|
||||
|
||||
bool Data_Mul_MaxPacketSize = FALSE;
|
||||
uint8_t Data_Mul_MaxPacketSize = FALSE;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static void DataStageOut(void);
|
||||
static void DataStageIn(void);
|
||||
@ -66,7 +66,7 @@ static void Data_Setup0(void);
|
||||
* Return : Return 1 , if the request is invalid when "Length" is 0.
|
||||
* Return "Buffer" if the "Length" is not 0.
|
||||
*******************************************************************************/
|
||||
uint8_t *Standard_GetConfiguration(uint16_t Length)
|
||||
const uint8_t *Standard_GetConfiguration(uint16_t Length)
|
||||
{
|
||||
if (Length == 0)
|
||||
{
|
||||
@ -112,7 +112,7 @@ RESULT Standard_SetConfiguration(void)
|
||||
* Return : Return 0, if the request is invalid when "Length" is 0.
|
||||
* Return "Buffer" if the "Length" is not 0.
|
||||
*******************************************************************************/
|
||||
uint8_t *Standard_GetInterface(uint16_t Length)
|
||||
const uint8_t *Standard_GetInterface(uint16_t Length)
|
||||
{
|
||||
if (Length == 0)
|
||||
{
|
||||
@ -168,7 +168,7 @@ RESULT Standard_SetInterface(void)
|
||||
* Return : Return 0, if the request is at end of data block,
|
||||
* or is invalid when "Length" is 0.
|
||||
*******************************************************************************/
|
||||
uint8_t *Standard_GetStatus(uint16_t Length)
|
||||
const uint8_t *Standard_GetStatus(uint16_t Length)
|
||||
{
|
||||
if (Length == 0)
|
||||
{
|
||||
@ -430,7 +430,7 @@ uint8_t *Standard_GetDescriptorData(uint16_t Length, ONE_DESCRIPTOR *pDesc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pDesc->Descriptor + wOffset;
|
||||
return (uint8_t *)(pDesc->Descriptor + wOffset);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
@ -682,7 +682,7 @@ exit_NoData_Setup0:
|
||||
*******************************************************************************/
|
||||
void Data_Setup0(void)
|
||||
{
|
||||
uint8_t *(*CopyRoutine)(uint16_t);
|
||||
const uint8_t *(*CopyRoutine)(uint16_t);
|
||||
RESULT Result;
|
||||
uint32_t Request_No = pInformation->USBbRequest;
|
||||
|
||||
@ -787,7 +787,7 @@ void Data_Setup0(void)
|
||||
if (CopyRoutine)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wOffset = wOffset;
|
||||
pInformation->Ctrl_Info.CopyData = CopyRoutine;
|
||||
pInformation->Ctrl_Info.CopyData = (typeof(pInformation->Ctrl_Info.CopyData))CopyRoutine;
|
||||
/* sb in the original the cast to word was directly */
|
||||
/* now the cast is made step by step */
|
||||
(*CopyRoutine)(0);
|
||||
@ -859,7 +859,7 @@ void Data_Setup0(void)
|
||||
* Output : None.
|
||||
* Return : Post0_Process.
|
||||
*******************************************************************************/
|
||||
uint8_t Setup0_Process(void)
|
||||
uint8_t __attribute__((optimize("O0"))) Setup0_Process(void)
|
||||
{
|
||||
|
||||
union
|
||||
@ -867,9 +867,21 @@ uint8_t Setup0_Process(void)
|
||||
uint8_t* b;
|
||||
uint16_t* w;
|
||||
} pBuf;
|
||||
|
||||
#ifdef STM32F10X_CL
|
||||
USB_OTG_EP *ep;
|
||||
uint16_t offset = 0;
|
||||
|
||||
ep = PCD_GetOutEP(ENDP0);
|
||||
pBuf.b = ep->xfer_buff;
|
||||
#elif defined(STM32F303xD) || defined(STM32F303xE)
|
||||
uint16_t offset = 0;
|
||||
pBuf.b = (uint8_t *)(PMAAddr + _GetEPRxAddr(ENDP0));
|
||||
#else
|
||||
uint16_t offset = 1;
|
||||
|
||||
pBuf.b = PMAAddr + (uint8_t *)(_GetEPRxAddr(ENDP0) * 2); /* *2 for 32 bits addr */
|
||||
#endif /* STM32F10X_CL */
|
||||
|
||||
if (pInformation->ControlState != PAUSE)
|
||||
{
|
||||
|
@ -36,6 +36,11 @@
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
#if defined(STM32F303xC) || \
|
||||
defined(STM32F303x8) || defined(STM32F334x8) || \
|
||||
defined(STM32F301x8) || \
|
||||
defined(STM32F373xC) || defined(STM32F378xx) || \
|
||||
defined(STM32F302xC)
|
||||
/*******************************************************************************
|
||||
* Function Name : UserToPMABufferCopy
|
||||
* Description : Copy a buffer from user memory area to packet memory area (PMA)
|
||||
@ -64,7 +69,7 @@ void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNByt
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PMAToUserBufferCopy
|
||||
* Description : Copy a buffer from user memory area to packet memory area (PMA)
|
||||
* Description : Copy a buffer from packet memory area (PMA) to user memory area
|
||||
* Input : - pbUsrBuf = pointer to user memory area.
|
||||
* - wPMABufAddr = address into PMA.
|
||||
* - wNBytes = no. of bytes to be copied.
|
||||
@ -83,5 +88,58 @@ void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNByt
|
||||
pbUsrBuf++;
|
||||
}
|
||||
}
|
||||
#endif /* STM32F303xC || */
|
||||
/* STM32F303x8 || STM32F334x8 || */
|
||||
/* STM32F301x8 || */
|
||||
/* STM32F373xC || STM32F378xx */
|
||||
#if defined(STM32F302xE) || defined(STM32F303xD) || defined(STM32F303xE)
|
||||
/*******************************************************************************
|
||||
* Function Name : UserToPMABufferCopy
|
||||
* Description : Copy a buffer from user memory area to packet memory area (PMA)
|
||||
* Input : - pbUsrBuf: pointer to user memory area.
|
||||
* - wPMABufAddr: address into PMA.
|
||||
* - wNBytes: no. of bytes to be copied.
|
||||
* Output : None.
|
||||
* Return : None .
|
||||
*******************************************************************************/
|
||||
void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
|
||||
{
|
||||
uint32_t n = ((uint32_t)((uint32_t)wNBytes + 1U)) >> 1U;
|
||||
uint32_t i;
|
||||
uint16_t temp1, temp2;
|
||||
uint16_t *pdwVal;
|
||||
pdwVal = (uint16_t *)((uint32_t)(wPMABufAddr + PMAAddr));
|
||||
for (i = n; i != 0U; i--)
|
||||
{
|
||||
temp1 = (uint16_t) * pbUsrBuf;
|
||||
pbUsrBuf++;
|
||||
temp2 = temp1 | ((uint16_t)((uint16_t) * pbUsrBuf << 8U)) ;
|
||||
*pdwVal++ = temp2;
|
||||
pbUsrBuf++;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PMAToUserBufferCopy
|
||||
* Description : Copy a buffer from packet memory area (PMA) to user memory area
|
||||
* Input : - pbUsrBuf = pointer to user memory area.
|
||||
* - wPMABufAddr = address into PMA.
|
||||
* - wNBytes = no. of bytes to be copied.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
|
||||
{
|
||||
uint32_t n = ((uint32_t)((uint32_t)wNBytes + 1U)) >> 1U;
|
||||
uint32_t i;
|
||||
uint16_t *pdwVal;
|
||||
pdwVal = (uint16_t *)((uint32_t)(wPMABufAddr + PMAAddr));
|
||||
for (i = n; i != 0U; i--)
|
||||
{
|
||||
*(uint16_t*)((uint32_t)pbUsrBuf++) = *pdwVal++;
|
||||
pbUsrBuf++;
|
||||
}
|
||||
}
|
||||
#endif /* STM32F302xE || STM32F303xD || STM32F303xE */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
Loading…
x
Reference in New Issue
Block a user