mirror of
https://github.com/HEYAHONG/ExtBoard-001.git
synced 2025-05-08 23:52:38 +08:00
初步移植原厂USB虚拟串口(无需外部上拉电阻,暂未连接外设)
This commit is contained in:
parent
32bca09229
commit
acf50ff83e
@ -67,7 +67,7 @@ CONFIG_RT_USING_SMALL_MEM_AS_HEAP=y
|
||||
# CONFIG_RT_USING_USERHEAP is not set
|
||||
# CONFIG_RT_USING_NOHEAP is not set
|
||||
# CONFIG_RT_USING_MEMTRACE is not set
|
||||
# CONFIG_RT_USING_HEAP_ISR is not set
|
||||
CONFIG_RT_USING_HEAP_ISR=y
|
||||
CONFIG_RT_USING_HEAP=y
|
||||
CONFIG_RT_USING_DEVICE=y
|
||||
# CONFIG_RT_USING_DEVICE_OPS is not set
|
||||
@ -309,6 +309,21 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
#
|
||||
# CONFIG_PKG_USING_WLAN_WICED is not set
|
||||
# CONFIG_PKG_USING_RW007 is not set
|
||||
|
||||
#
|
||||
# CYW43012 WiFi
|
||||
#
|
||||
# CONFIG_PKG_USING_WLAN_CYW43012 is not set
|
||||
|
||||
#
|
||||
# BL808 WiFi
|
||||
#
|
||||
# CONFIG_PKG_USING_WLAN_BL808 is not set
|
||||
|
||||
#
|
||||
# CYW43439 WiFi
|
||||
#
|
||||
# CONFIG_PKG_USING_WLAN_CYW43439 is not set
|
||||
# CONFIG_PKG_USING_COAP is not set
|
||||
# CONFIG_PKG_USING_NOPOLL is not set
|
||||
# CONFIG_PKG_USING_NETUTILS is not set
|
||||
@ -330,7 +345,6 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_JIOT-C-SDK is not set
|
||||
# CONFIG_PKG_USING_UCLOUD_IOT_SDK is not set
|
||||
# CONFIG_PKG_USING_JOYLINK is not set
|
||||
# CONFIG_PKG_USING_EZ_IOT_OS is not set
|
||||
# CONFIG_PKG_USING_IOTSHARP_SDK is not set
|
||||
# CONFIG_PKG_USING_NIMBLE is not set
|
||||
# CONFIG_PKG_USING_LLSYNC_SDK_ADAPTER is not set
|
||||
@ -351,6 +365,8 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_NMEALIB is not set
|
||||
# CONFIG_PKG_USING_PDULIB is not set
|
||||
# CONFIG_PKG_USING_BTSTACK is not set
|
||||
# CONFIG_PKG_USING_BT_CYW43012 is not set
|
||||
# CONFIG_PKG_USING_CYW43XX is not set
|
||||
# CONFIG_PKG_USING_LORAWAN_ED_STACK is not set
|
||||
# CONFIG_PKG_USING_WAYZ_IOTKIT is not set
|
||||
# CONFIG_PKG_USING_MAVLINK is not set
|
||||
@ -370,6 +386,8 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_ZFTP is not set
|
||||
# CONFIG_PKG_USING_WOL is not set
|
||||
# CONFIG_PKG_USING_ZEPHYR_POLLING is not set
|
||||
# CONFIG_PKG_USING_MATTER_ADAPTATION_LAYER is not set
|
||||
# CONFIG_PKG_USING_LHC_MODBUS is not set
|
||||
|
||||
#
|
||||
# security packages
|
||||
@ -416,7 +434,6 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# LVGL: powerful and easy-to-use embedded GUI library
|
||||
#
|
||||
# CONFIG_PKG_USING_LVGL is not set
|
||||
# CONFIG_PKG_USING_LITTLEVGL2RTT is not set
|
||||
# CONFIG_PKG_USING_LV_MUSIC_DEMO is not set
|
||||
# CONFIG_PKG_USING_GUI_GUIDER_DEMO is not set
|
||||
|
||||
@ -492,6 +509,7 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_ARMV7M_DWT_TOOL is not set
|
||||
# CONFIG_PKG_USING_VOFA_PLUS is not set
|
||||
# CONFIG_PKG_USING_RT_TRACE is not set
|
||||
# CONFIG_PKG_USING_ZDEBUG is not set
|
||||
|
||||
#
|
||||
# system packages
|
||||
@ -528,10 +546,14 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_UC_COMMON is not set
|
||||
# CONFIG_PKG_USING_UC_MODBUS is not set
|
||||
# CONFIG_PKG_USING_FREERTOS_WRAPPER is not set
|
||||
# CONFIG_PKG_USING_LITEOS_SDK is not set
|
||||
# CONFIG_PKG_USING_TZ_DATABASE is not set
|
||||
# CONFIG_PKG_USING_CAIRO is not set
|
||||
# CONFIG_PKG_USING_PIXMAN is not set
|
||||
# CONFIG_PKG_USING_PARTITION is not set
|
||||
# CONFIG_PKG_USING_PERF_COUNTER is not set
|
||||
# CONFIG_PKG_USING_FILEX is not set
|
||||
# CONFIG_PKG_USING_LEVELX is not set
|
||||
# CONFIG_PKG_USING_FLASHDB is not set
|
||||
# CONFIG_PKG_USING_SQLITE is not set
|
||||
# CONFIG_PKG_USING_RTI is not set
|
||||
@ -551,6 +573,7 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_QBOOT is not set
|
||||
# CONFIG_PKG_USING_PPOOL is not set
|
||||
# CONFIG_PKG_USING_OPENAMP is not set
|
||||
# CONFIG_PKG_USING_RPMSG_LITE is not set
|
||||
# CONFIG_PKG_USING_LPM is not set
|
||||
# CONFIG_PKG_USING_TLSF is not set
|
||||
# CONFIG_PKG_USING_EVENT_RECORDER is not set
|
||||
@ -564,6 +587,11 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_AGILE_UPGRADE is not set
|
||||
# CONFIG_PKG_USING_FLASH_BLOB is not set
|
||||
# CONFIG_PKG_USING_MLIBC is not set
|
||||
# CONFIG_PKG_USING_TASK_MSG_BUS is not set
|
||||
# CONFIG_PKG_USING_SFDB is not set
|
||||
# CONFIG_PKG_USING_RTP is not set
|
||||
# CONFIG_PKG_USING_REB is not set
|
||||
# CONFIG_PKG_USING_R_RHEALSTONE is not set
|
||||
|
||||
#
|
||||
# peripheral libraries and drivers
|
||||
@ -628,6 +656,7 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_BALANCE is not set
|
||||
# CONFIG_PKG_USING_SHT2X is not set
|
||||
# CONFIG_PKG_USING_SHT3X is not set
|
||||
# CONFIG_PKG_USING_SHT4X is not set
|
||||
# CONFIG_PKG_USING_AD7746 is not set
|
||||
# CONFIG_PKG_USING_ADT74XX is not set
|
||||
# CONFIG_PKG_USING_MAX17048 is not set
|
||||
@ -729,6 +758,11 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_FINGERPRINT is not set
|
||||
# CONFIG_PKG_USING_BT_ECB02C is not set
|
||||
# CONFIG_PKG_USING_UAT is not set
|
||||
# CONFIG_PKG_USING_ST7789 is not set
|
||||
# CONFIG_PKG_USING_VS1003 is not set
|
||||
# CONFIG_PKG_USING_X9555 is not set
|
||||
# CONFIG_PKG_USING_SYSTEM_RUN_LED is not set
|
||||
# CONFIG_PKG_USING_BT_MX01 is not set
|
||||
# CONFIG_PKG_USING_SPI_TOOLS is not set
|
||||
|
||||
#
|
||||
@ -743,6 +777,7 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_ULAPACK is not set
|
||||
# CONFIG_PKG_USING_QUEST is not set
|
||||
# CONFIG_PKG_USING_NAXOS is not set
|
||||
# CONFIG_PKG_USING_R_TINYMAIX is not set
|
||||
|
||||
#
|
||||
# Signal Processing and Control Algorithm Packages
|
||||
@ -752,6 +787,7 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_UKAL is not set
|
||||
# CONFIG_PKG_USING_DIGITALCTRL is not set
|
||||
# CONFIG_PKG_USING_KISSFFT is not set
|
||||
# CONFIG_PKG_USING_CMSIS_DSP is not set
|
||||
|
||||
#
|
||||
# miscellaneous packages
|
||||
@ -783,12 +819,14 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_DONUT is not set
|
||||
# CONFIG_PKG_USING_COWSAY is not set
|
||||
# CONFIG_PKG_USING_MORSE is not set
|
||||
# CONFIG_PKG_USING_TINYSQUARE is not set
|
||||
# CONFIG_PKG_USING_LIBCSV is not set
|
||||
# CONFIG_PKG_USING_OPTPARSE is not set
|
||||
# CONFIG_PKG_USING_FASTLZ is not set
|
||||
# CONFIG_PKG_USING_MINILZO is not set
|
||||
# CONFIG_PKG_USING_QUICKLZ is not set
|
||||
# CONFIG_PKG_USING_LZMA is not set
|
||||
# CONFIG_PKG_USING_RALARAM is not set
|
||||
# CONFIG_PKG_USING_MULTIBUTTON is not set
|
||||
# CONFIG_PKG_USING_FLEXIBLE_BUTTON is not set
|
||||
# CONFIG_PKG_USING_CANFESTIVAL is not set
|
||||
@ -825,7 +863,9 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# Projects and Demos
|
||||
#
|
||||
# CONFIG_PKG_USING_ARDUINO_MSGQ_C_CPP_DEMO is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SKETCH_LOADER_DEMO is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ULTRASOUND_RADAR is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_NINEINONE_SENSOR_SHIELD is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SENSOR_KIT is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_MATLAB_SUPPORT is not set
|
||||
|
||||
@ -833,13 +873,13 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# Sensors
|
||||
#
|
||||
# CONFIG_PKG_USING_ARDUINO_SENSOR_DEVICE_DRIVERS is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_CAPACITIVESENSOR is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SENSOR is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SENSORLAB is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ADXL375 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_VL53L0X is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_VL53L1X is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SENSOR is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_VL6180X is not set
|
||||
# CONFIG_PKG_USING_ADAFRUIT_MAX31855 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MAX31855 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MAX31865 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MAX31856 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MAX6675 is not set
|
||||
@ -884,7 +924,7 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LIS3MDL is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MLX90640 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MMA8451 is not set
|
||||
# CONFIG_PKG_USING_ADAFRUIT_MSA301 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MSA301 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MPL115A2 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BNO08X is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BNO08X_RVC is not set
|
||||
@ -923,7 +963,6 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_HTU21DF is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_AS7341 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_HTU31D is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SENSORLAB is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_INA260 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_TMP007_LIBRARY is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_L3GD20 is not set
|
||||
@ -946,7 +985,7 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_TSL2561 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_PAJ7620 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_VL53L0X is not set
|
||||
# CONFIG_PKG_USING_SEEED_ITG3200 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_ITG3200 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_SHT31 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_HP20X is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_DRV2605L is not set
|
||||
@ -954,7 +993,7 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_HMC5883L is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_LSM303DLH is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_TCS3414CS is not set
|
||||
# CONFIG_PKG_USING_SEEED_MP503 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_MP503 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_BMP085 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_HIGHTEMP is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_VEML6070 is not set
|
||||
@ -967,12 +1006,14 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_MCP9600 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_LTC2941 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_LDC1612 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_CAPACITIVESENSOR is not set
|
||||
|
||||
#
|
||||
# Display
|
||||
#
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_GFX_LIBRARY is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_U8G2 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_TFT_ESPI is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ST7735 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SSD1306 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ILI9341 is not set
|
||||
@ -981,6 +1022,7 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
#
|
||||
# Timing
|
||||
#
|
||||
# CONFIG_PKG_USING_ARDUINO_RTCLIB is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_MSTIMER2 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_TICKER is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_TASKSCHEDULER is not set
|
||||
@ -990,6 +1032,7 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
#
|
||||
# CONFIG_PKG_USING_ARDUINO_KALMANFILTER is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ARDUINOJSON is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_TENSORFLOW_LITE_MICRO is not set
|
||||
|
||||
#
|
||||
# Data Storage
|
||||
@ -1006,18 +1049,17 @@ CONFIG_RT_USING_CPP_WRAPPER=y
|
||||
#
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_PCF8574 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_PCA9685 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_PCF85063TP is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_TPA2016 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_DRV2605 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_DS1841 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_DS3502 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_SEEED_PCF85063TP is not set
|
||||
|
||||
#
|
||||
# Other
|
||||
#
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MFRC630 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SI5351 is not set
|
||||
# CONFIG_PKG_USING_ARDUINO_RTCLIB is not set
|
||||
|
||||
#
|
||||
# Signal IO
|
||||
|
151
FW/Core/001-base_rt/USB/CONFIG/hw_config.c
Normal file
151
FW/Core/001-base_rt/USB/CONFIG/hw_config.c
Normal file
@ -0,0 +1,151 @@
|
||||
#include "hw_config.h"
|
||||
#include "usb_lib.h"
|
||||
#include "usb_prop.h"
|
||||
#include "usb_desc.h"
|
||||
#include "usb_istr.h"
|
||||
#include "usb_pwr.h"
|
||||
#include "string.h"
|
||||
#include "stdarg.h"
|
||||
#include "stdio.h"
|
||||
|
||||
_usb_usart_fifo uu_txfifo; //USB串口发送FIFO结构体
|
||||
u8 USART_PRINTF_Buffer[USB_USART_REC_LEN]; //usb_printf发送缓冲区
|
||||
|
||||
//用类似串口1接收数据的方法,来处理USB虚拟串口接收到的数据.
|
||||
u8 USB_USART_RX_BUF[USB_USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.
|
||||
//接收状态
|
||||
//bit15, 接收完成标志
|
||||
//bit14, 接收到0x0d
|
||||
//bit13~0, 接收到的有效字节数目
|
||||
u16 USB_USART_RX_STA=0; //接收状态标记
|
||||
|
||||
extern LINE_CODING linecoding; //USB虚拟串口配置信息
|
||||
|
||||
////USB唤醒中断服务函数
|
||||
//void USBWakeUp_IRQHandler(void)
|
||||
//{
|
||||
// EXTI_ClearITPendingBit(EXTI_Line18);//清除USB唤醒中断挂起位
|
||||
//}
|
||||
|
||||
////USB中断处理函数
|
||||
//void USB_LP_CAN1_RX0_IRQHandler(void)
|
||||
//{
|
||||
// USB_Istr();
|
||||
//}
|
||||
|
||||
//USB时钟配置函数,USBclk=48Mhz@HCLK=72Mhz
|
||||
void Set_USBClock(void)
|
||||
{
|
||||
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_4Div5);//USBclk=PLLclk/4.5=48Mhz
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE); //USB时钟使能
|
||||
}
|
||||
|
||||
//USB进入低功耗模式
|
||||
//当USB进入suspend模式时,MCU进入低功耗模式
|
||||
//需自行添加低功耗代码(比如关时钟等)
|
||||
void Enter_LowPowerMode(void)
|
||||
{
|
||||
printf("usb enter low power mode\r\n");
|
||||
bDeviceState=SUSPENDED;
|
||||
}
|
||||
|
||||
//USB退出低功耗模式
|
||||
//用户可以自行添加相关代码(比如重新配置时钟等)
|
||||
void Leave_LowPowerMode(void)
|
||||
{
|
||||
DEVICE_INFO *pInfo=&Device_Info;
|
||||
printf("leave low power mode\r\n");
|
||||
if (pInfo->Current_Configuration!=0)bDeviceState=CONFIGURED;
|
||||
else bDeviceState = ATTACHED;
|
||||
}
|
||||
|
||||
//USB中断配置
|
||||
void USB_Interrupts_Config(void)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
|
||||
/* Configure the EXTI line 18 connected internally to the USB IP */
|
||||
EXTI_ClearITPendingBit(EXTI_Line18);
|
||||
// 开启线18上的中断
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line18; // USB resume from suspend mode
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //line 18上事件上升降沿触发
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
/* Enable the USB interrupt */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
/* Enable the USB Wake-up interrupt */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USBWakeUp_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
//USB接口配置
|
||||
//NewState:DISABLE,不上拉
|
||||
// ENABLE,上拉
|
||||
void USB_Cable_Config (FunctionalState NewState)
|
||||
{
|
||||
if (NewState!=DISABLE)printf("usb pull up enable\r\n");
|
||||
else printf("usb pull up disable\r\n");
|
||||
}
|
||||
|
||||
//USB使能连接/断线
|
||||
//enable:0,断开
|
||||
// 1,允许连接
|
||||
void USB_Port_Set(u8 enable)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); //使能PORTA时钟
|
||||
if(enable)_SetCNTR(_GetCNTR()&(~(1<<1)));//退出断电模式
|
||||
else
|
||||
{
|
||||
_SetCNTR(_GetCNTR()|(1<<1)); // 断电模式
|
||||
GPIOA->CRH&=0XFFF00FFF;
|
||||
GPIOA->CRH|=0X00033000;
|
||||
PAout(12)=0;
|
||||
}
|
||||
}
|
||||
|
||||
//用于USB配置信息
|
||||
void Get_SerialNum(void)
|
||||
{
|
||||
u32 Device_Serial0, Device_Serial1, Device_Serial2;
|
||||
Device_Serial0 = *(u32*)(0x1FFFF7E8);
|
||||
Device_Serial1 = *(u32*)(0x1FFFF7EC);
|
||||
Device_Serial2 = *(u32*)(0x1FFFF7F0);
|
||||
Device_Serial0 += Device_Serial2;
|
||||
if (Device_Serial0 != 0)
|
||||
{
|
||||
IntToUnicode (Device_Serial0,&Virtual_Com_Port_StringSerial[2], 8);
|
||||
IntToUnicode (Device_Serial1,&Virtual_Com_Port_StringSerial[18], 4);
|
||||
}
|
||||
}
|
||||
|
||||
//将32位的值转换成unicode.
|
||||
//value,要转换的值(32bit)
|
||||
//pbuf:存储地址
|
||||
//len:要转换的长度
|
||||
void IntToUnicode (u32 value, u8 *pbuf, u8 len)
|
||||
{
|
||||
u8 idx = 0;
|
||||
for( idx = 0 ; idx < len ; idx ++)
|
||||
{
|
||||
if( ((value >> 28)) < 0xA )
|
||||
{
|
||||
pbuf[ 2* idx] = (value >> 28) + '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2* idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
value = value << 4;
|
||||
pbuf[ 2* idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
35
FW/Core/001-base_rt/USB/CONFIG/hw_config.h
Normal file
35
FW/Core/001-base_rt/USB/CONFIG/hw_config.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef __HW_CONFIG_H
|
||||
#define __HW_CONFIG_H
|
||||
|
||||
#include "platform_config.h"
|
||||
#include "usb_type.h"
|
||||
|
||||
|
||||
|
||||
#define USB_USART_TXFIFO_SIZE 1024 //USB虚拟串口发送FIFO大小
|
||||
#define USB_USART_REC_LEN 200 //USB串口接收缓冲区最大字节数
|
||||
|
||||
//定义一个USB USART FIFO结构体
|
||||
typedef struct
|
||||
{
|
||||
u8 buffer[USB_USART_TXFIFO_SIZE]; //buffer
|
||||
vu16 writeptr; //写指针
|
||||
vu16 readptr; //读指针
|
||||
} _usb_usart_fifo;
|
||||
extern _usb_usart_fifo uu_txfifo; //USB串口发送FIFO
|
||||
|
||||
extern u8 USB_USART_RX_BUF[USB_USART_REC_LEN]; //接收缓冲,最大USB_USART_REC_LEN个字节.末字节为换行符
|
||||
extern u16 USB_USART_RX_STA; //接收状态标记
|
||||
|
||||
//USB通用代码函数声明
|
||||
void Set_USBClock(void);
|
||||
void Enter_LowPowerMode(void);
|
||||
void Leave_LowPowerMode(void);
|
||||
void USB_Interrupts_Config(void);
|
||||
void USB_Cable_Config (FunctionalState NewState);
|
||||
void USB_Port_Set(u8 enable);
|
||||
void IntToUnicode (u32 value,u8 *pbuf,u8 len);
|
||||
void Get_SerialNum(void);
|
||||
|
||||
|
||||
#endif
|
50
FW/Core/001-base_rt/USB/CONFIG/platform_config.h
Normal file
50
FW/Core/001-base_rt/USB/CONFIG/platform_config.h
Normal file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file platform_config.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 21-January-2013
|
||||
* @brief Evaluation board specific configuration file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __PLATFORM_CONFIG_H
|
||||
#define __PLATFORM_CONFIG_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "system.h"
|
||||
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Uncomment the line corresponding to the STMicroelectronics evaluation board
|
||||
used to run the example */
|
||||
|
||||
#define USE_STM3210E_EVAL //STM32F10XʹÓõİ汾
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* __PLATFORM_CONFIG_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
103
FW/Core/001-base_rt/USB/CONFIG/usb_conf.h
Normal file
103
FW/Core/001-base_rt/USB/CONFIG/usb_conf.h
Normal file
@ -0,0 +1,103 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_conf.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 21-January-2013
|
||||
* @brief Virtual COM Port Demo configuration header
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_CONF_H
|
||||
#define __USB_CONF_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
/* External variables --------------------------------------------------------*/
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* EP_NUM */
|
||||
/* defines how many endpoints are used by the device */
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
#define EP_NUM (4)
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* -------------- Buffer Description Table -----------------*/
|
||||
/*-------------------------------------------------------------*/
|
||||
/* buffer table base address */
|
||||
/* buffer table base address */
|
||||
#define BTABLE_ADDRESS (0x00)
|
||||
|
||||
/* EP0 */
|
||||
/* rx/tx buffer base address */
|
||||
#define ENDP0_RXADDR (0x40)
|
||||
#define ENDP0_TXADDR (0x80)
|
||||
|
||||
/* EP1 */
|
||||
/* tx buffer base address */
|
||||
#define ENDP1_TXADDR (0xC0)
|
||||
#define ENDP2_TXADDR (0x100)
|
||||
#define ENDP3_RXADDR (0x110)
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* ------------------- ISTR events -------------------------*/
|
||||
/*-------------------------------------------------------------*/
|
||||
/* IMR_MSK */
|
||||
/* mask defining which events has to be handled */
|
||||
/* by the device application software */
|
||||
#define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_SUSPM | CNTR_ERRM | CNTR_SOFM \
|
||||
| CNTR_ESOFM | CNTR_RESETM )
|
||||
|
||||
/*#define CTR_CALLBACK*/
|
||||
/*#define DOVR_CALLBACK*/
|
||||
/*#define ERR_CALLBACK*/
|
||||
/*#define WKUP_CALLBACK*/
|
||||
/*#define SUSP_CALLBACK*/
|
||||
/*#define RESET_CALLBACK*/
|
||||
#define SOF_CALLBACK
|
||||
/*#define ESOF_CALLBACK*/
|
||||
/* CTR service routines */
|
||||
/* associated to defined endpoints */
|
||||
/*#define EP1_IN_Callback NOP_Process*/
|
||||
#define EP2_IN_Callback NOP_Process
|
||||
#define EP3_IN_Callback NOP_Process
|
||||
#define EP4_IN_Callback NOP_Process
|
||||
#define EP5_IN_Callback NOP_Process
|
||||
#define EP6_IN_Callback NOP_Process
|
||||
#define EP7_IN_Callback NOP_Process
|
||||
|
||||
#define EP1_OUT_Callback NOP_Process
|
||||
#define EP2_OUT_Callback NOP_Process
|
||||
/*#define EP3_OUT_Callback NOP_Process*/
|
||||
#define EP4_OUT_Callback NOP_Process
|
||||
#define EP5_OUT_Callback NOP_Process
|
||||
#define EP6_OUT_Callback NOP_Process
|
||||
#define EP7_OUT_Callback NOP_Process
|
||||
|
||||
#endif /* __USB_CONF_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
172
FW/Core/001-base_rt/USB/CONFIG/usb_desc.c
Normal file
172
FW/Core/001-base_rt/USB/CONFIG/usb_desc.c
Normal file
@ -0,0 +1,172 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_desc.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 21-January-2013
|
||||
* @brief Descriptors for Virtual Com Port Demo
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_lib.h"
|
||||
#include "usb_desc.h"
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
const uint8_t Virtual_Com_Port_DeviceDescriptor[] =
|
||||
{
|
||||
0x12, /* bLength */
|
||||
USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
0x00,
|
||||
0x02, /* bcdUSB = 2.00 */
|
||||
0x02, /* bDeviceClass: CDC */
|
||||
0x00, /* bDeviceSubClass */
|
||||
0x00, /* bDeviceProtocol */
|
||||
0x40, /* bMaxPacketSize0 */
|
||||
0x83,
|
||||
0x04, /* idVendor = 0x0483 */
|
||||
0x40,
|
||||
0x57, /* idProduct = 0x7540 */
|
||||
0x00,
|
||||
0x02, /* bcdDevice = 2.00 */
|
||||
1, /* Index of string descriptor describing manufacturer */
|
||||
2, /* Index of string descriptor describing product */
|
||||
3, /* Index of string descriptor describing the device's serial number */
|
||||
0x01 /* bNumConfigurations */
|
||||
};
|
||||
|
||||
const uint8_t Virtual_Com_Port_ConfigDescriptor[] =
|
||||
{
|
||||
/*Configuration Descriptor*/
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
|
||||
VIRTUAL_COM_PORT_SIZ_CONFIG_DESC, /* wTotalLength:no of returned bytes */
|
||||
0x00,
|
||||
0x02, /* bNumInterfaces: 2 interface */
|
||||
0x01, /* bConfigurationValue: Configuration value */
|
||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||
0xC0, /* bmAttributes: self powered */
|
||||
0x32, /* MaxPower 0 mA */
|
||||
/*Interface Descriptor*/
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */
|
||||
/* Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints: One endpoints used */
|
||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
||||
0x02, /* bInterfaceSubClass: Abstract Control Model */
|
||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||
0x00, /* iInterface: */
|
||||
/*Header Functional Descriptor*/
|
||||
0x05, /* bLength: Endpoint Descriptor size */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||
0x10, /* bcdCDC: spec release number */
|
||||
0x01,
|
||||
/*Call Management Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
||||
0x00, /* bmCapabilities: D0+D1 */
|
||||
0x01, /* bDataInterface: 1 */
|
||||
/*ACM Functional Descriptor*/
|
||||
0x04, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
||||
0x02, /* bmCapabilities */
|
||||
/*Union Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x06, /* bDescriptorSubtype: Union func desc */
|
||||
0x00, /* bMasterInterface: Communication class interface */
|
||||
0x01, /* bSlaveInterface0: Data Class Interface */
|
||||
/*Endpoint 2 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
||||
0x82, /* bEndpointAddress: (IN2) */
|
||||
0x03, /* bmAttributes: Interrupt */
|
||||
VIRTUAL_COM_PORT_INT_SIZE, /* wMaxPacketSize: */
|
||||
0x00,
|
||||
0xFF, /* bInterval: */
|
||||
/*Data class interface descriptor*/
|
||||
0x09, /* bLength: Endpoint Descriptor size */
|
||||
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */
|
||||
0x01, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x02, /* bNumEndpoints: Two endpoints used */
|
||||
0x0A, /* bInterfaceClass: CDC */
|
||||
0x00, /* bInterfaceSubClass: */
|
||||
0x00, /* bInterfaceProtocol: */
|
||||
0x00, /* iInterface: */
|
||||
/*Endpoint 3 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
||||
0x03, /* bEndpointAddress: (OUT3) */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
VIRTUAL_COM_PORT_DATA_SIZE, /* wMaxPacketSize: */
|
||||
0x00,
|
||||
0x00, /* bInterval: ignore for Bulk transfer */
|
||||
/*Endpoint 1 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
||||
0x81, /* bEndpointAddress: (IN1) */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
VIRTUAL_COM_PORT_DATA_SIZE, /* wMaxPacketSize: */
|
||||
0x00,
|
||||
0x00 /* bInterval */
|
||||
};
|
||||
|
||||
/* USB String Descriptors */
|
||||
const uint8_t Virtual_Com_Port_StringLangID[VIRTUAL_COM_PORT_SIZ_STRING_LANGID] =
|
||||
{
|
||||
VIRTUAL_COM_PORT_SIZ_STRING_LANGID,
|
||||
USB_STRING_DESCRIPTOR_TYPE,
|
||||
0x09,
|
||||
0x04 /* LangID = 0x0409: U.S. English */
|
||||
};
|
||||
|
||||
const uint8_t Virtual_Com_Port_StringVendor[VIRTUAL_COM_PORT_SIZ_STRING_VENDOR] =
|
||||
{
|
||||
VIRTUAL_COM_PORT_SIZ_STRING_VENDOR, /* Size of Vendor string */
|
||||
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType*/
|
||||
/* Manufacturer: "HYH" */
|
||||
'H', 0, 'Y', 0, 'H', 0,
|
||||
};
|
||||
|
||||
const uint8_t Virtual_Com_Port_StringProduct[VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT] =
|
||||
{
|
||||
VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT, /* bLength */
|
||||
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
/* Product name: "ExtBoard-001-Core" */
|
||||
'E', 0, 'x', 0, 't', 0, 'B', 0, 'o', 0, 'a', 0, 'r', 0, 'd', 0,
|
||||
'-', 0, '0', 0, '0', 0, '1', 0, '-', 0, 'C', 0, 'o', 0, 'r', 0,
|
||||
'e', 0
|
||||
};
|
||||
|
||||
uint8_t Virtual_Com_Port_StringSerial[VIRTUAL_COM_PORT_SIZ_STRING_SERIAL] =
|
||||
{
|
||||
VIRTUAL_COM_PORT_SIZ_STRING_SERIAL, /* bLength */
|
||||
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
'H', 0, 'Y', 0, 'H', 0, ' ', 0, ' ', 0
|
||||
};
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
66
FW/Core/001-base_rt/USB/CONFIG/usb_desc.h
Normal file
66
FW/Core/001-base_rt/USB/CONFIG/usb_desc.h
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_desc.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 21-January-2013
|
||||
* @brief Descriptor Header for Virtual COM Port Device
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_DESC_H
|
||||
#define __USB_DESC_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
|
||||
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
|
||||
#define USB_STRING_DESCRIPTOR_TYPE 0x03
|
||||
#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
|
||||
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
|
||||
|
||||
#define VIRTUAL_COM_PORT_DATA_SIZE 64
|
||||
#define VIRTUAL_COM_PORT_INT_SIZE 8
|
||||
|
||||
#define VIRTUAL_COM_PORT_SIZ_DEVICE_DESC 18
|
||||
#define VIRTUAL_COM_PORT_SIZ_CONFIG_DESC 67
|
||||
#define VIRTUAL_COM_PORT_SIZ_STRING_LANGID 4
|
||||
#define VIRTUAL_COM_PORT_SIZ_STRING_VENDOR 8
|
||||
#define VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT 36
|
||||
#define VIRTUAL_COM_PORT_SIZ_STRING_SERIAL 26
|
||||
|
||||
#define STANDARD_ENDPOINT_DESC_SIZE 0x09
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
extern const uint8_t Virtual_Com_Port_DeviceDescriptor[VIRTUAL_COM_PORT_SIZ_DEVICE_DESC];
|
||||
extern const uint8_t Virtual_Com_Port_ConfigDescriptor[VIRTUAL_COM_PORT_SIZ_CONFIG_DESC];
|
||||
|
||||
extern const uint8_t Virtual_Com_Port_StringLangID[VIRTUAL_COM_PORT_SIZ_STRING_LANGID];
|
||||
extern const uint8_t Virtual_Com_Port_StringVendor[VIRTUAL_COM_PORT_SIZ_STRING_VENDOR];
|
||||
extern const uint8_t Virtual_Com_Port_StringProduct[VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT];
|
||||
extern uint8_t Virtual_Com_Port_StringSerial[VIRTUAL_COM_PORT_SIZ_STRING_SERIAL];
|
||||
|
||||
#endif /* __USB_DESC_H */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
128
FW/Core/001-base_rt/USB/CONFIG/usb_endp.c
Normal file
128
FW/Core/001-base_rt/USB/CONFIG/usb_endp.c
Normal file
@ -0,0 +1,128 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_endp.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 21-January-2013
|
||||
* @brief Endpoint routines
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_lib.h"
|
||||
#include "usb_desc.h"
|
||||
#include "usb_mem.h"
|
||||
#include "hw_config.h"
|
||||
#include "usb_istr.h"
|
||||
#include "usb_pwr.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Interval between sending IN packets in frame number (1 frame = 1ms) */
|
||||
#define VCOMPORT_IN_FRAME_INTERVAL 5
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
uint8_t USB_Rx_Buffer[VIRTUAL_COM_PORT_DATA_SIZE];
|
||||
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EP1_IN_Callback
|
||||
* Description :
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void EP1_IN_Callback (void)
|
||||
{
|
||||
u16 USB_Tx_ptr;
|
||||
u16 USB_Tx_length;
|
||||
if(uu_txfifo.readptr==uu_txfifo.writeptr) //无任何数据要发送,直接退出
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(uu_txfifo.readptr<uu_txfifo.writeptr) //没有超过数组,读指针<写指针
|
||||
{
|
||||
USB_Tx_length=uu_txfifo.writeptr-uu_txfifo.readptr;//得到要发送的数据长度
|
||||
} else //超过数组了 读指针>写指针
|
||||
{
|
||||
USB_Tx_length=USB_USART_TXFIFO_SIZE-uu_txfifo.readptr;//得到要发送的数据长度
|
||||
}
|
||||
if(USB_Tx_length>VIRTUAL_COM_PORT_DATA_SIZE) //超过64字节?
|
||||
{
|
||||
USB_Tx_length=VIRTUAL_COM_PORT_DATA_SIZE; //此次发送数据量
|
||||
}
|
||||
USB_Tx_ptr=uu_txfifo.readptr; //发送起始地址
|
||||
uu_txfifo.readptr+=USB_Tx_length; //读指针偏移
|
||||
if(uu_txfifo.readptr>=USB_USART_TXFIFO_SIZE) //读指针归零
|
||||
{
|
||||
uu_txfifo.readptr=0;
|
||||
}
|
||||
UserToPMABufferCopy(&uu_txfifo.buffer[USB_Tx_ptr], ENDP1_TXADDR, USB_Tx_length);
|
||||
SetEPTxCount(ENDP1, USB_Tx_length);
|
||||
SetEPTxValid(ENDP1);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EP3_OUT_Callback
|
||||
* Description :
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void EP3_OUT_Callback(void)
|
||||
{
|
||||
u16 USB_Rx_Cnt;
|
||||
USB_Rx_Cnt = USB_SIL_Read(EP3_OUT, USB_Rx_Buffer); //得到USB接收到的数据及其长度
|
||||
SetEPRxValid(ENDP3); //时能端点3的数据接收
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SOF_Callback / INTR_SOFINTR_Callback
|
||||
* Description :
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SOF_Callback(void)
|
||||
{
|
||||
static uint32_t FrameCount = 0;
|
||||
|
||||
if(bDeviceState == CONFIGURED)
|
||||
{
|
||||
if (FrameCount++ == VCOMPORT_IN_FRAME_INTERVAL)
|
||||
{
|
||||
/* Reset the frame counter */
|
||||
FrameCount = 0;
|
||||
|
||||
/* Check the data to be sent through IN pipe */
|
||||
EP1_IN_Callback();//通过EP1_IN_Callback函数实现TX数据发送给USB
|
||||
//Handle_USBAsynchXfer();
|
||||
}
|
||||
}
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
233
FW/Core/001-base_rt/USB/CONFIG/usb_istr.c
Normal file
233
FW/Core/001-base_rt/USB/CONFIG/usb_istr.c
Normal file
@ -0,0 +1,233 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_istr.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 21-January-2013
|
||||
* @brief ISTR events interrupt service routines
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_lib.h"
|
||||
#include "usb_prop.h"
|
||||
#include "usb_pwr.h"
|
||||
#include "usb_istr.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
__IO uint16_t wIstr; /* ISTR register last read value */
|
||||
__IO uint8_t bIntPackSOF = 0; /* SOFs received between 2 consecutive packets */
|
||||
__IO uint32_t esof_counter =0; /* expected SOF counter */
|
||||
__IO uint32_t wCNTR=0;
|
||||
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* function pointers to non-control endpoints service routines */
|
||||
void (*pEpInt_IN[7])(void) =
|
||||
{
|
||||
EP1_IN_Callback,
|
||||
EP2_IN_Callback,
|
||||
EP3_IN_Callback,
|
||||
EP4_IN_Callback,
|
||||
EP5_IN_Callback,
|
||||
EP6_IN_Callback,
|
||||
EP7_IN_Callback,
|
||||
};
|
||||
|
||||
void (*pEpInt_OUT[7])(void) =
|
||||
{
|
||||
EP1_OUT_Callback,
|
||||
EP2_OUT_Callback,
|
||||
EP3_OUT_Callback,
|
||||
EP4_OUT_Callback,
|
||||
EP5_OUT_Callback,
|
||||
EP6_OUT_Callback,
|
||||
EP7_OUT_Callback,
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USB_Istr
|
||||
* Description : ISTR events interrupt service routine
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void USB_Istr(void)
|
||||
{
|
||||
uint32_t i=0;
|
||||
__IO uint32_t EP[8];
|
||||
|
||||
wIstr = _GetISTR();
|
||||
|
||||
#if (IMR_MSK & ISTR_SOF)
|
||||
if (wIstr & ISTR_SOF & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_SOF);
|
||||
bIntPackSOF++;
|
||||
|
||||
#ifdef SOF_CALLBACK
|
||||
SOF_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
|
||||
#if (IMR_MSK & ISTR_CTR)
|
||||
if (wIstr & ISTR_CTR & wInterrupt_Mask)
|
||||
{
|
||||
/* servicing of the endpoint correct transfer interrupt */
|
||||
/* clear of the CTR flag into the sub */
|
||||
CTR_LP();
|
||||
#ifdef CTR_CALLBACK
|
||||
CTR_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
#if (IMR_MSK & ISTR_RESET)
|
||||
if (wIstr & ISTR_RESET & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_RESET);
|
||||
Device_Property.Reset();
|
||||
#ifdef RESET_CALLBACK
|
||||
RESET_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
#if (IMR_MSK & ISTR_DOVR)
|
||||
if (wIstr & ISTR_DOVR & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_DOVR);
|
||||
#ifdef DOVR_CALLBACK
|
||||
DOVR_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
#if (IMR_MSK & ISTR_ERR)
|
||||
if (wIstr & ISTR_ERR & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_ERR);
|
||||
#ifdef ERR_CALLBACK
|
||||
ERR_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
#if (IMR_MSK & ISTR_WKUP)
|
||||
if (wIstr & ISTR_WKUP & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_WKUP);
|
||||
Resume(RESUME_EXTERNAL);
|
||||
#ifdef WKUP_CALLBACK
|
||||
WKUP_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
#if (IMR_MSK & ISTR_SUSP)
|
||||
if (wIstr & ISTR_SUSP & wInterrupt_Mask)
|
||||
{
|
||||
|
||||
/* check if SUSPEND is possible */
|
||||
if (fSuspendEnabled)
|
||||
{
|
||||
Suspend();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* if not possible then resume after xx ms */
|
||||
Resume(RESUME_LATER);
|
||||
}
|
||||
/* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
|
||||
_SetISTR((uint16_t)CLR_SUSP);
|
||||
#ifdef SUSP_CALLBACK
|
||||
SUSP_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
|
||||
#if (IMR_MSK & ISTR_ESOF)
|
||||
if (wIstr & ISTR_ESOF & wInterrupt_Mask)
|
||||
{
|
||||
/* clear ESOF flag in ISTR */
|
||||
_SetISTR((uint16_t)CLR_ESOF);
|
||||
|
||||
if ((_GetFNR()&FNR_RXDP)!=0)
|
||||
{
|
||||
/* increment ESOF counter */
|
||||
esof_counter ++;
|
||||
|
||||
/* test if we enter in ESOF more than 3 times with FSUSP =0 and RXDP =1=>> possible missing SUSP flag*/
|
||||
if ((esof_counter >3)&&((_GetCNTR()&CNTR_FSUSP)==0))
|
||||
{
|
||||
/* this a sequence to apply a force RESET*/
|
||||
|
||||
/*Store CNTR value */
|
||||
wCNTR = _GetCNTR();
|
||||
|
||||
/*Store endpoints registers status */
|
||||
for (i=0; i<8; i++) EP[i] = _GetENDPOINT(i);
|
||||
|
||||
/*apply FRES */
|
||||
wCNTR|=CNTR_FRES;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/*clear FRES*/
|
||||
wCNTR&=~CNTR_FRES;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/*poll for RESET flag in ISTR*/
|
||||
while((_GetISTR()&ISTR_RESET) == 0);
|
||||
|
||||
/* clear RESET flag in ISTR */
|
||||
_SetISTR((uint16_t)CLR_RESET);
|
||||
|
||||
/*restore Enpoints*/
|
||||
for (i=0; i<8; i++)
|
||||
_SetENDPOINT(i, EP[i]);
|
||||
|
||||
esof_counter = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
esof_counter = 0;
|
||||
}
|
||||
|
||||
/* resume handling timing is made with ESOFs */
|
||||
Resume(RESUME_ESOF); /* request without change of the machine state */
|
||||
|
||||
#ifdef ESOF_CALLBACK
|
||||
ESOF_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
} /* USB_Istr */
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
94
FW/Core/001-base_rt/USB/CONFIG/usb_istr.h
Normal file
94
FW/Core/001-base_rt/USB/CONFIG/usb_istr.h
Normal file
@ -0,0 +1,94 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_istr.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 21-January-2013
|
||||
* @brief This file includes the peripherals header files in the user application.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_ISTR_H
|
||||
#define __USB_ISTR_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_conf.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
void USB_Istr(void);
|
||||
|
||||
/* function prototypes Automatically built defining related macros */
|
||||
|
||||
void EP1_IN_Callback(void);
|
||||
void EP2_IN_Callback(void);
|
||||
void EP3_IN_Callback(void);
|
||||
void EP4_IN_Callback(void);
|
||||
void EP5_IN_Callback(void);
|
||||
void EP6_IN_Callback(void);
|
||||
void EP7_IN_Callback(void);
|
||||
|
||||
void EP1_OUT_Callback(void);
|
||||
void EP2_OUT_Callback(void);
|
||||
void EP3_OUT_Callback(void);
|
||||
void EP4_OUT_Callback(void);
|
||||
void EP5_OUT_Callback(void);
|
||||
void EP6_OUT_Callback(void);
|
||||
void EP7_OUT_Callback(void);
|
||||
|
||||
#ifdef CTR_CALLBACK
|
||||
void CTR_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef DOVR_CALLBACK
|
||||
void DOVR_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef ERR_CALLBACK
|
||||
void ERR_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef WKUP_CALLBACK
|
||||
void WKUP_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef SUSP_CALLBACK
|
||||
void SUSP_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef RESET_CALLBACK
|
||||
void RESET_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef SOF_CALLBACK
|
||||
void SOF_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef ESOF_CALLBACK
|
||||
void ESOF_Callback(void);
|
||||
#endif
|
||||
#endif /*__USB_ISTR_H*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
418
FW/Core/001-base_rt/USB/CONFIG/usb_prop.c
Normal file
418
FW/Core/001-base_rt/USB/CONFIG/usb_prop.c
Normal file
@ -0,0 +1,418 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_prop.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 21-January-2013
|
||||
* @brief All processing related to Virtual Com Port Demo
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_lib.h"
|
||||
#include "usb_conf.h"
|
||||
#include "usb_prop.h"
|
||||
#include "usb_desc.h"
|
||||
#include "usb_pwr.h"
|
||||
#include "hw_config.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
uint8_t Request = 0;
|
||||
|
||||
LINE_CODING linecoding =
|
||||
{
|
||||
115200, /* baud rate*/
|
||||
0x00, /* stop bits-1*/
|
||||
0x00, /* parity - none*/
|
||||
0x08 /* no. of bits 8*/
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Structures initializations */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
DEVICE Device_Table =
|
||||
{
|
||||
EP_NUM,
|
||||
1
|
||||
};
|
||||
|
||||
DEVICE_PROP Device_Property =
|
||||
{
|
||||
Virtual_Com_Port_init,
|
||||
Virtual_Com_Port_Reset,
|
||||
Virtual_Com_Port_Status_In,
|
||||
Virtual_Com_Port_Status_Out,
|
||||
Virtual_Com_Port_Data_Setup,
|
||||
Virtual_Com_Port_NoData_Setup,
|
||||
Virtual_Com_Port_Get_Interface_Setting,
|
||||
Virtual_Com_Port_GetDeviceDescriptor,
|
||||
Virtual_Com_Port_GetConfigDescriptor,
|
||||
Virtual_Com_Port_GetStringDescriptor,
|
||||
0,
|
||||
0x40 /*MAX PACKET SIZE*/
|
||||
};
|
||||
|
||||
USER_STANDARD_REQUESTS User_Standard_Requests =
|
||||
{
|
||||
Virtual_Com_Port_GetConfiguration,
|
||||
Virtual_Com_Port_SetConfiguration,
|
||||
Virtual_Com_Port_GetInterface,
|
||||
Virtual_Com_Port_SetInterface,
|
||||
Virtual_Com_Port_GetStatus,
|
||||
Virtual_Com_Port_ClearFeature,
|
||||
Virtual_Com_Port_SetEndPointFeature,
|
||||
Virtual_Com_Port_SetDeviceFeature,
|
||||
Virtual_Com_Port_SetDeviceAddress
|
||||
};
|
||||
|
||||
ONE_DESCRIPTOR Device_Descriptor =
|
||||
{
|
||||
(uint8_t*)Virtual_Com_Port_DeviceDescriptor,
|
||||
VIRTUAL_COM_PORT_SIZ_DEVICE_DESC
|
||||
};
|
||||
|
||||
ONE_DESCRIPTOR Config_Descriptor =
|
||||
{
|
||||
(uint8_t*)Virtual_Com_Port_ConfigDescriptor,
|
||||
VIRTUAL_COM_PORT_SIZ_CONFIG_DESC
|
||||
};
|
||||
|
||||
ONE_DESCRIPTOR String_Descriptor[4] =
|
||||
{
|
||||
{(uint8_t*)Virtual_Com_Port_StringLangID, VIRTUAL_COM_PORT_SIZ_STRING_LANGID},
|
||||
{(uint8_t*)Virtual_Com_Port_StringVendor, VIRTUAL_COM_PORT_SIZ_STRING_VENDOR},
|
||||
{(uint8_t*)Virtual_Com_Port_StringProduct, VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT},
|
||||
{(uint8_t*)Virtual_Com_Port_StringSerial, VIRTUAL_COM_PORT_SIZ_STRING_SERIAL}
|
||||
};
|
||||
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Extern function prototypes ------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_init.
|
||||
* Description : Virtual COM Port Mouse init routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Virtual_Com_Port_init(void)
|
||||
{
|
||||
|
||||
/* Update the serial number string descriptor with the data from the unique
|
||||
ID*/
|
||||
Get_SerialNum();
|
||||
|
||||
pInformation->Current_Configuration = 0;
|
||||
|
||||
/* Connect the device */
|
||||
PowerOn();
|
||||
|
||||
/* Perform basic device initialization operations */
|
||||
USB_SIL_Init();
|
||||
|
||||
/* configure the USART to the default settings */
|
||||
|
||||
bDeviceState = UNCONNECTED;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_Reset
|
||||
* Description : Virtual_Com_Port Mouse reset routine
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Virtual_Com_Port_Reset(void)
|
||||
{
|
||||
/* Set Virtual_Com_Port DEVICE as not configured */
|
||||
pInformation->Current_Configuration = 0;
|
||||
|
||||
/* Current Feature initialization */
|
||||
pInformation->Current_Feature = Virtual_Com_Port_ConfigDescriptor[7];
|
||||
|
||||
/* Set Virtual_Com_Port DEVICE with the default Interface*/
|
||||
pInformation->Current_Interface = 0;
|
||||
|
||||
SetBTABLE(BTABLE_ADDRESS);
|
||||
|
||||
/* Initialize Endpoint 0 */
|
||||
SetEPType(ENDP0, EP_CONTROL);
|
||||
SetEPTxStatus(ENDP0, EP_TX_STALL);
|
||||
SetEPRxAddr(ENDP0, ENDP0_RXADDR);
|
||||
SetEPTxAddr(ENDP0, ENDP0_TXADDR);
|
||||
Clear_Status_Out(ENDP0);
|
||||
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
|
||||
SetEPRxValid(ENDP0);
|
||||
|
||||
/* Initialize Endpoint 1 */
|
||||
SetEPType(ENDP1, EP_BULK);
|
||||
SetEPTxAddr(ENDP1, ENDP1_TXADDR);
|
||||
SetEPTxStatus(ENDP1, EP_TX_NAK);
|
||||
SetEPRxStatus(ENDP1, EP_RX_DIS);
|
||||
|
||||
/* Initialize Endpoint 2 */
|
||||
SetEPType(ENDP2, EP_INTERRUPT);
|
||||
SetEPTxAddr(ENDP2, ENDP2_TXADDR);
|
||||
SetEPRxStatus(ENDP2, EP_RX_DIS);
|
||||
SetEPTxStatus(ENDP2, EP_TX_NAK);
|
||||
|
||||
/* Initialize Endpoint 3 */
|
||||
SetEPType(ENDP3, EP_BULK);
|
||||
SetEPRxAddr(ENDP3, ENDP3_RXADDR);
|
||||
SetEPRxCount(ENDP3, VIRTUAL_COM_PORT_DATA_SIZE);
|
||||
SetEPRxStatus(ENDP3, EP_RX_VALID);
|
||||
SetEPTxStatus(ENDP3, EP_TX_DIS);
|
||||
|
||||
/* Set this device to response on default address */
|
||||
SetDeviceAddress(0);
|
||||
|
||||
bDeviceState = ATTACHED;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_SetConfiguration.
|
||||
* Description : Update the device state to configured.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Virtual_Com_Port_SetConfiguration(void)
|
||||
{
|
||||
DEVICE_INFO *pInfo = &Device_Info;
|
||||
|
||||
if (pInfo->Current_Configuration != 0)
|
||||
{
|
||||
/* Device configured */
|
||||
bDeviceState = CONFIGURED;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_SetConfiguration.
|
||||
* Description : Update the device state to addressed.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Virtual_Com_Port_SetDeviceAddress (void)
|
||||
{
|
||||
bDeviceState = ADDRESSED;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_Status_In.
|
||||
* Description : Virtual COM Port Status In Routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Virtual_Com_Port_Status_In(void)
|
||||
{
|
||||
if (Request == SET_LINE_CODING)
|
||||
{
|
||||
Request = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_Status_Out
|
||||
* Description : Virtual COM Port Status OUT Routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Virtual_Com_Port_Status_Out(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_Data_Setup
|
||||
* Description : handle the data class specific requests
|
||||
* Input : Request Nb.
|
||||
* Output : None.
|
||||
* Return : USB_UNSUPPORT or USB_SUCCESS.
|
||||
*******************************************************************************/
|
||||
RESULT Virtual_Com_Port_Data_Setup(uint8_t RequestNo)
|
||||
{
|
||||
uint8_t *(*CopyRoutine)(uint16_t);
|
||||
|
||||
CopyRoutine = NULL;
|
||||
|
||||
if (RequestNo == GET_LINE_CODING)
|
||||
{
|
||||
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||
{
|
||||
CopyRoutine = Virtual_Com_Port_GetLineCoding;
|
||||
}
|
||||
}
|
||||
else if (RequestNo == SET_LINE_CODING)
|
||||
{
|
||||
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||
{
|
||||
CopyRoutine = Virtual_Com_Port_SetLineCoding;
|
||||
}
|
||||
Request = SET_LINE_CODING;
|
||||
}
|
||||
|
||||
if (CopyRoutine == NULL)
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
pInformation->Ctrl_Info.CopyData = CopyRoutine;
|
||||
pInformation->Ctrl_Info.Usb_wOffset = 0;
|
||||
(*CopyRoutine)(0);
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_NoData_Setup.
|
||||
* Description : handle the no data class specific requests.
|
||||
* Input : Request Nb.
|
||||
* Output : None.
|
||||
* Return : USB_UNSUPPORT or USB_SUCCESS.
|
||||
*******************************************************************************/
|
||||
RESULT Virtual_Com_Port_NoData_Setup(uint8_t RequestNo)
|
||||
{
|
||||
|
||||
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||
{
|
||||
if (RequestNo == SET_COMM_FEATURE)
|
||||
{
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
else if (RequestNo == SET_CONTROL_LINE_STATE)
|
||||
{
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_GetDeviceDescriptor.
|
||||
* Description : Gets the device descriptor.
|
||||
* Input : Length.
|
||||
* Output : None.
|
||||
* Return : The address of the device descriptor.
|
||||
*******************************************************************************/
|
||||
uint8_t *Virtual_Com_Port_GetDeviceDescriptor(uint16_t Length)
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &Device_Descriptor);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_GetConfigDescriptor.
|
||||
* Description : get the configuration descriptor.
|
||||
* Input : Length.
|
||||
* Output : None.
|
||||
* Return : The address of the configuration descriptor.
|
||||
*******************************************************************************/
|
||||
uint8_t *Virtual_Com_Port_GetConfigDescriptor(uint16_t Length)
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &Config_Descriptor);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_GetStringDescriptor
|
||||
* Description : Gets the string descriptors according to the needed index
|
||||
* Input : Length.
|
||||
* Output : None.
|
||||
* Return : The address of the string descriptors.
|
||||
*******************************************************************************/
|
||||
uint8_t *Virtual_Com_Port_GetStringDescriptor(uint16_t Length)
|
||||
{
|
||||
uint8_t wValue0 = pInformation->USBwValue0;
|
||||
if (wValue0 > 4)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_Get_Interface_Setting.
|
||||
* Description : test the interface and the alternate setting according to the
|
||||
* supported one.
|
||||
* Input1 : uint8_t: Interface : interface number.
|
||||
* Input2 : uint8_t: AlternateSetting : Alternate Setting number.
|
||||
* Output : None.
|
||||
* Return : The address of the string descriptors.
|
||||
*******************************************************************************/
|
||||
RESULT Virtual_Com_Port_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting)
|
||||
{
|
||||
if (AlternateSetting > 0)
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
else if (Interface > 1)
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_GetLineCoding.
|
||||
* Description : send the linecoding structure to the PC host.
|
||||
* Input : Length.
|
||||
* Output : None.
|
||||
* Return : Linecoding structure base address.
|
||||
*******************************************************************************/
|
||||
uint8_t *Virtual_Com_Port_GetLineCoding(uint16_t Length)
|
||||
{
|
||||
if (Length == 0)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);
|
||||
return NULL;
|
||||
}
|
||||
return(uint8_t *)&linecoding;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Virtual_Com_Port_SetLineCoding.
|
||||
* Description : Set the linecoding structure fields.
|
||||
* Input : Length.
|
||||
* Output : None.
|
||||
* Return : Linecoding structure base address.
|
||||
*******************************************************************************/
|
||||
uint8_t *Virtual_Com_Port_SetLineCoding(uint16_t Length)
|
||||
{
|
||||
if (Length == 0)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);
|
||||
return NULL;
|
||||
}
|
||||
return(uint8_t *)&linecoding;
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
87
FW/Core/001-base_rt/USB/CONFIG/usb_prop.h
Normal file
87
FW/Core/001-base_rt/USB/CONFIG/usb_prop.h
Normal file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_prop.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 21-January-2013
|
||||
* @brief All processing related to Virtual COM Port Demo (Endpoint 0)
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __usb_prop_H
|
||||
#define __usb_prop_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t bitrate;
|
||||
uint8_t format;
|
||||
uint8_t paritytype;
|
||||
uint8_t datatype;
|
||||
} LINE_CODING;
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
|
||||
#define Virtual_Com_Port_GetConfiguration NOP_Process
|
||||
//#define Virtual_Com_Port_SetConfiguration NOP_Process
|
||||
#define Virtual_Com_Port_GetInterface NOP_Process
|
||||
#define Virtual_Com_Port_SetInterface NOP_Process
|
||||
#define Virtual_Com_Port_GetStatus NOP_Process
|
||||
#define Virtual_Com_Port_ClearFeature NOP_Process
|
||||
#define Virtual_Com_Port_SetEndPointFeature NOP_Process
|
||||
#define Virtual_Com_Port_SetDeviceFeature NOP_Process
|
||||
//#define Virtual_Com_Port_SetDeviceAddress NOP_Process
|
||||
|
||||
#define SEND_ENCAPSULATED_COMMAND 0x00
|
||||
#define GET_ENCAPSULATED_RESPONSE 0x01
|
||||
#define SET_COMM_FEATURE 0x02
|
||||
#define GET_COMM_FEATURE 0x03
|
||||
#define CLEAR_COMM_FEATURE 0x04
|
||||
#define SET_LINE_CODING 0x20
|
||||
#define GET_LINE_CODING 0x21
|
||||
#define SET_CONTROL_LINE_STATE 0x22
|
||||
#define SEND_BREAK 0x23
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void Virtual_Com_Port_init(void);
|
||||
void Virtual_Com_Port_Reset(void);
|
||||
void Virtual_Com_Port_SetConfiguration(void);
|
||||
void Virtual_Com_Port_SetDeviceAddress (void);
|
||||
void Virtual_Com_Port_Status_In (void);
|
||||
void Virtual_Com_Port_Status_Out (void);
|
||||
RESULT Virtual_Com_Port_Data_Setup(uint8_t);
|
||||
RESULT Virtual_Com_Port_NoData_Setup(uint8_t);
|
||||
RESULT Virtual_Com_Port_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting);
|
||||
uint8_t *Virtual_Com_Port_GetDeviceDescriptor(uint16_t );
|
||||
uint8_t *Virtual_Com_Port_GetConfigDescriptor(uint16_t);
|
||||
uint8_t *Virtual_Com_Port_GetStringDescriptor(uint16_t);
|
||||
|
||||
uint8_t *Virtual_Com_Port_GetLineCoding(uint16_t Length);
|
||||
uint8_t *Virtual_Com_Port_SetLineCoding(uint16_t Length);
|
||||
|
||||
#endif /* __usb_prop_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
270
FW/Core/001-base_rt/USB/CONFIG/usb_pwr.c
Normal file
270
FW/Core/001-base_rt/USB/CONFIG/usb_pwr.c
Normal file
@ -0,0 +1,270 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_pwr.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 21-January-2013
|
||||
* @brief Connection/disconnection & power management
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_lib.h"
|
||||
#include "usb_conf.h"
|
||||
#include "usb_pwr.h"
|
||||
#include "hw_config.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
__IO uint32_t bDeviceState = UNCONNECTED; /* USB device status */
|
||||
__IO bool fSuspendEnabled = TRUE; /* true when suspend is possible */
|
||||
__IO uint32_t EP[8];
|
||||
|
||||
struct
|
||||
{
|
||||
__IO RESUME_STATE eState;
|
||||
__IO uint8_t bESOFcnt;
|
||||
}
|
||||
ResumeS;
|
||||
|
||||
__IO uint32_t remotewakeupon=0;
|
||||
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Extern function prototypes ------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PowerOn
|
||||
* Description :
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : USB_SUCCESS.
|
||||
*******************************************************************************/
|
||||
RESULT PowerOn(void)
|
||||
{
|
||||
uint16_t wRegVal;
|
||||
|
||||
/*** cable plugged-in ? ***/
|
||||
USB_Cable_Config(ENABLE);
|
||||
|
||||
/*** CNTR_PWDN = 0 ***/
|
||||
wRegVal = CNTR_FRES;
|
||||
_SetCNTR(wRegVal);
|
||||
|
||||
/*** CNTR_FRES = 0 ***/
|
||||
wInterrupt_Mask = 0;
|
||||
_SetCNTR(wInterrupt_Mask);
|
||||
/*** Clear pending interrupts ***/
|
||||
_SetISTR(0);
|
||||
/*** Set interrupt mask ***/
|
||||
wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM;
|
||||
_SetCNTR(wInterrupt_Mask);
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PowerOff
|
||||
* Description : handles switch-off conditions
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : USB_SUCCESS.
|
||||
*******************************************************************************/
|
||||
RESULT PowerOff()
|
||||
{
|
||||
/* disable all interrupts and force USB reset */
|
||||
_SetCNTR(CNTR_FRES);
|
||||
/* clear interrupt status register */
|
||||
_SetISTR(0);
|
||||
/* Disable the Pull-Up*/
|
||||
USB_Cable_Config(DISABLE);
|
||||
/* switch-off device */
|
||||
_SetCNTR(CNTR_FRES + CNTR_PDWN);
|
||||
/* sw variables reset */
|
||||
/* ... */
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Suspend
|
||||
* Description : sets suspend mode operating conditions
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : USB_SUCCESS.
|
||||
*******************************************************************************/
|
||||
void Suspend(void)
|
||||
{
|
||||
uint32_t i =0;
|
||||
uint16_t wCNTR;
|
||||
__IO uint32_t savePWR_CR=0;
|
||||
/* suspend preparation */
|
||||
/* ... */
|
||||
|
||||
/*Store CNTR value */
|
||||
wCNTR = _GetCNTR();
|
||||
|
||||
/* This a sequence to apply a force RESET to handle a robustness case */
|
||||
|
||||
/*Store endpoints registers status */
|
||||
for (i=0; i<8; i++) EP[i] = _GetENDPOINT(i);
|
||||
|
||||
/* unmask RESET flag */
|
||||
wCNTR|=CNTR_RESETM;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/*apply FRES */
|
||||
wCNTR|=CNTR_FRES;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/*clear FRES*/
|
||||
wCNTR&=~CNTR_FRES;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/*poll for RESET flag in ISTR*/
|
||||
while((_GetISTR()&ISTR_RESET) == 0);
|
||||
|
||||
/* clear RESET flag in ISTR */
|
||||
_SetISTR((uint16_t)CLR_RESET);
|
||||
|
||||
/*restore Enpoints*/
|
||||
for (i=0; i<8; i++)
|
||||
_SetENDPOINT(i, EP[i]);
|
||||
|
||||
/* Now it is safe to enter macrocell in suspend mode */
|
||||
wCNTR |= CNTR_FSUSP;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/* force low-power mode in the macrocell */
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR |= CNTR_LPMODE;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
Enter_LowPowerMode();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Resume_Init
|
||||
* Description : Handles wake-up restoring normal operations
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : USB_SUCCESS.
|
||||
*******************************************************************************/
|
||||
void Resume_Init(void)
|
||||
{
|
||||
uint16_t wCNTR;
|
||||
|
||||
/* ------------------ ONLY WITH BUS-POWERED DEVICES ---------------------- */
|
||||
/* restart the clocks */
|
||||
/* ... */
|
||||
|
||||
/* CNTR_LPMODE = 0 */
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR &= (~CNTR_LPMODE);
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/* restore full power */
|
||||
/* ... on connected devices */
|
||||
Leave_LowPowerMode();
|
||||
|
||||
/* reset FSUSP bit */
|
||||
_SetCNTR(IMR_MSK);
|
||||
|
||||
/* reverse suspend preparation */
|
||||
/* ... */
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Resume
|
||||
* Description : This is the state machine handling resume operations and
|
||||
* timing sequence. The control is based on the Resume structure
|
||||
* variables and on the ESOF interrupt calling this subroutine
|
||||
* without changing machine state.
|
||||
* Input : a state machine value (RESUME_STATE)
|
||||
* RESUME_ESOF doesn't change ResumeS.eState allowing
|
||||
* decrementing of the ESOF counter in different states.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Resume(RESUME_STATE eResumeSetVal)
|
||||
{
|
||||
uint16_t wCNTR;
|
||||
|
||||
if (eResumeSetVal != RESUME_ESOF)
|
||||
ResumeS.eState = eResumeSetVal;
|
||||
switch (ResumeS.eState)
|
||||
{
|
||||
case RESUME_EXTERNAL:
|
||||
if (remotewakeupon ==0)
|
||||
{
|
||||
Resume_Init();
|
||||
ResumeS.eState = RESUME_OFF;
|
||||
}
|
||||
else /* RESUME detected during the RemoteWAkeup signalling => keep RemoteWakeup handling*/
|
||||
{
|
||||
ResumeS.eState = RESUME_ON;
|
||||
}
|
||||
break;
|
||||
case RESUME_INTERNAL:
|
||||
Resume_Init();
|
||||
ResumeS.eState = RESUME_START;
|
||||
remotewakeupon = 1;
|
||||
break;
|
||||
case RESUME_LATER:
|
||||
ResumeS.bESOFcnt = 2;
|
||||
ResumeS.eState = RESUME_WAIT;
|
||||
break;
|
||||
case RESUME_WAIT:
|
||||
ResumeS.bESOFcnt--;
|
||||
if (ResumeS.bESOFcnt == 0)
|
||||
ResumeS.eState = RESUME_START;
|
||||
break;
|
||||
case RESUME_START:
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR |= CNTR_RESUME;
|
||||
_SetCNTR(wCNTR);
|
||||
ResumeS.eState = RESUME_ON;
|
||||
ResumeS.bESOFcnt = 10;
|
||||
break;
|
||||
case RESUME_ON:
|
||||
ResumeS.bESOFcnt--;
|
||||
if (ResumeS.bESOFcnt == 0)
|
||||
{
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR &= (~CNTR_RESUME);
|
||||
_SetCNTR(wCNTR);
|
||||
ResumeS.eState = RESUME_OFF;
|
||||
remotewakeupon = 0;
|
||||
}
|
||||
break;
|
||||
case RESUME_OFF:
|
||||
case RESUME_ESOF:
|
||||
default:
|
||||
ResumeS.eState = RESUME_OFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
72
FW/Core/001-base_rt/USB/CONFIG/usb_pwr.h
Normal file
72
FW/Core/001-base_rt/USB/CONFIG/usb_pwr.h
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_pwr.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 21-January-2013
|
||||
* @brief Connection/disconnection & power management header
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_PWR_H
|
||||
#define __USB_PWR_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef enum _RESUME_STATE
|
||||
{
|
||||
RESUME_EXTERNAL,
|
||||
RESUME_INTERNAL,
|
||||
RESUME_LATER,
|
||||
RESUME_WAIT,
|
||||
RESUME_START,
|
||||
RESUME_ON,
|
||||
RESUME_OFF,
|
||||
RESUME_ESOF
|
||||
} RESUME_STATE;
|
||||
|
||||
typedef enum _DEVICE_STATE
|
||||
{
|
||||
UNCONNECTED,
|
||||
ATTACHED,
|
||||
POWERED,
|
||||
SUSPENDED,
|
||||
ADDRESSED,
|
||||
CONFIGURED
|
||||
} DEVICE_STATE;
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void Suspend(void);
|
||||
void Resume_Init(void);
|
||||
void Resume(RESUME_STATE eResumeSetVal);
|
||||
RESULT PowerOn(void);
|
||||
RESULT PowerOff(void);
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern __IO uint32_t bDeviceState; /* USB device status */
|
||||
extern __IO bool fSuspendEnabled; /* true when suspend is possible */
|
||||
|
||||
#endif /*__USB_PWR_H*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
23
FW/Core/001-base_rt/USB/SConscript
Normal file
23
FW/Core/001-base_rt/USB/SConscript
Normal file
@ -0,0 +1,23 @@
|
||||
from building import *
|
||||
import os
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
src += Glob('*.cpp')
|
||||
|
||||
src += Glob('CONFIG/*.c')
|
||||
src += Glob('air32_USB-FS-Device_Driver/src/*.c')
|
||||
|
||||
CPPPATH = [ cwd ]
|
||||
CPPPATH += [cwd + "/CONFIG" ]
|
||||
CPPPATH += [cwd + "/air32_USB-FS-Device_Driver/inc" ]
|
||||
|
||||
|
||||
group = DefineGroup('USB', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
list = os.listdir(cwd)
|
||||
for item in list:
|
||||
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
|
||||
group = group + SConscript(os.path.join(item, 'SConscript'))
|
||||
|
||||
Return('group')
|
@ -0,0 +1,259 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_core.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief Standard protocol processing functions prototypes
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_CORE_H
|
||||
#define __USB_CORE_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef enum _CONTROL_STATE
|
||||
{
|
||||
WAIT_SETUP, /* 0 */
|
||||
SETTING_UP, /* 1 */
|
||||
IN_DATA, /* 2 */
|
||||
OUT_DATA, /* 3 */
|
||||
LAST_IN_DATA, /* 4 */
|
||||
LAST_OUT_DATA, /* 5 */
|
||||
WAIT_STATUS_IN, /* 7 */
|
||||
WAIT_STATUS_OUT, /* 8 */
|
||||
STALLED, /* 9 */
|
||||
PAUSE /* 10 */
|
||||
} CONTROL_STATE; /* The state machine states of a control pipe */
|
||||
|
||||
typedef struct OneDescriptor
|
||||
{
|
||||
uint8_t *Descriptor;
|
||||
uint16_t Descriptor_Size;
|
||||
}
|
||||
ONE_DESCRIPTOR, *PONE_DESCRIPTOR;
|
||||
/* All the request process routines return a value of this type
|
||||
If the return value is not SUCCESS or NOT_READY,
|
||||
the software will STALL the correspond endpoint */
|
||||
typedef enum _RESULT
|
||||
{
|
||||
USB_SUCCESS = 0, /* Process successfully */
|
||||
USB_ERROR,
|
||||
USB_UNSUPPORT,
|
||||
USB_NOT_READY /* The process has not been finished, endpoint will be
|
||||
NAK to further request */
|
||||
} RESULT;
|
||||
|
||||
|
||||
/*-*-*-*-*-*-*-*-*-*-* Definitions for endpoint level -*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
typedef struct _ENDPOINT_INFO
|
||||
{
|
||||
/* When send data out of the device,
|
||||
CopyData() is used to get data buffer 'Length' bytes data
|
||||
if Length is 0,
|
||||
CopyData() returns the total length of the data
|
||||
if the request is not supported, returns 0
|
||||
(NEW Feature )
|
||||
if CopyData() returns -1, the calling routine should not proceed
|
||||
further and will resume the SETUP process by the class device
|
||||
if Length is not 0,
|
||||
CopyData() returns a pointer to indicate the data location
|
||||
Usb_wLength is the data remain to be sent,
|
||||
Usb_wOffset is the Offset of original data
|
||||
When receive data from the host,
|
||||
CopyData() is used to get user data buffer which is capable
|
||||
of Length bytes data to copy data from the endpoint buffer.
|
||||
if Length is 0,
|
||||
CopyData() returns the available data length,
|
||||
if Length is not 0,
|
||||
CopyData() returns user buffer address
|
||||
Usb_rLength is the data remain to be received,
|
||||
Usb_rPointer is the Offset of data buffer
|
||||
*/
|
||||
uint16_t Usb_wLength;
|
||||
uint16_t Usb_wOffset;
|
||||
uint16_t PacketSize;
|
||||
uint8_t *(*CopyData)(uint16_t Length);
|
||||
} ENDPOINT_INFO;
|
||||
|
||||
/*-*-*-*-*-*-*-*-*-*-*-* Definitions for device level -*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
|
||||
typedef struct _DEVICE
|
||||
{
|
||||
uint8_t Total_Endpoint; /* Number of endpoints that are used */
|
||||
uint8_t Total_Configuration;/* Number of configuration available */
|
||||
}
|
||||
DEVICE;
|
||||
|
||||
typedef union
|
||||
{
|
||||
uint16_t w;
|
||||
struct BW
|
||||
{
|
||||
uint8_t bb1;
|
||||
uint8_t bb0;
|
||||
}
|
||||
bw;
|
||||
} uint16_t_uint8_t;
|
||||
|
||||
typedef struct _DEVICE_INFO
|
||||
{
|
||||
uint8_t USBbmRequestType; /* bmRequestType */
|
||||
uint8_t USBbRequest; /* bRequest */
|
||||
uint16_t_uint8_t USBwValues; /* wValue */
|
||||
uint16_t_uint8_t USBwIndexs; /* wIndex */
|
||||
uint16_t_uint8_t USBwLengths; /* wLength */
|
||||
|
||||
uint8_t ControlState; /* of type CONTROL_STATE */
|
||||
uint8_t Current_Feature;
|
||||
uint8_t Current_Configuration; /* Selected configuration */
|
||||
uint8_t Current_Interface; /* Selected interface of current configuration */
|
||||
uint8_t Current_AlternateSetting;/* Selected Alternate Setting of current
|
||||
interface*/
|
||||
|
||||
ENDPOINT_INFO Ctrl_Info;
|
||||
} DEVICE_INFO;
|
||||
|
||||
typedef struct _DEVICE_PROP
|
||||
{
|
||||
void (*Init)(void); /* Initialize the device */
|
||||
void (*Reset)(void); /* Reset routine of this device */
|
||||
|
||||
/* Device dependent process after the status stage */
|
||||
void (*Process_Status_IN)(void);
|
||||
void (*Process_Status_OUT)(void);
|
||||
|
||||
/* Procedure of process on setup stage of a class specified request with data stage */
|
||||
/* All class specified requests with data stage are processed in Class_Data_Setup
|
||||
Class_Data_Setup()
|
||||
responses to check all special requests and fills ENDPOINT_INFO
|
||||
according to the request
|
||||
If IN tokens are expected, then wLength & wOffset will be filled
|
||||
with the total transferring bytes and the starting position
|
||||
If OUT tokens are expected, then rLength & rOffset will be filled
|
||||
with the total expected bytes and the starting position in the buffer
|
||||
|
||||
If the request is valid, Class_Data_Setup returns SUCCESS, else UNSUPPORT
|
||||
|
||||
CAUTION:
|
||||
Since GET_CONFIGURATION & GET_INTERFACE are highly related to
|
||||
the individual classes, they will be checked and processed here.
|
||||
*/
|
||||
RESULT (*Class_Data_Setup)(uint8_t RequestNo);
|
||||
|
||||
/* Procedure of process on setup stage of a class specified request without data stage */
|
||||
/* All class specified requests without data stage are processed in Class_NoData_Setup
|
||||
Class_NoData_Setup
|
||||
responses to check all special requests and perform the request
|
||||
|
||||
CAUTION:
|
||||
Since SET_CONFIGURATION & SET_INTERFACE are highly related to
|
||||
the individual classes, they will be checked and processed here.
|
||||
*/
|
||||
RESULT (*Class_NoData_Setup)(uint8_t RequestNo);
|
||||
|
||||
/*Class_Get_Interface_Setting
|
||||
This function is used by the file usb_core.c to test if the selected Interface
|
||||
and Alternate Setting (uint8_t Interface, uint8_t AlternateSetting) are supported by
|
||||
the application.
|
||||
This function is writing by user. It should return "SUCCESS" if the Interface
|
||||
and Alternate Setting are supported by the application or "UNSUPPORT" if they
|
||||
are not supported. */
|
||||
|
||||
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);
|
||||
|
||||
/* This field is not used in current library version. It is kept only for
|
||||
compatibility with previous versions */
|
||||
void* RxEP_buffer;
|
||||
|
||||
uint8_t MaxPacketSize;
|
||||
|
||||
} DEVICE_PROP;
|
||||
|
||||
typedef struct _USER_STANDARD_REQUESTS
|
||||
{
|
||||
void (*User_GetConfiguration)(void); /* Get Configuration */
|
||||
void (*User_SetConfiguration)(void); /* Set Configuration */
|
||||
void (*User_GetInterface)(void); /* Get Interface */
|
||||
void (*User_SetInterface)(void); /* Set Interface */
|
||||
void (*User_GetStatus)(void); /* Get Status */
|
||||
void (*User_ClearFeature)(void); /* Clear Feature */
|
||||
void (*User_SetEndPointFeature)(void); /* Set Endpoint Feature */
|
||||
void (*User_SetDeviceFeature)(void); /* Set Device Feature */
|
||||
void (*User_SetDeviceAddress)(void); /* Set Device Address */
|
||||
}
|
||||
USER_STANDARD_REQUESTS;
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define Type_Recipient (pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT))
|
||||
|
||||
#define Usb_rLength Usb_wLength
|
||||
#define Usb_rOffset Usb_wOffset
|
||||
|
||||
#define USBwValue USBwValues.w
|
||||
#define USBwValue0 USBwValues.bw.bb0
|
||||
#define USBwValue1 USBwValues.bw.bb1
|
||||
#define USBwIndex USBwIndexs.w
|
||||
#define USBwIndex0 USBwIndexs.bw.bb0
|
||||
#define USBwIndex1 USBwIndexs.bw.bb1
|
||||
#define USBwLength USBwLengths.w
|
||||
#define USBwLength0 USBwLengths.bw.bb0
|
||||
#define USBwLength1 USBwLengths.bw.bb1
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
uint8_t Setup0_Process(void);
|
||||
uint8_t Post0_Process(void);
|
||||
uint8_t Out0_Process(void);
|
||||
uint8_t In0_Process(void);
|
||||
|
||||
RESULT Standard_SetEndPointFeature(void);
|
||||
RESULT Standard_SetDeviceFeature(void);
|
||||
|
||||
uint8_t *Standard_GetConfiguration(uint16_t Length);
|
||||
RESULT Standard_SetConfiguration(void);
|
||||
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);
|
||||
RESULT Standard_ClearFeature(void);
|
||||
void SetDeviceAddress(uint8_t);
|
||||
void NOP_Process(void);
|
||||
|
||||
extern DEVICE_PROP Device_Property;
|
||||
extern USER_STANDARD_REQUESTS User_Standard_Requests;
|
||||
extern DEVICE Device_Table;
|
||||
extern DEVICE_INFO Device_Info;
|
||||
|
||||
/* cells saving status during interrupt servicing */
|
||||
extern __IO uint16_t SaveRState;
|
||||
extern __IO uint16_t SaveTState;
|
||||
|
||||
#endif /* __USB_CORE_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -0,0 +1,92 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_def.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief Definitions related to USB Core
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_DEF_H
|
||||
#define __USB_DEF_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef enum _RECIPIENT_TYPE
|
||||
{
|
||||
DEVICE_RECIPIENT, /* Recipient device */
|
||||
INTERFACE_RECIPIENT, /* Recipient interface */
|
||||
ENDPOINT_RECIPIENT, /* Recipient endpoint */
|
||||
OTHER_RECIPIENT
|
||||
} RECIPIENT_TYPE;
|
||||
|
||||
|
||||
typedef enum _STANDARD_REQUESTS
|
||||
{
|
||||
GET_STATUS = 0,
|
||||
CLEAR_FEATURE,
|
||||
RESERVED1,
|
||||
SET_FEATURE,
|
||||
RESERVED2,
|
||||
SET_ADDRESS,
|
||||
GET_DESCRIPTOR,
|
||||
SET_DESCRIPTOR,
|
||||
GET_CONFIGURATION,
|
||||
SET_CONFIGURATION,
|
||||
GET_INTERFACE,
|
||||
SET_INTERFACE,
|
||||
TOTAL_sREQUEST, /* Total number of Standard request */
|
||||
SYNCH_FRAME = 12
|
||||
} STANDARD_REQUESTS;
|
||||
|
||||
/* Definition of "USBwValue" */
|
||||
typedef enum _DESCRIPTOR_TYPE
|
||||
{
|
||||
DEVICE_DESCRIPTOR = 1,
|
||||
CONFIG_DESCRIPTOR,
|
||||
STRING_DESCRIPTOR,
|
||||
INTERFACE_DESCRIPTOR,
|
||||
ENDPOINT_DESCRIPTOR
|
||||
} DESCRIPTOR_TYPE;
|
||||
|
||||
/* Feature selector of a SET_FEATURE or CLEAR_FEATURE */
|
||||
typedef enum _FEATURE_SELECTOR
|
||||
{
|
||||
ENDPOINT_STALL,
|
||||
DEVICE_REMOTE_WAKEUP
|
||||
} FEATURE_SELECTOR;
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Definition of "USBbmRequestType" */
|
||||
#define REQUEST_TYPE 0x60 /* Mask to get request type */
|
||||
#define STANDARD_REQUEST 0x00 /* Standard request */
|
||||
#define CLASS_REQUEST 0x20 /* Class request */
|
||||
#define VENDOR_REQUEST 0x40 /* Vendor request */
|
||||
|
||||
#define RECIPIENT 0x1F /* Mask to get recipient */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
#endif /* __USB_DEF_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -0,0 +1,62 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_init.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief Initialization routines & global variables
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_INIT_H
|
||||
#define __USB_INIT_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void USB_Init(void);
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
/* The number of current endpoint, it will be used to specify an endpoint */
|
||||
extern uint8_t EPindex;
|
||||
/* The number of current device, it is an index to the Device_Table */
|
||||
/*extern uint8_t Device_no; */
|
||||
/* Points to the DEVICE_INFO structure of current device */
|
||||
/* The purpose of this register is to speed up the execution */
|
||||
extern DEVICE_INFO* pInformation;
|
||||
/* Points to the DEVICE_PROP structure of current device */
|
||||
/* The purpose of this register is to speed up the execution */
|
||||
extern DEVICE_PROP* pProperty;
|
||||
/* Temporary save the state of Rx & Tx status. */
|
||||
/* Whenever the Rx or Tx state is changed, its value is saved */
|
||||
/* in this variable first and will be set to the EPRB or EPRA */
|
||||
/* at the end of interrupt process */
|
||||
extern USER_STANDARD_REQUESTS *pUser_Standard_Requests;
|
||||
|
||||
extern uint16_t SaveState ;
|
||||
extern uint16_t wInterrupt_Mask;
|
||||
|
||||
#endif /* __USB_INIT_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -0,0 +1,45 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_int.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief Endpoint CTR (Low and High) interrupt's service routines prototypes
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_INT_H
|
||||
#define __USB_INT_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void CTR_LP(void);
|
||||
void CTR_HP(void);
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
|
||||
#endif /* __USB_INT_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -0,0 +1,52 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_lib.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief USB library include files
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_LIB_H
|
||||
#define __USB_LIB_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "hw_config.h"
|
||||
#include "usb_type.h"
|
||||
#include "usb_regs.h"
|
||||
#include "usb_def.h"
|
||||
#include "usb_core.h"
|
||||
#include "usb_init.h"
|
||||
#include "usb_sil.h"
|
||||
#include "usb_mem.h"
|
||||
#include "usb_int.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
/* External variables --------------------------------------------------------*/
|
||||
|
||||
#endif /* __USB_LIB_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -0,0 +1,45 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_mem.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief Utility prototypes functions for memory/PMA transfers
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_MEM_H
|
||||
#define __USB_MEM_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
|
||||
void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
|
||||
#endif /*__USB_MEM_H*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -0,0 +1,683 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_regs.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief Interface prototype functions to USB cell registers
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_REGS_H
|
||||
#define __USB_REGS_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef enum _EP_DBUF_DIR
|
||||
{
|
||||
/* double buffered endpoint direction */
|
||||
EP_DBUF_ERR,
|
||||
EP_DBUF_OUT,
|
||||
EP_DBUF_IN
|
||||
} EP_DBUF_DIR;
|
||||
|
||||
/* endpoint buffer number */
|
||||
enum EP_BUF_NUM
|
||||
{
|
||||
EP_NOBUF,
|
||||
EP_BUF0,
|
||||
EP_BUF1
|
||||
};
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define RegBase (0x40005C00L) /* USB_IP Peripheral Registers base address */
|
||||
#define PMAAddr (0x40006000L) /* USB_IP Packet Memory Area base address */
|
||||
|
||||
/******************************************************************************/
|
||||
/* General registers */
|
||||
/******************************************************************************/
|
||||
|
||||
/* Control register */
|
||||
#define CNTR ((__IO unsigned *)(RegBase + 0x40))
|
||||
/* Interrupt status register */
|
||||
#define ISTR ((__IO unsigned *)(RegBase + 0x44))
|
||||
/* Frame number register */
|
||||
#define FNR ((__IO unsigned *)(RegBase + 0x48))
|
||||
/* Device address register */
|
||||
#define DADDR ((__IO unsigned *)(RegBase + 0x4C))
|
||||
/* Buffer Table address register */
|
||||
#define BTABLE ((__IO unsigned *)(RegBase + 0x50))
|
||||
|
||||
#define DP_PUUP *((__IO unsigned *)(RegBase + 0x54))
|
||||
|
||||
/******************************************************************************/
|
||||
/* Endpoint registers */
|
||||
/******************************************************************************/
|
||||
#define EP0REG ((__IO unsigned *)(RegBase)) /* endpoint 0 register address */
|
||||
|
||||
/* Endpoint Addresses (w/direction) */
|
||||
#define EP0_OUT ((uint8_t)0x00)
|
||||
#define EP0_IN ((uint8_t)0x80)
|
||||
#define EP1_OUT ((uint8_t)0x01)
|
||||
#define EP1_IN ((uint8_t)0x81)
|
||||
#define EP2_OUT ((uint8_t)0x02)
|
||||
#define EP2_IN ((uint8_t)0x82)
|
||||
#define EP3_OUT ((uint8_t)0x03)
|
||||
#define EP3_IN ((uint8_t)0x83)
|
||||
#define EP4_OUT ((uint8_t)0x04)
|
||||
#define EP4_IN ((uint8_t)0x84)
|
||||
#define EP5_OUT ((uint8_t)0x05)
|
||||
#define EP5_IN ((uint8_t)0x85)
|
||||
#define EP6_OUT ((uint8_t)0x06)
|
||||
#define EP6_IN ((uint8_t)0x86)
|
||||
#define EP7_OUT ((uint8_t)0x07)
|
||||
#define EP7_IN ((uint8_t)0x87)
|
||||
|
||||
/* endpoints enumeration */
|
||||
#define ENDP0 ((uint8_t)0)
|
||||
#define ENDP1 ((uint8_t)1)
|
||||
#define ENDP2 ((uint8_t)2)
|
||||
#define ENDP3 ((uint8_t)3)
|
||||
#define ENDP4 ((uint8_t)4)
|
||||
#define ENDP5 ((uint8_t)5)
|
||||
#define ENDP6 ((uint8_t)6)
|
||||
#define ENDP7 ((uint8_t)7)
|
||||
|
||||
/******************************************************************************/
|
||||
/* ISTR interrupt events */
|
||||
/******************************************************************************/
|
||||
#define ISTR_CTR (0x8000) /* Correct TRansfer (clear-only bit) */
|
||||
#define ISTR_DOVR (0x4000) /* DMA OVeR/underrun (clear-only bit) */
|
||||
#define ISTR_ERR (0x2000) /* ERRor (clear-only bit) */
|
||||
#define ISTR_WKUP (0x1000) /* WaKe UP (clear-only bit) */
|
||||
#define ISTR_SUSP (0x0800) /* SUSPend (clear-only bit) */
|
||||
#define ISTR_RESET (0x0400) /* RESET (clear-only bit) */
|
||||
#define ISTR_SOF (0x0200) /* Start Of Frame (clear-only bit) */
|
||||
#define ISTR_ESOF (0x0100) /* Expected Start Of Frame (clear-only bit) */
|
||||
|
||||
|
||||
#define ISTR_DIR (0x0010) /* DIRection of transaction (read-only bit) */
|
||||
#define ISTR_EP_ID (0x000F) /* EndPoint IDentifier (read-only bit) */
|
||||
|
||||
#define CLR_CTR (~ISTR_CTR) /* clear Correct TRansfer bit */
|
||||
#define CLR_DOVR (~ISTR_DOVR) /* clear DMA OVeR/underrun bit*/
|
||||
#define CLR_ERR (~ISTR_ERR) /* clear ERRor bit */
|
||||
#define CLR_WKUP (~ISTR_WKUP) /* clear WaKe UP bit */
|
||||
#define CLR_SUSP (~ISTR_SUSP) /* clear SUSPend bit */
|
||||
#define CLR_RESET (~ISTR_RESET) /* clear RESET bit */
|
||||
#define CLR_SOF (~ISTR_SOF) /* clear Start Of Frame bit */
|
||||
#define CLR_ESOF (~ISTR_ESOF) /* clear Expected Start Of Frame bit */
|
||||
|
||||
/******************************************************************************/
|
||||
/* CNTR control register bits definitions */
|
||||
/******************************************************************************/
|
||||
#define CNTR_CTRM (0x8000) /* Correct TRansfer Mask */
|
||||
#define CNTR_DOVRM (0x4000) /* DMA OVeR/underrun Mask */
|
||||
#define CNTR_ERRM (0x2000) /* ERRor Mask */
|
||||
#define CNTR_WKUPM (0x1000) /* WaKe UP Mask */
|
||||
#define CNTR_SUSPM (0x0800) /* SUSPend Mask */
|
||||
#define CNTR_RESETM (0x0400) /* RESET Mask */
|
||||
#define CNTR_SOFM (0x0200) /* Start Of Frame Mask */
|
||||
#define CNTR_ESOFM (0x0100) /* Expected Start Of Frame Mask */
|
||||
|
||||
|
||||
#define CNTR_RESUME (0x0010) /* RESUME request */
|
||||
#define CNTR_FSUSP (0x0008) /* Force SUSPend */
|
||||
#define CNTR_LPMODE (0x0004) /* Low-power MODE */
|
||||
#define CNTR_PDWN (0x0002) /* Power DoWN */
|
||||
#define CNTR_FRES (0x0001) /* Force USB RESet */
|
||||
|
||||
/******************************************************************************/
|
||||
/* FNR Frame Number Register bit definitions */
|
||||
/******************************************************************************/
|
||||
#define FNR_RXDP (0x8000) /* status of D+ data line */
|
||||
#define FNR_RXDM (0x4000) /* status of D- data line */
|
||||
#define FNR_LCK (0x2000) /* LoCKed */
|
||||
#define FNR_LSOF (0x1800) /* Lost SOF */
|
||||
#define FNR_FN (0x07FF) /* Frame Number */
|
||||
/******************************************************************************/
|
||||
/* DADDR Device ADDRess bit definitions */
|
||||
/******************************************************************************/
|
||||
#define DADDR_EF (0x80)
|
||||
#define DADDR_ADD (0x7F)
|
||||
/******************************************************************************/
|
||||
/* Endpoint register */
|
||||
/******************************************************************************/
|
||||
/* bit positions */
|
||||
#define EP_CTR_RX (0x8000) /* EndPoint Correct TRansfer RX */
|
||||
#define EP_DTOG_RX (0x4000) /* EndPoint Data TOGGLE RX */
|
||||
#define EPRX_STAT (0x3000) /* EndPoint RX STATus bit field */
|
||||
#define EP_SETUP (0x0800) /* EndPoint SETUP */
|
||||
#define EP_T_FIELD (0x0600) /* EndPoint TYPE */
|
||||
#define EP_KIND (0x0100) /* EndPoint KIND */
|
||||
#define EP_CTR_TX (0x0080) /* EndPoint Correct TRansfer TX */
|
||||
#define EP_DTOG_TX (0x0040) /* EndPoint Data TOGGLE TX */
|
||||
#define EPTX_STAT (0x0030) /* EndPoint TX STATus bit field */
|
||||
#define EPADDR_FIELD (0x000F) /* EndPoint ADDRess FIELD */
|
||||
|
||||
/* EndPoint REGister MASK (no toggle fields) */
|
||||
#define EPREG_MASK (EP_CTR_RX|EP_SETUP|EP_T_FIELD|EP_KIND|EP_CTR_TX|EPADDR_FIELD)
|
||||
|
||||
/* EP_TYPE[1:0] EndPoint TYPE */
|
||||
#define EP_TYPE_MASK (0x0600) /* EndPoint TYPE Mask */
|
||||
#define EP_BULK (0x0000) /* EndPoint BULK */
|
||||
#define EP_CONTROL (0x0200) /* EndPoint CONTROL */
|
||||
#define EP_ISOCHRONOUS (0x0400) /* EndPoint ISOCHRONOUS */
|
||||
#define EP_INTERRUPT (0x0600) /* EndPoint INTERRUPT */
|
||||
#define EP_T_MASK (~EP_T_FIELD & EPREG_MASK)
|
||||
|
||||
|
||||
/* EP_KIND EndPoint KIND */
|
||||
#define EPKIND_MASK (~EP_KIND & EPREG_MASK)
|
||||
|
||||
/* STAT_TX[1:0] STATus for TX transfer */
|
||||
#define EP_TX_DIS (0x0000) /* EndPoint TX DISabled */
|
||||
#define EP_TX_STALL (0x0010) /* EndPoint TX STALLed */
|
||||
#define EP_TX_NAK (0x0020) /* EndPoint TX NAKed */
|
||||
#define EP_TX_VALID (0x0030) /* EndPoint TX VALID */
|
||||
#define EPTX_DTOG1 (0x0010) /* EndPoint TX Data TOGgle bit1 */
|
||||
#define EPTX_DTOG2 (0x0020) /* EndPoint TX Data TOGgle bit2 */
|
||||
#define EPTX_DTOGMASK (EPTX_STAT|EPREG_MASK)
|
||||
|
||||
/* STAT_RX[1:0] STATus for RX transfer */
|
||||
#define EP_RX_DIS (0x0000) /* EndPoint RX DISabled */
|
||||
#define EP_RX_STALL (0x1000) /* EndPoint RX STALLed */
|
||||
#define EP_RX_NAK (0x2000) /* EndPoint RX NAKed */
|
||||
#define EP_RX_VALID (0x3000) /* EndPoint RX VALID */
|
||||
#define EPRX_DTOG1 (0x1000) /* EndPoint RX Data TOGgle bit1 */
|
||||
#define EPRX_DTOG2 (0x2000) /* EndPoint RX Data TOGgle bit1 */
|
||||
#define EPRX_DTOGMASK (EPRX_STAT|EPREG_MASK)
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* SetCNTR */
|
||||
#define _SetCNTR(wRegValue) (*CNTR = (uint16_t)wRegValue)
|
||||
|
||||
/* SetISTR */
|
||||
#define _SetISTR(wRegValue) (*ISTR = (uint16_t)wRegValue)
|
||||
|
||||
/* SetDADDR */
|
||||
#define _SetDADDR(wRegValue) (*DADDR = (uint16_t)wRegValue)
|
||||
|
||||
/* SetBTABLE */
|
||||
#define _SetBTABLE(wRegValue)(*BTABLE = (uint16_t)(wRegValue & 0xFFF8))
|
||||
|
||||
/* GetCNTR */
|
||||
#define _GetCNTR() ((uint16_t) *CNTR)
|
||||
|
||||
/* GetISTR */
|
||||
#define _GetISTR() ((uint16_t) *ISTR)
|
||||
|
||||
/* GetFNR */
|
||||
#define _GetFNR() ((uint16_t) *FNR)
|
||||
|
||||
/* GetDADDR */
|
||||
#define _GetDADDR() ((uint16_t) *DADDR)
|
||||
|
||||
/* GetBTABLE */
|
||||
#define _GetBTABLE() ((uint16_t) *BTABLE)
|
||||
|
||||
/* SetENDPOINT */
|
||||
#define _SetENDPOINT(bEpNum,wRegValue) (*(EP0REG + bEpNum)= \
|
||||
(uint16_t)wRegValue)
|
||||
|
||||
/* GetENDPOINT */
|
||||
#define _GetENDPOINT(bEpNum) ((uint16_t)(*(EP0REG + bEpNum)))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPType
|
||||
* Description : sets the type in the endpoint register(bits EP_TYPE[1:0])
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wType
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPType(bEpNum,wType) (_SetENDPOINT(bEpNum,\
|
||||
((_GetENDPOINT(bEpNum) & EP_T_MASK) | wType )))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetEPType
|
||||
* Description : gets the type in the endpoint register(bits EP_TYPE[1:0])
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Endpoint Type
|
||||
*******************************************************************************/
|
||||
#define _GetEPType(bEpNum) (_GetENDPOINT(bEpNum) & EP_T_FIELD)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPTxStatus
|
||||
* Description : sets the status for tx transfer (bits STAT_TX[1:0]).
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wState: new state
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPTxStatus(bEpNum,wState) {\
|
||||
register uint16_t _wRegVal; \
|
||||
_wRegVal = _GetENDPOINT(bEpNum) & EPTX_DTOGMASK;\
|
||||
/* toggle first bit ? */ \
|
||||
if((EPTX_DTOG1 & wState)!= 0) \
|
||||
_wRegVal ^= EPTX_DTOG1; \
|
||||
/* toggle second bit ? */ \
|
||||
if((EPTX_DTOG2 & wState)!= 0) \
|
||||
_wRegVal ^= EPTX_DTOG2; \
|
||||
_SetENDPOINT(bEpNum, (_wRegVal | EP_CTR_RX|EP_CTR_TX)); \
|
||||
} /* _SetEPTxStatus */
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPRxStatus
|
||||
* Description : sets the status for rx transfer (bits STAT_TX[1:0])
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wState: new state.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPRxStatus(bEpNum,wState) {\
|
||||
register uint16_t _wRegVal; \
|
||||
\
|
||||
_wRegVal = _GetENDPOINT(bEpNum) & EPRX_DTOGMASK;\
|
||||
/* toggle first bit ? */ \
|
||||
if((EPRX_DTOG1 & wState)!= 0) \
|
||||
_wRegVal ^= EPRX_DTOG1; \
|
||||
/* toggle second bit ? */ \
|
||||
if((EPRX_DTOG2 & wState)!= 0) \
|
||||
_wRegVal ^= EPRX_DTOG2; \
|
||||
_SetENDPOINT(bEpNum, (_wRegVal | EP_CTR_RX|EP_CTR_TX)); \
|
||||
} /* _SetEPRxStatus */
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPRxTxStatus
|
||||
* Description : sets the status for rx & tx (bits STAT_TX[1:0] & STAT_RX[1:0])
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wStaterx: new state.
|
||||
* wStatetx: new state.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPRxTxStatus(bEpNum,wStaterx,wStatetx) {\
|
||||
register uint32_t _wRegVal; \
|
||||
\
|
||||
_wRegVal = _GetENDPOINT(bEpNum) & (EPRX_DTOGMASK |EPTX_STAT) ;\
|
||||
/* toggle first bit ? */ \
|
||||
if((EPRX_DTOG1 & wStaterx)!= 0) \
|
||||
_wRegVal ^= EPRX_DTOG1; \
|
||||
/* toggle second bit ? */ \
|
||||
if((EPRX_DTOG2 & wStaterx)!= 0) \
|
||||
_wRegVal ^= EPRX_DTOG2; \
|
||||
/* toggle first bit ? */ \
|
||||
if((EPTX_DTOG1 & wStatetx)!= 0) \
|
||||
_wRegVal ^= EPTX_DTOG1; \
|
||||
/* toggle second bit ? */ \
|
||||
if((EPTX_DTOG2 & wStatetx)!= 0) \
|
||||
_wRegVal ^= EPTX_DTOG2; \
|
||||
_SetENDPOINT(bEpNum, _wRegVal | EP_CTR_RX|EP_CTR_TX); \
|
||||
} /* _SetEPRxTxStatus */
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetEPTxStatus / GetEPRxStatus
|
||||
* Description : gets the status for tx/rx transfer (bits STAT_TX[1:0]
|
||||
* /STAT_RX[1:0])
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : status .
|
||||
*******************************************************************************/
|
||||
#define _GetEPTxStatus(bEpNum) ((uint16_t)_GetENDPOINT(bEpNum) & EPTX_STAT)
|
||||
|
||||
#define _GetEPRxStatus(bEpNum) ((uint16_t)_GetENDPOINT(bEpNum) & EPRX_STAT)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPTxValid / SetEPRxValid
|
||||
* Description : sets directly the VALID tx/rx-status into the enpoint register
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPTxValid(bEpNum) (_SetEPTxStatus(bEpNum, EP_TX_VALID))
|
||||
|
||||
#define _SetEPRxValid(bEpNum) (_SetEPRxStatus(bEpNum, EP_RX_VALID))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetTxStallStatus / GetRxStallStatus.
|
||||
* Description : checks stall condition in an endpoint.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : TRUE = endpoint in stall condition.
|
||||
*******************************************************************************/
|
||||
#define _GetTxStallStatus(bEpNum) (_GetEPTxStatus(bEpNum) \
|
||||
== EP_TX_STALL)
|
||||
#define _GetRxStallStatus(bEpNum) (_GetEPRxStatus(bEpNum) \
|
||||
== EP_RX_STALL)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEP_KIND / ClearEP_KIND.
|
||||
* Description : set & clear EP_KIND bit.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
|
||||
(EP_CTR_RX|EP_CTR_TX|((_GetENDPOINT(bEpNum) | EP_KIND) & EPREG_MASK))))
|
||||
#define _ClearEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
|
||||
(EP_CTR_RX|EP_CTR_TX|(_GetENDPOINT(bEpNum) & EPKIND_MASK))))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : Set_Status_Out / Clear_Status_Out.
|
||||
* Description : Sets/clears directly STATUS_OUT bit in the endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _Set_Status_Out(bEpNum) _SetEP_KIND(bEpNum)
|
||||
#define _Clear_Status_Out(bEpNum) _ClearEP_KIND(bEpNum)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPDoubleBuff / ClearEPDoubleBuff.
|
||||
* Description : Sets/clears directly EP_KIND bit in the endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPDoubleBuff(bEpNum) _SetEP_KIND(bEpNum)
|
||||
#define _ClearEPDoubleBuff(bEpNum) _ClearEP_KIND(bEpNum)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : ClearEP_CTR_RX / ClearEP_CTR_TX.
|
||||
* Description : Clears bit CTR_RX / CTR_TX in the endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _ClearEP_CTR_RX(bEpNum) (_SetENDPOINT(bEpNum,\
|
||||
_GetENDPOINT(bEpNum) & 0x7FFF & EPREG_MASK))
|
||||
#define _ClearEP_CTR_TX(bEpNum) (_SetENDPOINT(bEpNum,\
|
||||
_GetENDPOINT(bEpNum) & 0xFF7F & EPREG_MASK))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : ToggleDTOG_RX / ToggleDTOG_TX .
|
||||
* Description : Toggles DTOG_RX / DTOG_TX bit in the endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _ToggleDTOG_RX(bEpNum) (_SetENDPOINT(bEpNum, \
|
||||
EP_CTR_RX|EP_CTR_TX|EP_DTOG_RX | (_GetENDPOINT(bEpNum) & EPREG_MASK)))
|
||||
#define _ToggleDTOG_TX(bEpNum) (_SetENDPOINT(bEpNum, \
|
||||
EP_CTR_RX|EP_CTR_TX|EP_DTOG_TX | (_GetENDPOINT(bEpNum) & EPREG_MASK)))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : ClearDTOG_RX / ClearDTOG_TX.
|
||||
* Description : Clears DTOG_RX / DTOG_TX bit in the endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _ClearDTOG_RX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_RX) != 0)\
|
||||
_ToggleDTOG_RX(bEpNum)
|
||||
#define _ClearDTOG_TX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_TX) != 0)\
|
||||
_ToggleDTOG_TX(bEpNum)
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPAddress.
|
||||
* Description : Sets address in an endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* bAddr: Address.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPAddress(bEpNum,bAddr) _SetENDPOINT(bEpNum,\
|
||||
EP_CTR_RX|EP_CTR_TX|(_GetENDPOINT(bEpNum) & EPREG_MASK) | bAddr)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetEPAddress.
|
||||
* Description : Gets address in an endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#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))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPTxAddr / SetEPRxAddr.
|
||||
* Description : sets address of the tx/rx buffer.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wAddr: address to be set (must be word aligned).
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPTxAddr(bEpNum,wAddr) (*_pEPTxAddr(bEpNum) = ((wAddr >> 1) << 1))
|
||||
#define _SetEPRxAddr(bEpNum,wAddr) (*_pEPRxAddr(bEpNum) = ((wAddr >> 1) << 1))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetEPTxAddr / GetEPRxAddr.
|
||||
* Description : Gets address of the tx/rx buffer.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : address of the buffer.
|
||||
*******************************************************************************/
|
||||
#define _GetEPTxAddr(bEpNum) ((uint16_t)*_pEPTxAddr(bEpNum))
|
||||
#define _GetEPRxAddr(bEpNum) ((uint16_t)*_pEPRxAddr(bEpNum))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPCountRxReg.
|
||||
* Description : Sets counter of rx buffer with no. of blocks.
|
||||
* Input : pdwReg: pointer to counter.
|
||||
* wCount: Counter.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _BlocksOf32(dwReg,wCount,wNBlocks) {\
|
||||
wNBlocks = wCount >> 5;\
|
||||
if((wCount & 0x1f) == 0)\
|
||||
wNBlocks--;\
|
||||
*pdwReg = (uint32_t)((wNBlocks << 10) | 0x8000);\
|
||||
}/* _BlocksOf32 */
|
||||
|
||||
#define _BlocksOf2(dwReg,wCount,wNBlocks) {\
|
||||
wNBlocks = wCount >> 1;\
|
||||
if((wCount & 0x1) != 0)\
|
||||
wNBlocks++;\
|
||||
*pdwReg = (uint32_t)(wNBlocks << 10);\
|
||||
}/* _BlocksOf2 */
|
||||
|
||||
#define _SetEPCountRxReg(dwReg,wCount) {\
|
||||
uint16_t wNBlocks;\
|
||||
if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\
|
||||
else {_BlocksOf2(dwReg,wCount,wNBlocks);}\
|
||||
}/* _SetEPCountRxReg */
|
||||
|
||||
|
||||
|
||||
#define _SetEPRxDblBuf0Count(bEpNum,wCount) {\
|
||||
uint32_t *pdwReg = _pEPTxCount(bEpNum); \
|
||||
_SetEPCountRxReg(pdwReg, wCount);\
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPTxCount / SetEPRxCount.
|
||||
* Description : sets counter for the tx/rx buffer.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* wCount: Counter value.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPTxCount(bEpNum,wCount) (*_pEPTxCount(bEpNum) = wCount)
|
||||
#define _SetEPRxCount(bEpNum,wCount) {\
|
||||
uint32_t *pdwReg = _pEPRxCount(bEpNum); \
|
||||
_SetEPCountRxReg(pdwReg, wCount);\
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetEPTxCount / GetEPRxCount.
|
||||
* Description : gets counter of the tx buffer.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* Output : None.
|
||||
* Return : Counter value.
|
||||
*******************************************************************************/
|
||||
#define _GetEPTxCount(bEpNum)((uint16_t)(*_pEPTxCount(bEpNum)) & 0x3ff)
|
||||
#define _GetEPRxCount(bEpNum)((uint16_t)(*_pEPRxCount(bEpNum)) & 0x3ff)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPDblBuf0Addr / SetEPDblBuf1Addr.
|
||||
* Description : Sets buffer 0/1 address in a double buffer endpoint.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* : wBuf0Addr: buffer 0 address.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPDblBuf0Addr(bEpNum,wBuf0Addr) {_SetEPTxAddr(bEpNum, wBuf0Addr);}
|
||||
#define _SetEPDblBuf1Addr(bEpNum,wBuf1Addr) {_SetEPRxAddr(bEpNum, wBuf1Addr);}
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPDblBuffAddr.
|
||||
* Description : Sets addresses in a double buffer endpoint.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* : wBuf0Addr: buffer 0 address.
|
||||
* : wBuf1Addr = buffer 1 address.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPDblBuffAddr(bEpNum,wBuf0Addr,wBuf1Addr) { \
|
||||
_SetEPDblBuf0Addr(bEpNum, wBuf0Addr);\
|
||||
_SetEPDblBuf1Addr(bEpNum, wBuf1Addr);\
|
||||
} /* _SetEPDblBuffAddr */
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetEPDblBuf0Addr / GetEPDblBuf1Addr.
|
||||
* Description : Gets buffer 0/1 address of a double buffer endpoint.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _GetEPDblBuf0Addr(bEpNum) (_GetEPTxAddr(bEpNum))
|
||||
#define _GetEPDblBuf1Addr(bEpNum) (_GetEPRxAddr(bEpNum))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPDblBuffCount / SetEPDblBuf0Count / SetEPDblBuf1Count.
|
||||
* Description : Gets buffer 0/1 address of a double buffer endpoint.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* : bDir: endpoint dir EP_DBUF_OUT = OUT
|
||||
* EP_DBUF_IN = IN
|
||||
* : wCount: Counter value
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPDblBuf0Count(bEpNum, bDir, wCount) { \
|
||||
if(bDir == EP_DBUF_OUT)\
|
||||
/* OUT endpoint */ \
|
||||
{_SetEPRxDblBuf0Count(bEpNum,wCount);} \
|
||||
else if(bDir == EP_DBUF_IN)\
|
||||
/* IN endpoint */ \
|
||||
*_pEPTxCount(bEpNum) = (uint32_t)wCount; \
|
||||
} /* SetEPDblBuf0Count*/
|
||||
|
||||
#define _SetEPDblBuf1Count(bEpNum, bDir, wCount) { \
|
||||
if(bDir == EP_DBUF_OUT)\
|
||||
/* OUT endpoint */ \
|
||||
{_SetEPRxCount(bEpNum,wCount);}\
|
||||
else if(bDir == EP_DBUF_IN)\
|
||||
/* IN endpoint */\
|
||||
*_pEPRxCount(bEpNum) = (uint32_t)wCount; \
|
||||
} /* SetEPDblBuf1Count */
|
||||
|
||||
#define _SetEPDblBuffCount(bEpNum, bDir, wCount) {\
|
||||
_SetEPDblBuf0Count(bEpNum, bDir, wCount); \
|
||||
_SetEPDblBuf1Count(bEpNum, bDir, wCount); \
|
||||
} /* _SetEPDblBuffCount */
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetEPDblBuf0Count / GetEPDblBuf1Count.
|
||||
* Description : Gets buffer 0/1 rx/tx counter for double buffering.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _GetEPDblBuf0Count(bEpNum) (_GetEPTxCount(bEpNum))
|
||||
#define _GetEPDblBuf1Count(bEpNum) (_GetEPRxCount(bEpNum))
|
||||
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern __IO uint16_t wIstr; /* ISTR register last read value */
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void SetCNTR(uint16_t /*wRegValue*/);
|
||||
void SetISTR(uint16_t /*wRegValue*/);
|
||||
void SetDADDR(uint16_t /*wRegValue*/);
|
||||
void SetBTABLE(uint16_t /*wRegValue*/);
|
||||
void SetBTABLE(uint16_t /*wRegValue*/);
|
||||
uint16_t GetCNTR(void);
|
||||
uint16_t GetISTR(void);
|
||||
uint16_t GetFNR(void);
|
||||
uint16_t GetDADDR(void);
|
||||
uint16_t GetBTABLE(void);
|
||||
void SetENDPOINT(uint8_t /*bEpNum*/, uint16_t /*wRegValue*/);
|
||||
uint16_t GetENDPOINT(uint8_t /*bEpNum*/);
|
||||
void SetEPType(uint8_t /*bEpNum*/, uint16_t /*wType*/);
|
||||
uint16_t GetEPType(uint8_t /*bEpNum*/);
|
||||
void SetEPTxStatus(uint8_t /*bEpNum*/, uint16_t /*wState*/);
|
||||
void SetEPRxStatus(uint8_t /*bEpNum*/, uint16_t /*wState*/);
|
||||
void SetDouBleBuffEPStall(uint8_t /*bEpNum*/, uint8_t bDir);
|
||||
uint16_t GetEPTxStatus(uint8_t /*bEpNum*/);
|
||||
uint16_t GetEPRxStatus(uint8_t /*bEpNum*/);
|
||||
void SetEPTxValid(uint8_t /*bEpNum*/);
|
||||
void SetEPRxValid(uint8_t /*bEpNum*/);
|
||||
uint16_t GetTxStallStatus(uint8_t /*bEpNum*/);
|
||||
uint16_t GetRxStallStatus(uint8_t /*bEpNum*/);
|
||||
void SetEP_KIND(uint8_t /*bEpNum*/);
|
||||
void ClearEP_KIND(uint8_t /*bEpNum*/);
|
||||
void Set_Status_Out(uint8_t /*bEpNum*/);
|
||||
void Clear_Status_Out(uint8_t /*bEpNum*/);
|
||||
void SetEPDoubleBuff(uint8_t /*bEpNum*/);
|
||||
void ClearEPDoubleBuff(uint8_t /*bEpNum*/);
|
||||
void ClearEP_CTR_RX(uint8_t /*bEpNum*/);
|
||||
void ClearEP_CTR_TX(uint8_t /*bEpNum*/);
|
||||
void ToggleDTOG_RX(uint8_t /*bEpNum*/);
|
||||
void ToggleDTOG_TX(uint8_t /*bEpNum*/);
|
||||
void ClearDTOG_RX(uint8_t /*bEpNum*/);
|
||||
void ClearDTOG_TX(uint8_t /*bEpNum*/);
|
||||
void SetEPAddress(uint8_t /*bEpNum*/, uint8_t /*bAddr*/);
|
||||
uint8_t GetEPAddress(uint8_t /*bEpNum*/);
|
||||
void SetEPTxAddr(uint8_t /*bEpNum*/, uint16_t /*wAddr*/);
|
||||
void SetEPRxAddr(uint8_t /*bEpNum*/, uint16_t /*wAddr*/);
|
||||
uint16_t GetEPTxAddr(uint8_t /*bEpNum*/);
|
||||
uint16_t GetEPRxAddr(uint8_t /*bEpNum*/);
|
||||
void SetEPCountRxReg(uint32_t * /*pdwReg*/, uint16_t /*wCount*/);
|
||||
void SetEPTxCount(uint8_t /*bEpNum*/, uint16_t /*wCount*/);
|
||||
void SetEPRxCount(uint8_t /*bEpNum*/, uint16_t /*wCount*/);
|
||||
uint16_t GetEPTxCount(uint8_t /*bEpNum*/);
|
||||
uint16_t GetEPRxCount(uint8_t /*bEpNum*/);
|
||||
void SetEPDblBuf0Addr(uint8_t /*bEpNum*/, uint16_t /*wBuf0Addr*/);
|
||||
void SetEPDblBuf1Addr(uint8_t /*bEpNum*/, uint16_t /*wBuf1Addr*/);
|
||||
void SetEPDblBuffAddr(uint8_t /*bEpNum*/, uint16_t /*wBuf0Addr*/, uint16_t /*wBuf1Addr*/);
|
||||
uint16_t GetEPDblBuf0Addr(uint8_t /*bEpNum*/);
|
||||
uint16_t GetEPDblBuf1Addr(uint8_t /*bEpNum*/);
|
||||
void SetEPDblBuffCount(uint8_t /*bEpNum*/, uint8_t /*bDir*/, uint16_t /*wCount*/);
|
||||
void SetEPDblBuf0Count(uint8_t /*bEpNum*/, uint8_t /*bDir*/, uint16_t /*wCount*/);
|
||||
void SetEPDblBuf1Count(uint8_t /*bEpNum*/, uint8_t /*bDir*/, uint16_t /*wCount*/);
|
||||
uint16_t GetEPDblBuf0Count(uint8_t /*bEpNum*/);
|
||||
uint16_t GetEPDblBuf1Count(uint8_t /*bEpNum*/);
|
||||
EP_DBUF_DIR GetEPDblBufDir(uint8_t /*bEpNum*/);
|
||||
void FreeUserBuffer(uint8_t bEpNum/*bEpNum*/, uint8_t bDir);
|
||||
uint16_t ToWord(uint8_t, uint8_t);
|
||||
uint16_t ByteSwap(uint16_t);
|
||||
|
||||
#endif /* __USB_REGS_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -0,0 +1,47 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_sil.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief Simplified Interface Layer function prototypes.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_SIL_H
|
||||
#define __USB_SIL_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
uint32_t USB_SIL_Init(void);
|
||||
uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize);
|
||||
uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer);
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
|
||||
#endif /* __USB_SIL_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -0,0 +1,54 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_type.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief Type definitions used by the USB Library
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_TYPE_H
|
||||
#define __USB_TYPE_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_conf.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FALSE = 0, TRUE = !FALSE
|
||||
}
|
||||
bool;
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
/* External variables --------------------------------------------------------*/
|
||||
|
||||
#endif /* __USB_TYPE_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
1033
FW/Core/001-base_rt/USB/air32_USB-FS-Device_Driver/src/usb_core.c
Normal file
1033
FW/Core/001-base_rt/USB/air32_USB-FS-Device_Driver/src/usb_core.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,76 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_init.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief Initialization routines & global variables
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_lib.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* The number of current endpoint, it will be used to specify an endpoint */
|
||||
uint8_t EPindex;
|
||||
/* The number of current device, it is an index to the Device_Table */
|
||||
/* uint8_t Device_no; */
|
||||
/* Points to the DEVICE_INFO structure of current device */
|
||||
/* The purpose of this register is to speed up the execution */
|
||||
DEVICE_INFO *pInformation;
|
||||
/* Points to the DEVICE_PROP structure of current device */
|
||||
/* The purpose of this register is to speed up the execution */
|
||||
DEVICE_PROP *pProperty;
|
||||
/* Temporary save the state of Rx & Tx status. */
|
||||
/* Whenever the Rx or Tx state is changed, its value is saved */
|
||||
/* in this variable first and will be set to the EPRB or EPRA */
|
||||
/* at the end of interrupt process */
|
||||
uint16_t SaveState ;
|
||||
uint16_t wInterrupt_Mask;
|
||||
DEVICE_INFO Device_Info;
|
||||
USER_STANDARD_REQUESTS *pUser_Standard_Requests;
|
||||
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USB_Init
|
||||
* Description : USB system initialization
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void USB_Init(void)
|
||||
{
|
||||
pInformation = &Device_Info;
|
||||
pInformation->ControlState = 2;
|
||||
pProperty = &Device_Property;
|
||||
pUser_Standard_Requests = &User_Standard_Requests;
|
||||
/* Initialize devices one by one */
|
||||
pProperty->Init();
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
195
FW/Core/001-base_rt/USB/air32_USB-FS-Device_Driver/src/usb_int.c
Normal file
195
FW/Core/001-base_rt/USB/air32_USB-FS-Device_Driver/src/usb_int.c
Normal file
@ -0,0 +1,195 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_int.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief Endpoint CTR (Low and High) interrupt's service routines
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_lib.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
__IO uint16_t SaveRState;
|
||||
__IO uint16_t SaveTState;
|
||||
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
extern void (*pEpInt_IN[7])(void); /* Handles IN interrupts */
|
||||
extern void (*pEpInt_OUT[7])(void); /* Handles OUT interrupts */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CTR_LP.
|
||||
* Description : Low priority Endpoint Correct Transfer interrupt's service
|
||||
* routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void CTR_LP(void)
|
||||
{
|
||||
__IO uint16_t wEPVal = 0;
|
||||
/* stay in loop while pending interrupts */
|
||||
while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
|
||||
{
|
||||
/* extract highest priority endpoint number */
|
||||
EPindex = (uint8_t)(wIstr & ISTR_EP_ID);
|
||||
if (EPindex == 0)
|
||||
{
|
||||
/* Decode and service control endpoint interrupt */
|
||||
/* calling related service routine */
|
||||
/* (Setup0_Process, In0_Process, Out0_Process) */
|
||||
|
||||
/* save RX & TX status */
|
||||
/* and set both to NAK */
|
||||
|
||||
SaveRState = _GetENDPOINT(ENDP0);
|
||||
SaveTState = SaveRState & EPTX_STAT;
|
||||
SaveRState &= EPRX_STAT;
|
||||
|
||||
_SetEPRxTxStatus(ENDP0,EP_RX_NAK,EP_TX_NAK);
|
||||
|
||||
/* DIR bit = origin of the interrupt */
|
||||
|
||||
if ((wIstr & ISTR_DIR) == 0)
|
||||
{
|
||||
/* DIR = 0 */
|
||||
|
||||
/* DIR = 0 => IN int */
|
||||
/* DIR = 0 implies that (EP_CTR_TX = 1) always */
|
||||
|
||||
_ClearEP_CTR_TX(ENDP0);
|
||||
In0_Process();
|
||||
|
||||
/* before terminate set Tx & Rx status */
|
||||
|
||||
_SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* DIR = 1 */
|
||||
|
||||
/* DIR = 1 & CTR_RX => SETUP or OUT int */
|
||||
/* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
|
||||
|
||||
wEPVal = _GetENDPOINT(ENDP0);
|
||||
|
||||
if ((wEPVal &EP_SETUP) != 0)
|
||||
{
|
||||
_ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
|
||||
Setup0_Process();
|
||||
/* before terminate set Tx & Rx status */
|
||||
|
||||
_SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
|
||||
return;
|
||||
}
|
||||
|
||||
else if ((wEPVal & EP_CTR_RX) != 0)
|
||||
{
|
||||
_ClearEP_CTR_RX(ENDP0);
|
||||
Out0_Process();
|
||||
/* before terminate set Tx & Rx status */
|
||||
|
||||
_SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}/* if(EPindex == 0) */
|
||||
else
|
||||
{
|
||||
/* Decode and service non control endpoints interrupt */
|
||||
|
||||
/* process related endpoint register */
|
||||
wEPVal = _GetENDPOINT(EPindex);
|
||||
if ((wEPVal & EP_CTR_RX) != 0)
|
||||
{
|
||||
/* clear int flag */
|
||||
_ClearEP_CTR_RX(EPindex);
|
||||
|
||||
/* call OUT service function */
|
||||
(*pEpInt_OUT[EPindex-1])();
|
||||
|
||||
} /* if((wEPVal & EP_CTR_RX) */
|
||||
|
||||
if ((wEPVal & EP_CTR_TX) != 0)
|
||||
{
|
||||
/* clear int flag */
|
||||
_ClearEP_CTR_TX(EPindex);
|
||||
|
||||
/* call IN service function */
|
||||
(*pEpInt_IN[EPindex-1])();
|
||||
} /* if((wEPVal & EP_CTR_TX) != 0) */
|
||||
|
||||
}/* if(EPindex == 0) else */
|
||||
|
||||
}/* while(...) */
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CTR_HP.
|
||||
* Description : High Priority Endpoint Correct Transfer interrupt's service
|
||||
* routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void CTR_HP(void)
|
||||
{
|
||||
uint32_t wEPVal = 0;
|
||||
|
||||
while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_CTR); /* clear CTR flag */
|
||||
/* extract highest priority endpoint number */
|
||||
EPindex = (uint8_t)(wIstr & ISTR_EP_ID);
|
||||
/* process related endpoint register */
|
||||
wEPVal = _GetENDPOINT(EPindex);
|
||||
if ((wEPVal & EP_CTR_RX) != 0)
|
||||
{
|
||||
/* clear int flag */
|
||||
_ClearEP_CTR_RX(EPindex);
|
||||
|
||||
/* call OUT service function */
|
||||
(*pEpInt_OUT[EPindex-1])();
|
||||
|
||||
} /* if((wEPVal & EP_CTR_RX) */
|
||||
else if ((wEPVal & EP_CTR_TX) != 0)
|
||||
{
|
||||
/* clear int flag */
|
||||
_ClearEP_CTR_TX(EPindex);
|
||||
|
||||
/* call IN service function */
|
||||
(*pEpInt_IN[EPindex-1])();
|
||||
|
||||
|
||||
} /* if((wEPVal & EP_CTR_TX) != 0) */
|
||||
|
||||
}/* while(...) */
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -0,0 +1,87 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_mem.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief Utility functions for memory transfers to/from PMA
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_lib.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* 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 = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */
|
||||
uint32_t i, temp1, temp2;
|
||||
uint16_t *pdwVal;
|
||||
pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr);
|
||||
for (i = n; i != 0; i--)
|
||||
{
|
||||
temp1 = (uint16_t) * pbUsrBuf;
|
||||
pbUsrBuf++;
|
||||
temp2 = temp1 | (uint16_t) * pbUsrBuf << 8;
|
||||
*pdwVal++ = temp2;
|
||||
pdwVal++;
|
||||
pbUsrBuf++;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : PMAToUserBufferCopy
|
||||
* 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 PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
|
||||
{
|
||||
uint32_t n = (wNBytes + 1) >> 1;/* /2*/
|
||||
uint32_t i;
|
||||
uint32_t *pdwVal;
|
||||
pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr);
|
||||
for (i = n; i != 0; i--)
|
||||
{
|
||||
*(uint16_t*)pbUsrBuf++ = *pdwVal++;
|
||||
pbUsrBuf++;
|
||||
}
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -0,0 +1,760 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_regs.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief Interface functions to USB cell registers
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_lib.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SetCNTR.
|
||||
* Description : Set the CNTR register value.
|
||||
* Input : wRegValue: new register value.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetCNTR(uint16_t wRegValue)
|
||||
{
|
||||
_SetCNTR(wRegValue);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GetCNTR.
|
||||
* Description : returns the CNTR register value.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : CNTR register Value.
|
||||
*******************************************************************************/
|
||||
uint16_t GetCNTR(void)
|
||||
{
|
||||
return(_GetCNTR());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SetISTR.
|
||||
* Description : Set the ISTR register value.
|
||||
* Input : wRegValue: new register value.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetISTR(uint16_t wRegValue)
|
||||
{
|
||||
_SetISTR(wRegValue);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GetISTR
|
||||
* Description : Returns the ISTR register value.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : ISTR register Value
|
||||
*******************************************************************************/
|
||||
uint16_t GetISTR(void)
|
||||
{
|
||||
return(_GetISTR());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GetFNR
|
||||
* Description : Returns the FNR register value.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : FNR register Value
|
||||
*******************************************************************************/
|
||||
uint16_t GetFNR(void)
|
||||
{
|
||||
return(_GetFNR());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SetDADDR
|
||||
* Description : Set the DADDR register value.
|
||||
* Input : wRegValue: new register value.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetDADDR(uint16_t wRegValue)
|
||||
{
|
||||
_SetDADDR(wRegValue);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GetDADDR
|
||||
* Description : Returns the DADDR register value.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : DADDR register Value
|
||||
*******************************************************************************/
|
||||
uint16_t GetDADDR(void)
|
||||
{
|
||||
return(_GetDADDR());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SetBTABLE
|
||||
* Description : Set the BTABLE.
|
||||
* Input : wRegValue: New register value.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetBTABLE(uint16_t wRegValue)
|
||||
{
|
||||
_SetBTABLE(wRegValue);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GetBTABLE.
|
||||
* Description : Returns the BTABLE register value.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : BTABLE address.
|
||||
*******************************************************************************/
|
||||
uint16_t GetBTABLE(void)
|
||||
{
|
||||
return(_GetBTABLE());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SetENDPOINT
|
||||
* Description : Set the Endpoint register value.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wRegValue.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetENDPOINT(uint8_t bEpNum, uint16_t wRegValue)
|
||||
{
|
||||
_SetENDPOINT(bEpNum, wRegValue);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GetENDPOINT
|
||||
* Description : Return the Endpoint register value.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Endpoint register value.
|
||||
*******************************************************************************/
|
||||
uint16_t GetENDPOINT(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetENDPOINT(bEpNum));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPType
|
||||
* Description : sets the type in the endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wType: type definition.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPType(uint8_t bEpNum, uint16_t wType)
|
||||
{
|
||||
_SetEPType(bEpNum, wType);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GetEPType
|
||||
* Description : Returns the endpoint type.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Endpoint Type
|
||||
*******************************************************************************/
|
||||
uint16_t GetEPType(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPType(bEpNum));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPTxStatus
|
||||
* Description : Set the status of Tx endpoint.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wState: new state.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPTxStatus(uint8_t bEpNum, uint16_t wState)
|
||||
{
|
||||
_SetEPTxStatus(bEpNum, wState);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPRxStatus
|
||||
* Description : Set the status of Rx endpoint.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wState: new state.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPRxStatus(uint8_t bEpNum, uint16_t wState)
|
||||
{
|
||||
_SetEPRxStatus(bEpNum, wState);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SetDouBleBuffEPStall
|
||||
* Description : sets the status for Double Buffer Endpoint to STALL
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* bDir: Endpoint direction.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetDouBleBuffEPStall(uint8_t bEpNum, uint8_t bDir)
|
||||
{
|
||||
uint16_t Endpoint_DTOG_Status;
|
||||
Endpoint_DTOG_Status = GetENDPOINT(bEpNum);
|
||||
if (bDir == EP_DBUF_OUT)
|
||||
{ /* OUT double buffered endpoint */
|
||||
_SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPRX_DTOG1);
|
||||
}
|
||||
else if (bDir == EP_DBUF_IN)
|
||||
{ /* IN double buffered endpoint */
|
||||
_SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPTX_DTOG1);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GetEPTxStatus
|
||||
* Description : Returns the endpoint Tx status.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Endpoint TX Status
|
||||
*******************************************************************************/
|
||||
uint16_t GetEPTxStatus(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPTxStatus(bEpNum));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : GetEPRxStatus
|
||||
* Description : Returns the endpoint Rx status.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Endpoint RX Status
|
||||
*******************************************************************************/
|
||||
uint16_t GetEPRxStatus(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPRxStatus(bEpNum));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPTxValid
|
||||
* Description : Valid the endpoint Tx Status.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPTxValid(uint8_t bEpNum)
|
||||
{
|
||||
_SetEPTxStatus(bEpNum, EP_TX_VALID);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPRxValid
|
||||
* Description : Valid the endpoint Rx Status.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPRxValid(uint8_t bEpNum)
|
||||
{
|
||||
_SetEPRxStatus(bEpNum, EP_RX_VALID);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEP_KIND
|
||||
* Description : Clear the EP_KIND bit.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEP_KIND(uint8_t bEpNum)
|
||||
{
|
||||
_SetEP_KIND(bEpNum);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : ClearEP_KIND
|
||||
* Description : set the EP_KIND bit.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void ClearEP_KIND(uint8_t bEpNum)
|
||||
{
|
||||
_ClearEP_KIND(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : Clear_Status_Out
|
||||
* Description : Clear the Status Out of the related Endpoint
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Clear_Status_Out(uint8_t bEpNum)
|
||||
{
|
||||
_ClearEP_KIND(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : Set_Status_Out
|
||||
* Description : Set the Status Out of the related Endpoint
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Set_Status_Out(uint8_t bEpNum)
|
||||
{
|
||||
_SetEP_KIND(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPDoubleBuff
|
||||
* Description : Enable the double buffer feature for the endpoint.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPDoubleBuff(uint8_t bEpNum)
|
||||
{
|
||||
_SetEP_KIND(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : ClearEPDoubleBuff
|
||||
* Description : Disable the double buffer feature for the endpoint.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void ClearEPDoubleBuff(uint8_t bEpNum)
|
||||
{
|
||||
_ClearEP_KIND(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : GetTxStallStatus
|
||||
* Description : Returns the Stall status of the Tx endpoint.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Tx Stall status.
|
||||
*******************************************************************************/
|
||||
uint16_t GetTxStallStatus(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetTxStallStatus(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : GetRxStallStatus
|
||||
* Description : Returns the Stall status of the Rx endpoint.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Rx Stall status.
|
||||
*******************************************************************************/
|
||||
uint16_t GetRxStallStatus(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetRxStallStatus(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : ClearEP_CTR_RX
|
||||
* Description : Clear the CTR_RX bit.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void ClearEP_CTR_RX(uint8_t bEpNum)
|
||||
{
|
||||
_ClearEP_CTR_RX(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : ClearEP_CTR_TX
|
||||
* Description : Clear the CTR_TX bit.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void ClearEP_CTR_TX(uint8_t bEpNum)
|
||||
{
|
||||
_ClearEP_CTR_TX(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : ToggleDTOG_RX
|
||||
* Description : Toggle the DTOG_RX bit.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void ToggleDTOG_RX(uint8_t bEpNum)
|
||||
{
|
||||
_ToggleDTOG_RX(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : ToggleDTOG_TX
|
||||
* Description : Toggle the DTOG_TX bit.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void ToggleDTOG_TX(uint8_t bEpNum)
|
||||
{
|
||||
_ToggleDTOG_TX(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : ClearDTOG_RX.
|
||||
* Description : Clear the DTOG_RX bit.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void ClearDTOG_RX(uint8_t bEpNum)
|
||||
{
|
||||
_ClearDTOG_RX(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : ClearDTOG_TX.
|
||||
* Description : Clear the DTOG_TX bit.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void ClearDTOG_TX(uint8_t bEpNum)
|
||||
{
|
||||
_ClearDTOG_TX(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPAddress
|
||||
* Description : Set the endpoint address.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* bAddr: New endpoint address.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPAddress(uint8_t bEpNum, uint8_t bAddr)
|
||||
{
|
||||
_SetEPAddress(bEpNum, bAddr);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : GetEPAddress
|
||||
* Description : Get the endpoint address.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Endpoint address.
|
||||
*******************************************************************************/
|
||||
uint8_t GetEPAddress(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPAddress(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPTxAddr
|
||||
* Description : Set the endpoint Tx buffer address.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wAddr: new address.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPTxAddr(uint8_t bEpNum, uint16_t wAddr)
|
||||
{
|
||||
_SetEPTxAddr(bEpNum, wAddr);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPRxAddr
|
||||
* Description : Set the endpoint Rx buffer address.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wAddr: new address.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPRxAddr(uint8_t bEpNum, uint16_t wAddr)
|
||||
{
|
||||
_SetEPRxAddr(bEpNum, wAddr);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : GetEPTxAddr
|
||||
* Description : Returns the endpoint Tx buffer address.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Rx buffer address.
|
||||
*******************************************************************************/
|
||||
uint16_t GetEPTxAddr(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPTxAddr(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : GetEPRxAddr.
|
||||
* Description : Returns the endpoint Rx buffer address.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Rx buffer address.
|
||||
*******************************************************************************/
|
||||
uint16_t GetEPRxAddr(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPRxAddr(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPTxCount.
|
||||
* Description : Set the Tx count.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wCount: new count value.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPTxCount(uint8_t bEpNum, uint16_t wCount)
|
||||
{
|
||||
_SetEPTxCount(bEpNum, wCount);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPCountRxReg.
|
||||
* Description : Set the Count Rx Register value.
|
||||
* Input : *pdwReg: point to the register.
|
||||
* wCount: the new register value.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPCountRxReg(uint32_t *pdwReg, uint16_t wCount)
|
||||
{
|
||||
_SetEPCountRxReg(dwReg, wCount);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPRxCount
|
||||
* Description : Set the Rx count.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wCount: the new count value.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPRxCount(uint8_t bEpNum, uint16_t wCount)
|
||||
{
|
||||
_SetEPRxCount(bEpNum, wCount);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : GetEPTxCount
|
||||
* Description : Get the Tx count.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None
|
||||
* Return : Tx count value.
|
||||
*******************************************************************************/
|
||||
uint16_t GetEPTxCount(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPTxCount(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : GetEPRxCount
|
||||
* Description : Get the Rx count.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Rx count value.
|
||||
*******************************************************************************/
|
||||
uint16_t GetEPRxCount(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPRxCount(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPDblBuffAddr
|
||||
* Description : Set the addresses of the buffer 0 and 1.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wBuf0Addr: new address of buffer 0.
|
||||
* wBuf1Addr: new address of buffer 1.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPDblBuffAddr(uint8_t bEpNum, uint16_t wBuf0Addr, uint16_t wBuf1Addr)
|
||||
{
|
||||
_SetEPDblBuffAddr(bEpNum, wBuf0Addr, wBuf1Addr);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPDblBuf0Addr
|
||||
* Description : Set the Buffer 1 address.
|
||||
* Input : bEpNum: Endpoint Number
|
||||
* wBuf0Addr: new address.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPDblBuf0Addr(uint8_t bEpNum, uint16_t wBuf0Addr)
|
||||
{
|
||||
_SetEPDblBuf0Addr(bEpNum, wBuf0Addr);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPDblBuf1Addr
|
||||
* Description : Set the Buffer 1 address.
|
||||
* Input : bEpNum: Endpoint Number
|
||||
* wBuf1Addr: new address.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPDblBuf1Addr(uint8_t bEpNum, uint16_t wBuf1Addr)
|
||||
{
|
||||
_SetEPDblBuf1Addr(bEpNum, wBuf1Addr);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : GetEPDblBuf0Addr
|
||||
* Description : Returns the address of the Buffer 0.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
uint16_t GetEPDblBuf0Addr(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPDblBuf0Addr(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : GetEPDblBuf1Addr
|
||||
* Description : Returns the address of the Buffer 1.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Address of the Buffer 1.
|
||||
*******************************************************************************/
|
||||
uint16_t GetEPDblBuf1Addr(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPDblBuf1Addr(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPDblBuffCount
|
||||
* Description : Set the number of bytes for a double Buffer
|
||||
* endpoint.
|
||||
* Input : bEpNum,bDir, wCount
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPDblBuffCount(uint8_t bEpNum, uint8_t bDir, uint16_t wCount)
|
||||
{
|
||||
_SetEPDblBuffCount(bEpNum, bDir, wCount);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPDblBuf0Count
|
||||
* Description : Set the number of bytes in the buffer 0 of a double Buffer
|
||||
* endpoint.
|
||||
* Input : bEpNum, bDir, wCount
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPDblBuf0Count(uint8_t bEpNum, uint8_t bDir, uint16_t wCount)
|
||||
{
|
||||
_SetEPDblBuf0Count(bEpNum, bDir, wCount);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SetEPDblBuf1Count
|
||||
* Description : Set the number of bytes in the buffer 0 of a double Buffer
|
||||
* endpoint.
|
||||
* Input : bEpNum, bDir, wCount
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SetEPDblBuf1Count(uint8_t bEpNum, uint8_t bDir, uint16_t wCount)
|
||||
{
|
||||
_SetEPDblBuf1Count(bEpNum, bDir, wCount);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : GetEPDblBuf0Count
|
||||
* Description : Returns the number of byte received in the buffer 0 of a double
|
||||
* Buffer endpoint.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Endpoint Buffer 0 count
|
||||
*******************************************************************************/
|
||||
uint16_t GetEPDblBuf0Count(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPDblBuf0Count(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : GetEPDblBuf1Count
|
||||
* Description : Returns the number of data received in the buffer 1 of a double
|
||||
* Buffer endpoint.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : Endpoint Buffer 1 count.
|
||||
*******************************************************************************/
|
||||
uint16_t GetEPDblBuf1Count(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPDblBuf1Count(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : GetEPDblBufDir
|
||||
* Description : gets direction of the double buffered endpoint
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Output : None.
|
||||
* Return : EP_DBUF_OUT, EP_DBUF_IN,
|
||||
* EP_DBUF_ERR if the endpoint counter not yet programmed.
|
||||
*******************************************************************************/
|
||||
EP_DBUF_DIR GetEPDblBufDir(uint8_t bEpNum)
|
||||
{
|
||||
if ((uint16_t)(*_pEPRxCount(bEpNum) & 0xFC00) != 0)
|
||||
return(EP_DBUF_OUT);
|
||||
else if (((uint16_t)(*_pEPTxCount(bEpNum)) & 0x03FF) != 0)
|
||||
return(EP_DBUF_IN);
|
||||
else
|
||||
return(EP_DBUF_ERR);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : FreeUserBuffer
|
||||
* Description : free buffer used from the application realizing it to the line
|
||||
toggles bit SW_BUF in the double buffered endpoint register
|
||||
* Input : bEpNum, bDir
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void FreeUserBuffer(uint8_t bEpNum, uint8_t bDir)
|
||||
{
|
||||
if (bDir == EP_DBUF_OUT)
|
||||
{ /* OUT double buffered endpoint */
|
||||
_ToggleDTOG_TX(bEpNum);
|
||||
}
|
||||
else if (bDir == EP_DBUF_IN)
|
||||
{ /* IN double buffered endpoint */
|
||||
_ToggleDTOG_RX(bEpNum);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : ToWord
|
||||
* Description : merge two byte in a word.
|
||||
* Input : bh: byte high, bl: bytes low.
|
||||
* Output : None.
|
||||
* Return : resulted word.
|
||||
*******************************************************************************/
|
||||
uint16_t ToWord(uint8_t bh, uint8_t bl)
|
||||
{
|
||||
uint16_t wRet;
|
||||
wRet = (uint16_t)bl | ((uint16_t)bh << 8);
|
||||
return(wRet);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : ByteSwap
|
||||
* Description : Swap two byte in a word.
|
||||
* Input : wSwW: word to Swap.
|
||||
* Output : None.
|
||||
* Return : resulted word.
|
||||
*******************************************************************************/
|
||||
uint16_t ByteSwap(uint16_t wSwW)
|
||||
{
|
||||
uint8_t bTemp;
|
||||
uint16_t wRet;
|
||||
bTemp = (uint8_t)(wSwW & 0xff);
|
||||
wRet = (wSwW >> 8) | ((uint16_t)bTemp << 8);
|
||||
return(wRet);
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
103
FW/Core/001-base_rt/USB/air32_USB-FS-Device_Driver/src/usb_sil.c
Normal file
103
FW/Core/001-base_rt/USB/air32_USB-FS-Device_Driver/src/usb_sil.c
Normal file
@ -0,0 +1,103 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_sil.c
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.0
|
||||
* @date 28-August-2012
|
||||
* @brief Simplified Interface Layer for Global Initialization and Endpoint
|
||||
* Rea/Write operations.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_lib.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USB_SIL_Init
|
||||
* Description : Initialize the USB Device IP and the Endpoint 0.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : Status.
|
||||
*******************************************************************************/
|
||||
uint32_t USB_SIL_Init(void)
|
||||
{
|
||||
/* USB interrupts initialization */
|
||||
/* clear pending interrupts */
|
||||
_SetISTR(0);
|
||||
wInterrupt_Mask = IMR_MSK;
|
||||
/* set interrupts mask */
|
||||
_SetCNTR(wInterrupt_Mask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USB_SIL_Write
|
||||
* Description : Write a buffer of data to a selected endpoint.
|
||||
* Input : - bEpAddr: The address of the non control endpoint.
|
||||
* - pBufferPointer: The pointer to the buffer of data to be written
|
||||
* to the endpoint.
|
||||
* - wBufferSize: Number of data to be written (in bytes).
|
||||
* Output : None.
|
||||
* Return : Status.
|
||||
*******************************************************************************/
|
||||
uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize)
|
||||
{
|
||||
/* Use the memory interface function to write to the selected endpoint */
|
||||
UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize);
|
||||
|
||||
/* Update the data length in the control register */
|
||||
SetEPTxCount((bEpAddr & 0x7F), wBufferSize);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USB_SIL_Read
|
||||
* Description : Write a buffer of data to a selected endpoint.
|
||||
* Input : - bEpAddr: The address of the non control endpoint.
|
||||
* - pBufferPointer: The pointer to which will be saved the
|
||||
* received data buffer.
|
||||
* Output : None.
|
||||
* Return : Number of received data (in Bytes).
|
||||
*******************************************************************************/
|
||||
uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer)
|
||||
{
|
||||
uint32_t DataLength = 0;
|
||||
|
||||
/* Get the number of received data on the selected Endpoint */
|
||||
DataLength = GetEPRxCount(bEpAddr & 0x7F);
|
||||
|
||||
/* Use the memory interface function to write to the selected endpoint */
|
||||
PMAToUserBufferCopy(pBufferPointer, GetEPRxAddr(bEpAddr & 0x7F), DataLength);
|
||||
|
||||
/* Return the number of received data */
|
||||
return DataLength;
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
36
FW/Core/001-base_rt/USB/system.c
Normal file
36
FW/Core/001-base_rt/USB/system.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "usb_lib.h"
|
||||
#include "hw_config.h"
|
||||
#include "usb_pwr.h"
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <board.h>
|
||||
|
||||
//USB唤醒中断服务函数
|
||||
void USBWakeUp_IRQHandler(void)
|
||||
{
|
||||
EXTI_ClearITPendingBit(EXTI_Line18);//清除USB唤醒中断挂起位
|
||||
}
|
||||
|
||||
//USB中断处理函数
|
||||
void USB_LP_CAN1_RX0_IRQHandler(void)
|
||||
{
|
||||
rt_interrupt_enter();
|
||||
extern void USB_Istr();
|
||||
USB_Istr();
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
|
||||
static int usb_init()
|
||||
{
|
||||
Set_USBClock();
|
||||
USB_Interrupts_Config();
|
||||
USB_Init();
|
||||
DP_PUUP = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
INIT_ENV_EXPORT(usb_init);
|
||||
|
55
FW/Core/001-base_rt/USB/system.h
Normal file
55
FW/Core/001-base_rt/USB/system.h
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef _system_H
|
||||
#define _system_H
|
||||
|
||||
#include "air32f10x.h"
|
||||
|
||||
|
||||
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
|
||||
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
|
||||
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
|
||||
|
||||
#define GPIOA_ODR_Addr (GPIOA_BASE+12) //0x4001080C
|
||||
#define GPIOB_ODR_Addr (GPIOB_BASE+12) //0x40010C0C
|
||||
#define GPIOC_ODR_Addr (GPIOC_BASE+12) //0x4001100C
|
||||
#define GPIOD_ODR_Addr (GPIOD_BASE+12) //0x4001140C
|
||||
#define GPIOE_ODR_Addr (GPIOE_BASE+12) //0x4001180C
|
||||
#define GPIOF_ODR_Addr (GPIOF_BASE+12) //0x40011A0C
|
||||
#define GPIOG_ODR_Addr (GPIOG_BASE+12) //0x40011E0C
|
||||
|
||||
#define GPIOA_IDR_Addr (GPIOA_BASE+8) //0x40010808
|
||||
#define GPIOB_IDR_Addr (GPIOB_BASE+8) //0x40010C08
|
||||
#define GPIOC_IDR_Addr (GPIOC_BASE+8) //0x40011008
|
||||
#define GPIOD_IDR_Addr (GPIOD_BASE+8) //0x40011408
|
||||
#define GPIOE_IDR_Addr (GPIOE_BASE+8) //0x40011808
|
||||
#define GPIOF_IDR_Addr (GPIOF_BASE+8) //0x40011A08
|
||||
#define GPIOG_IDR_Addr (GPIOG_BASE+8) //0x40011E08
|
||||
|
||||
|
||||
#define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n)
|
||||
#define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n)
|
||||
|
||||
#define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n)
|
||||
#define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n)
|
||||
|
||||
#define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n)
|
||||
#define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n)
|
||||
|
||||
#define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n)
|
||||
#define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n)
|
||||
|
||||
#define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n)
|
||||
#define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n)
|
||||
|
||||
#define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n)
|
||||
#define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n)
|
||||
|
||||
#define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n)
|
||||
#define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n)
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <board.h>
|
||||
|
||||
#define printf(...)
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -44,6 +44,7 @@
|
||||
#define RT_USING_MEMPOOL
|
||||
#define RT_USING_SMALL_MEM
|
||||
#define RT_USING_SMALL_MEM_AS_HEAP
|
||||
#define RT_USING_HEAP_ISR
|
||||
#define RT_USING_HEAP
|
||||
#define RT_USING_DEVICE
|
||||
#define RT_USING_CONSOLE
|
||||
@ -163,6 +164,15 @@
|
||||
/* Wiced WiFi */
|
||||
|
||||
|
||||
/* CYW43012 WiFi */
|
||||
|
||||
|
||||
/* BL808 WiFi */
|
||||
|
||||
|
||||
/* CYW43439 WiFi */
|
||||
|
||||
|
||||
/* IoT Cloud */
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user