initial commit

This commit is contained in:
tkl
2016-07-23 07:59:54 +02:00
commit cb58a410f1
1378 changed files with 372066 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
include firmware/arch/stm32f4xx/driver/gpio/gpio.mk
include firmware/arch/stm32f4xx/driver/timer/timer.mk
include firmware/arch/stm32f4xx/driver/usb/usb.mk
include firmware/arch/stm32f4xx/driver/usb_vport/usb_vport.mk

View File

@@ -0,0 +1,3 @@
SUB_FOLDER += firmware/arch/stm32f4xx/driver/gpio
INCLUDES += firmware/arch/stm32f4xx/driver/gpio
DOC_SRC += firmware/arch/stm32f4xx/driver/gpio

View File

@@ -0,0 +1,260 @@
//! \file stm32f4_gpio.c
//! \author tkl
//! \date Mai 8, 2012
//! \brief Source file of the stm32f4 architecture dependent gpio driver.
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include "stm32f4xx.h"
#include "gpio.h"
#include "stm32f4_gpio.h"
//! \brief Contains data for a callback for an external interrupt.
typedef struct {
gpio_ext_it_cb_t callback; //!< The call back to be executed.
void *param; //!< Parameter for the callback
}exti_cb_list_t;
//! \brief Contains call back data for all 16 exti lines.
static struct {
exti_cb_list_t callback_list[16]; //!< Call back data list for the exti lines.
}gpio_obj;
static uint8_t gpio_bin2dec(uint16_t bin)
{
uint8_t ret = 0;
switch(bin) {
case 0x0001: ret = 0; break;
case 0x0002: ret = 1; break;
case 0x0004: ret = 2; break;
case 0x0008: ret = 3; break;
case 0x0010: ret = 4; break;
case 0x0020: ret = 5; break;
case 0x0040: ret = 6; break;
case 0x0080: ret = 7; break;
case 0x0100: ret = 8; break;
case 0x0200: ret = 9; break;
case 0x0400: ret = 10; break;
case 0x0800: ret = 11; break;
case 0x1000: ret = 12; break;
case 0x2000: ret = 13; break;
case 0x4000: ret = 14; break;
case 0x8000: ret = 15; break;
}
return ret;
}
static void gpio_init(const struct stm32f4_gpio *gpio)
{
uint8_t m_port = 0;
uint8_t m_pin = 0;
uint32_t clock = 0;
if(gpio == NULL)
return;
if(gpio->port == GPIOA) {
clock = RCC_AHB1Periph_GPIOA;
m_port = EXTI_PortSourceGPIOA;
}
else if(gpio->port == GPIOB) {
clock = RCC_AHB1Periph_GPIOB;
m_port = EXTI_PortSourceGPIOB;
}
else if(gpio->port == GPIOC) {
clock = RCC_AHB1Periph_GPIOC;
m_port = EXTI_PortSourceGPIOC;
}
else if(gpio->port == GPIOD) {
clock = RCC_AHB1Periph_GPIOD;
m_port = EXTI_PortSourceGPIOD;
}
else if(gpio->port == GPIOE) {
clock = RCC_AHB1Periph_GPIOE;
m_port = EXTI_PortSourceGPIOE;
}
else if(gpio->port == GPIOF) {
clock = RCC_AHB1Periph_GPIOF;
m_port = EXTI_PortSourceGPIOF;
}
else if(gpio->port == GPIOG) {
clock = RCC_AHB1Periph_GPIOG;
m_port = EXTI_PortSourceGPIOG;
}
else if(gpio->port == GPIOH) {
clock = RCC_AHB1Periph_GPIOH;
m_port = EXTI_PortSourceGPIOH;
}
else if(gpio->port == GPIOI) {
clock = RCC_AHB1Periph_GPIOI;
m_port = EXTI_PortSourceGPIOI;
}
RCC_AHB1PeriphClockCmd(clock, ENABLE);
m_pin = gpio_bin2dec(gpio->pin->GPIO_Pin);
SYSCFG_EXTILineConfig(m_port, m_pin);
}
int stm32f4_gpio_open(const void *gpio)
{
struct stm32f4_gpio *this;
uint8_t m_pin = 0;
if(gpio == NULL)
return -1;
this = (struct stm32f4_gpio *)gpio;
gpio_init(this);
m_pin = gpio_bin2dec(this->pin->GPIO_Pin);
GPIO_Init(this->port, (GPIO_InitTypeDef*)this->pin);
if(this->ext_it_cb != NULL) {
gpio_obj.callback_list[m_pin].callback = this->ext_it_cb;
gpio_obj.callback_list[m_pin].param = this->param;
}
if((this->exti != NULL) && (this->nvic != NULL)) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
EXTI_Init((EXTI_InitTypeDef*)this->exti);
NVIC_Init((NVIC_InitTypeDef*)this->nvic);
}
return 0;
}
int stm32f4_gpio_close(const void *gpio)
{
if(gpio == NULL)
return -1;
// TODO: deinit exti, nvic & gpio
return 0;
}
char stm32f4_gpio_read(const void *gpio)
{
struct stm32f4_gpio *this;
if(gpio == NULL)
return 0;
this = (struct stm32f4_gpio *)gpio;
return GPIO_ReadOutputDataBit(this->port, this->pin->GPIO_Pin);
}
void stm32f4_gpio_write(const void *gpio, char byte) {
struct stm32f4_gpio *this;
if(gpio == NULL)
return;
this = (struct stm32f4_gpio *)gpio;
GPIO_WriteBit(this->port, this->pin->GPIO_Pin, (BitAction)byte);
}
void stm32f4_gpio_toggle(const void *gpio)
{
struct stm32f4_gpio *this;
if(gpio == NULL)
return;
this = (struct stm32f4_gpio *)gpio;
BitAction act = Bit_SET;
if(GPIO_ReadOutputDataBit(this->port, this->pin->GPIO_Pin))
act = Bit_RESET;
GPIO_WriteBit(this->port, this->pin->GPIO_Pin, act);
}
int stm32f4_gpio_set_exti_callback(const void *gpio,
const void *callback, const void *param)
{
struct stm32f4_gpio *this;
uint8_t pin;
if((gpio == NULL) || (callback == NULL))
return -1;
this = (struct stm32f4_gpio *)gpio;
pin = gpio_bin2dec(this->exti->EXTI_Line);
gpio_obj.callback_list[pin].callback = (gpio_ext_it_cb_t)callback;
gpio_obj.callback_list[pin].param = (void*)param;
return 0;
}
//! \brief The ISR for the EXTI0_IRQn interrupt.
void EXTI0_IRQHandler(void)
{
if(gpio_obj.callback_list[0].callback != NULL) {
gpio_ext_it_cb_t cb = gpio_obj.callback_list[0].callback;
void *param = gpio_obj.callback_list[0].param;
cb(param);
}
EXTI_ClearITPendingBit(EXTI_Line0);
}
//! \brief The ISR for the EXTI1_IRQn interrupt.
void EXTI1_IRQHandler(void)
{
if(gpio_obj.callback_list[1].callback != NULL) {
gpio_ext_it_cb_t cb = gpio_obj.callback_list[1].callback;
void *param = gpio_obj.callback_list[1].param;
cb(param);
}
EXTI_ClearITPendingBit(EXTI_Line1);
}
//! \brief The ISR for the EXTI2_IRQn interrupt.
void EXTI2_IRQHandler(void)
{
if(gpio_obj.callback_list[2].callback != NULL) {
gpio_ext_it_cb_t cb = gpio_obj.callback_list[2].callback;
void *param = gpio_obj.callback_list[2].param;
cb(param);
}
EXTI_ClearITPendingBit(EXTI_Line2);
}
//! \brief The ISR for the EXTI3_IRQn interrupt.
void EXTI3_IRQHandler(void)
{
if(gpio_obj.callback_list[3].callback != NULL) {
gpio_ext_it_cb_t cb = gpio_obj.callback_list[3].callback;
void *param = gpio_obj.callback_list[3].param;
cb(param);
}
EXTI_ClearITPendingBit(EXTI_Line3);
}
//! \brief The ISR for the EXTI4_IRQn interrupt.
void EXTI4_IRQHandler(void)
{
if(gpio_obj.callback_list[4].callback != NULL) {
gpio_ext_it_cb_t cb = gpio_obj.callback_list[4].callback;
void *param = gpio_obj.callback_list[4].param;
cb(param);
}
EXTI_ClearITPendingBit(EXTI_Line4);
}
//! \brief The ISR for the EXTI9_5_IRQn interrupt.
void EXTI9_5_IRQHandler(void) {
uint32_t exti = 0;
uint8_t pin;
if(EXTI_GetITStatus(EXTI_Line6))
exti = EXTI_Line6;
pin = gpio_bin2dec(exti);
if(gpio_obj.callback_list[pin].callback != NULL) {
gpio_ext_it_cb_t cb = gpio_obj.callback_list[pin].callback;
void *param = gpio_obj.callback_list[pin].param;
cb(param);
}
EXTI_ClearITPendingBit(exti);
}
//! \brief The ISR for the EXTI15_10_IRQn interrupt.
void EXTI15_10_IRQHandler(void) {
// TODO: detect & clear pending bit
}

View File

@@ -0,0 +1,62 @@
//! \file stm32f4_gpio.h
//! \author tkl
//! \date Mai 8, 2012
//! \brief Header file of the stm32f4xx architecture dependent gpio driver.
#ifndef STM32F4_GPIO_H_
#define STM32F4_GPIO_H_
//! callback for the external interrupt
typedef void* (*gpio_ext_it_cb_t)(void*);
//! \brief stm32f4 gpio device
struct stm32f4_gpio {
GPIO_TypeDef *port; //!< Gpio port
const GPIO_InitTypeDef *pin; //!< Gpio pin
const EXTI_InitTypeDef *exti; //!< Gpio exit it (could be NULL)
const NVIC_InitTypeDef *nvic; //!< Gpio nvic (could be NULL)
gpio_ext_it_cb_t ext_it_cb; //!< Gpio ext it callback (could be NULL)
void *param; //!< Parameter for the callback
};
//! \brief Open a gpio.
//! \param gpio The gpio to open. Must be of type stm32f4_gpio_t.
//! \retval -1 in error case.
int stm32f4_gpio_open(const void *gpio);
//! \brief Close a gpio.
//! \param gpio The gpio to close. Must be of type stm32f4_gpio_t.
//! \retval -1 in error case.
int stm32f4_gpio_close(const void *gpio);
//! \brief Read a gpio.
//! \param gpio The gpio to read. Must be of type stm32f4_gpio_t.
//! \return read out value.
char stm32f4_gpio_read(const void *gpio);
//! \brief Write to a gpio.
//! \param gpio The gpio to write. Must be of type stm32f4_gpio_t.
//! \param byte The data to write.
void stm32f4_gpio_write(const void *gpio, char byte);
//! \brief Toggle a gpio.
//! \param gpio The gpio to read. Must be of type stm32f4_gpio_t.
void stm32f4_gpio_toggle(const void *gpio);
//! \brief Set the callback for a gpio pin external interrupt.
//! \param gpio The gpio to set call back for. Must be of type stm32f4_gpio_t.
//! \param callback The function pointer to call back.
//! \param param The parameter for the call back.
//! \retval -1 in error case.
int stm32f4_gpio_set_exti_callback(const void *gpio, const void *callback,
const void *param);
static const struct gpio_fp gpio_fp = {
stm32f4_gpio_open,
stm32f4_gpio_close,
stm32f4_gpio_read,
stm32f4_gpio_write,
stm32f4_gpio_toggle,
stm32f4_gpio_set_exti_callback
};
#endif /* STM32F4_GPIO_H_ */

View File

@@ -0,0 +1,77 @@
//! \file stm32_sys_tick.c
//! \author tkl
//! \date Feb 15, 2012
//! \brief Source file of the stm32f10x architecture dependent sys tick timer implementation.
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include "stm32f4xx.h"
#include "stm32_sys_tick.h"
#include "stm32f4xx_isr.h"
struct stm32_sys_tick_obj {
stm32_sys_tick_cb_t sys_tick_cb;
void *sys_tick_cb_param;
};
static struct stm32_sys_tick_obj stm32_sys_tick_obj;
int stm32_sys_tick_open(const void *sys_tick) {
if(sys_tick == NULL)
return -1;
struct stm32_sys_tick *this = (struct stm32_sys_tick *)sys_tick;
uint32_t div = 1000;
switch(*this->tick_time_base) {
case STM32_SYS_TICK_TIME_BASE_US:
div = 1000000;
break;
case STM32_SYS_TICK_TIME_BASE_MS:
div = 1000;
break;
default:
return -1;
}
if(SysTick_Config(SystemCoreClock / div))
return -1;
return 0;
}
int stm32_sys_tick_close(const void *sys_tick)
{
if(sys_tick == NULL)
return -1;
SysTick->CTRL = 0;
return 0;
}
int stm32_sys_tick_set_cb(const void *sys_tick, const void *callback, const void *param)
{
if((sys_tick == NULL) || (callback == NULL))
return -1;
stm32_sys_tick_obj.sys_tick_cb = (stm32_sys_tick_cb_t)callback;
stm32_sys_tick_obj.sys_tick_cb_param = (void*)param;
return 0;
}
void SysTick_Handler(void)
{
enter_isr();
if(stm32_sys_tick_obj.sys_tick_cb != NULL) {
stm32_sys_tick_cb_t cb = stm32_sys_tick_obj.sys_tick_cb;
void *param = stm32_sys_tick_obj.sys_tick_cb_param;
cb(param);
}
exit_isr();
}

View File

@@ -0,0 +1,49 @@
//! \file stm32_sys_tick.h
//! \author tkl
//! \date Feb 15, 2012
//! \brief Header file of the stm32f10x architecture dependent sys tick timer implementation.
#ifndef STM32_SYS_TICK_H_
#define STM32_SYS_TICK_H_
#include "timer.h"
typedef void* (*stm32_sys_tick_cb_t)(void*); //!< callback for the external interrupt
//! \brief Type of sys tick base time.
enum stm32_sys_tick_time_base {
STM32_SYS_TICK_TIME_BASE_NONE = 0, //!< Not init
STM32_SYS_TICK_TIME_BASE_US, //!< Tick time = 1 us.
STM32_SYS_TICK_TIME_BASE_MS //!< Tick time = 1 ms.
};
//! \brief The sys tick device.
struct stm32_sys_tick {
const enum stm32_sys_tick_time_base *tick_time_base; //!< time base for the system tick
stm32_sys_tick_cb_t sys_tick_cb; //!< callback for the sys tick interrupt
void *sys_tick_cb_param; //!< parameter for the callback
};
//! \brief Open a sys tick timer.
//! \param sys_tick The sys tick to open. Must be of type const stm32_sys_tick_t*.
//! \return -1 in error case.
int stm32_sys_tick_open(const void *sys_tick);
//! \brief Close a sys tick timer.
//! \param sys_tick The sys tick to close. Must be of type const stm32_sys_tick_t*.
//! \return -1 in error case.
int stm32_sys_tick_close(const void *sys_tick);
//! \brief Set the call back for a sys tick timer.
//! \param sys_tick The sys tick to open. Mus be of type const stm32_sys_tick_t*.
//! \param callback The function pointer of the call back function.
//! \param param The parameter for the call back function.
//! \return -1 in error case.
int stm32_sys_tick_set_cb(const void *sys_tick, const void *callback, const void *param);
static const struct timer_fp timer_fp = {
stm32_sys_tick_open,
stm32_sys_tick_close,
stm32_sys_tick_set_cb
};
#endif /* STM32_SYS_TICK_H_ */

View File

@@ -0,0 +1,3 @@
SUB_FOLDER += firmware/arch/stm32f4xx/driver/timer
INCLUDES += firmware/arch/stm32f4xx/driver/timer
DOC_SRC += firmware/arch/stm32f4xx/driver/timer

View File

@@ -0,0 +1,5 @@
#SUB_FOLDER += firmware/arch/stm32f4xx/driver
#INCLUDES += firmware/arch/stm32f4xx/driver
#DOC_SRC += firmware/arch/stm32f4xx/driver
include firmware/arch/stm32f4xx/driver/usb/vcp/vcp.mk

View File

@@ -0,0 +1,191 @@
/**
******************************************************************************
* @file usb_bsp.c
* @author MCD Application Team
* @version V1.0.0
* @date 22-July-2011
* @brief This file is responsible to offer board support package and is
* configurable by user.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "usb_bsp.h"
#include "usbd_conf.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup USB_BSP
* @brief This file is responsible to offer board support package
* @{
*/
/** @defgroup USB_BSP_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USB_BSP_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USB_BSP_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBH_BSP_Private_Variables
* @{
*/
/**
* @}
*/
/** @defgroup USBH_BSP_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @defgroup USB_BSP_Private_Functions
* @{
*/
/**
* @brief USB_OTG_BSP_Init
* Initilizes BSP configurations
* @param None
* @retval None
*/
void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE);
/* Configure SOF VBUS ID DM DP Pins */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 |
GPIO_Pin_9 |
GPIO_Pin_11 |
GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_OTG1_FS) ;
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_OTG1_FS) ;
GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_OTG1_FS) ;
GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_OTG1_FS) ;
/* this for ID line debug */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_OTG1_FS) ;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ;
/* enable the PWR clock */
RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
}
/**
* @brief USB_OTG_BSP_EnableInterrupt
* Enabele USB Global interrupt
* @param None
* @retval None
*/
void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**
* @brief USB_OTG_BSP_uDelay
* This function provides delay time in micro sec
* @param usec : Value of delay required in micro sec
* @retval None
*/
void USB_OTG_BSP_uDelay (const uint32_t usec)
{
uint32_t count = 0;
const uint32_t utime = (120 * usec / 7);
do
{
if ( ++count > utime )
{
return ;
}
}
while (1);
}
/**
* @brief USB_OTG_BSP_mDelay
* This function provides delay time in milli sec
* @param msec : Value of delay required in milli sec
* @retval None
*/
void USB_OTG_BSP_mDelay (const uint32_t msec)
{
USB_OTG_BSP_uDelay(msec * 1000);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,164 @@
/**
******************************************************************************
* @file usb_conf.h
* @author MCD Application Team
* @version V1.0.0
* @date 22-July-2011
* @brief General low level driver configuration
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USB_CONF__H__
#define __USB_CONF__H__
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
/** @addtogroup USB_OTG_DRIVER
* @{
*/
/** @defgroup USB_CONF
* @brief USB low level driver configuration file
* @{
*/
/** @defgroup USB_CONF_Exported_Defines
* @{
*/
/* USB Core and PHY interface configuration.
Tip: To avoid modifying these defines each time you need to change the USB
configuration, you can declare the needed define in your toolchain
compiler preprocessor.
*/
#ifndef USE_USB_OTG_FS
#define USE_USB_OTG_FS
#endif /* USE_USB_OTG_FS */
#define USB_OTG_FS_CORE
/*******************************************************************************
* FIFO Size Configuration in Device mode
*
* (i) Receive data FIFO size = RAM for setup packets +
* OUT endpoint control information +
* data OUT packets + miscellaneous
* Space = ONE 32-bits words
* --> RAM for setup packets = 10 spaces
* (n is the nbr of CTRL EPs the device core supports)
* --> OUT EP CTRL info = 1 space
* (one space for status information written to the FIFO along with each
* received packet)
* --> data OUT packets = (Largest Packet Size / 4) + 1 spaces
* (MINIMUM to receive packets)
* --> OR data OUT packets = at least 2*(Largest Packet Size / 4) + 1 spaces
* (if high-bandwidth EP is enabled or multiple isochronous EPs)
* --> miscellaneous = 1 space per OUT EP
* (one space for transfer complete status information also pushed to the
* FIFO with each endpoint's last packet)
*
* (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for
* that particular IN EP. More space allocated in the IN EP Tx FIFO results
* in a better performance on the USB and can hide latencies on the AHB.
*
* (iii) TXn min size = 16 words. (n : Transmit FIFO index)
* (iv) When a TxFIFO is not used, the Configuration should be as follows:
* case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
* --> Txm can use the space allocated for Txn.
* case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
* --> Txn should be configured with the minimum space of 16 words
* (v) The FIFO is used optimally when used TxFIFOs are allocated in the top
* of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
*******************************************************************************/
/****************** USB OTG FS CONFIGURATION **********************************/
#ifdef USB_OTG_FS_CORE
#define RX_FIFO_FS_SIZE 128
#define TX0_FIFO_FS_SIZE 32
#define TX1_FIFO_FS_SIZE 128
#define TX2_FIFO_FS_SIZE 32
#define TX3_FIFO_FS_SIZE 0
#endif
/****************** USB OTG MODE CONFIGURATION ********************************/
#define USE_DEVICE_MODE
/****************** C Compilers dependant keywords ****************************/
/* In HS mode and when the DMA is used, all variables and data structures dealing
with the DMA during the transaction process should be 4-bytes aligned */
#define __ALIGN_BEGIN
#define __ALIGN_END
/* __packed keyword used to decrease the data type alignment to 1-byte */
#define __packed __attribute__ ((__packed__))
/**
* @}
*/
/** @defgroup USB_CONF_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup USB_CONF_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USB_CONF_Exported_Variables
* @{
*/
/**
* @}
*/
/** @defgroup USB_CONF_Exported_FunctionsPrototype
* @{
*/
/**
* @}
*/
#endif //__USB_CONF__H__
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,27 @@
/*
* usb_it.c
*
* Created on: May 15, 2012
* Author: tkl
*/
#include "usb_core.h"
#include "usbd_core.h"
#include "usbd_cdc_core.h"
#include "usb_dcd_int.h"
#include "usb_vport.h"
void OTG_FS_WKUP_IRQHandler(void) {
if(USB_OTG_dev.cfg.low_power) {
*(uint32_t *)(0xE000ED10) &= 0xFFFFFFF9 ;
// TODO!!!
// SystemInit();
USB_OTG_UngateClock(&USB_OTG_dev);
}
EXTI_ClearITPendingBit(EXTI_Line18);
}
void OTG_FS_IRQHandler(void) {
USBD_OTG_ISR_Handler (&USB_OTG_dev);
}

View File

@@ -0,0 +1,263 @@
/**
******************************************************************************
* @file usbd_cdc_vcp.c
* @author MCD Application Team
* @version V1.0.0
* @date 22-July-2011
* @brief Generic media access Layer.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "usbd_cdc_vcp.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
LINE_CODING linecoding =
{
115200, /* baud rate*/
0x00, /* stop bits-1*/
0x00, /* parity - none*/
0x08 /* nb. of bits 8*/
};
/* These are external variables imported from CDC core to be used for IN
transfer management. */
extern uint8_t APP_Rx_Buffer []; /* Write CDC received data in this buffer.
These data will be sent over USB IN endpoint
in the CDC core functions. */
extern uint32_t APP_Rx_ptr_in; /* Increment this pointer or roll it back to
start address when writing received data
in the buffer APP_Rx_Buffer. */
static uint8_t u8PortReady = 0;
/* Private function prototypes -----------------------------------------------*/
static uint16_t VCP_Init (void);
static uint16_t VCP_DeInit (void);
static uint16_t VCP_Ctrl (uint32_t Cmd, uint32_t wValue, uint8_t* Buf, uint32_t Len);
static uint16_t VCP_DataTx (uint8_t* Buf, uint32_t Len);
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len);
static uint16_t VCP_COMConfig(uint8_t Conf);
CDC_IF_Prop_TypeDef VCP_fops =
{
VCP_Init,
VCP_DeInit,
VCP_Ctrl,
VCP_DataTx,
VCP_DataRx
};
/* Private functions ---------------------------------------------------------*/
/**
* @brief VCP_Init
* Initializes the Media on the STM32
* @param None
* @retval Result of the opeartion (USBD_OK in all cases)
*/
static uint16_t VCP_Init(void)
{
return USBD_OK;
}
/**
* @brief VCP_DeInit
* DeInitializes the Media on the STM32
* @param None
* @retval Result of the opeartion (USBD_OK in all cases)
*/
static uint16_t VCP_DeInit(void)
{
return USBD_OK;
}
/**
* @brief VCP_Ctrl
* Manage the CDC class requests
* @param Cmd: Command code
* @param Buf: Buffer containing command data (request parameters)
* @param Len: Number of data to be sent (in bytes)
* @retval Result of the opeartion (USBD_OK in all cases)
*/
static uint16_t VCP_Ctrl (uint32_t Cmd, uint32_t wValue, uint8_t* Buf, uint32_t Len)
{
uint32_t cacheCmd = 0;
switch (Cmd)
{
case SEND_ENCAPSULATED_COMMAND:
cacheCmd = Cmd;
/* Not needed for this driver */
break;
case GET_ENCAPSULATED_RESPONSE:
cacheCmd = Cmd;
/* Not needed for this driver */
break;
case SET_COMM_FEATURE:
cacheCmd = Cmd;
/* Not needed for this driver */
break;
case GET_COMM_FEATURE:
cacheCmd = Cmd;
/* Not needed for this driver */
break;
case CLEAR_COMM_FEATURE:
cacheCmd = Cmd;
/* Not needed for this driver */
break;
case SET_LINE_CODING:
linecoding.bitrate = (uint32_t)(Buf[0] | (Buf[1] << 8) | (Buf[2] << 16) | (Buf[3] << 24));
linecoding.format = Buf[4];
linecoding.paritytype = Buf[5];
linecoding.datatype = Buf[6];
/* Set the new configuration */
VCP_COMConfig(OTHER_CONFIG);
break;
case GET_LINE_CODING:
Buf[0] = (uint8_t)(linecoding.bitrate);
Buf[1] = (uint8_t)(linecoding.bitrate >> 8);
Buf[2] = (uint8_t)(linecoding.bitrate >> 16);
Buf[3] = (uint8_t)(linecoding.bitrate >> 24);
Buf[4] = linecoding.format;
Buf[5] = linecoding.paritytype;
Buf[6] = linecoding.datatype;
break;
case SET_CONTROL_LINE_STATE:
if(wValue & 1)
{
u8PortReady = 1;
}
else
{
u8PortReady = 0;
}
/* Not needed for this driver */
break;
case SEND_BREAK:
cacheCmd = Cmd;
/* Not needed for this driver */
break;
default:
cacheCmd = Cmd;
break;
}
return USBD_OK;
}
/**
* @brief VCP_DataTx
* CDC received data to be send over USB IN endpoint are managed in
* this function.
* @param Buf: Buffer of data to be sent
* @param Len: Number of data to be sent (in bytes)
* @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL
*/
static uint16_t VCP_DataTx (uint8_t* Buf, uint32_t Len)
{
uint32_t i = 0;
for(i=0; i<Len; i++)
{
if (linecoding.datatype == 7)
{
APP_Rx_Buffer[APP_Rx_ptr_in] = Buf[i] & 0x7F;
}
else if (linecoding.datatype == 8)
{
APP_Rx_Buffer[APP_Rx_ptr_in] = Buf[i];
}
APP_Rx_ptr_in++;
/* To avoid buffer overflow */
if(APP_Rx_ptr_in == APP_RX_DATA_SIZE)
{
APP_Rx_ptr_in = 0;
}
}
return USBD_OK;
}
extern void data_in(unsigned char *buffer, unsigned int size);
/**
* @brief VCP_DataRx
* Data received over USB OUT endpoint are sent over CDC interface
* through this function.
*
* @note
* This function will block any OUT packet reception on USB endpoint
* untill exiting this function. If you exit this function before transfer
* is complete on CDC interface (ie. using DMA controller) it will result
* in receiving more data while previous ones are still not sent.
*
* @param Buf: Buffer of data to be received
* @param Len: Number of data received (in bytes)
* @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL
*/
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)
{
data_in(Buf, Len);
return USBD_OK;
}
/**
* @brief VCP_COMConfig
* Configure the COM Port with default values or values received from host.
* @param Conf: can be DEFAULT_CONFIG to set the default configuration or OTHER_CONFIG
* to set a configuration received from the host.
* @retval None.
*/
static uint16_t VCP_COMConfig(uint8_t Conf)
{
return USBD_OK;
}
uint16_t USB_VCOM_Send(char* buf, uint32_t len)
{
if(u8PortReady == 1)
{
return VCP_DataTx((uint8_t*)buf, len);
}
return 0;
}
uint16_t USB_VCOM_Receive(char* buf, uint32_t len)
{
return 0;
}
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,59 @@
/**
******************************************************************************
* @file usbd_cdc_vcp.h
* @author MCD Application Team
* @version V1.0.0
* @date 22-July-2011
* @brief Header for usbd_cdc_vcp.c file.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USBD_CDC_VCP_H
#define __USBD_CDC_VCP_H
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include "usbd_cdc_core.h"
#include "usbd_conf.h"
/* Exported typef ------------------------------------------------------------*/
/* The following structures groups all needed parameters to be configured for the
ComPort. These parameters can modified on the fly by the host through CDC class
command class requests. */
typedef struct
{
uint32_t bitrate;
uint8_t format;
uint8_t paritytype;
uint8_t datatype;
}LINE_CODING;
/* Exported constants --------------------------------------------------------*/
/* The following define is used to route the USART IRQ handler to be used.
The IRQ handler function is implemented in the usbd_cdc_vcp.c file. */
#define DEFAULT_CONFIG 0
#define OTHER_CONFIG 1
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
uint16_t USB_VCOM_Send(char* buf, uint32_t len);
#endif /* __USBD_CDC_VCP_H */
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,88 @@
/**
******************************************************************************
* @file usbd_conf.h
* @author MCD Application Team
* @version V1.0.0
* @date 22-July-2011
* @brief USB Device configuration file
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USBD_CONF__H__
#define __USBD_CONF__H__
/* Includes ------------------------------------------------------------------*/
/** @defgroup USB_CONF_Exported_Defines
* @{
*/
#define USBD_CFG_MAX_NUM 1
#define USBD_ITF_MAX_NUM 1
#define USB_MAX_STR_DESC_SIZ 50
/** @defgroup USB_VCP_Class_Layer_Parameter
* @{
*/
#define CDC_IN_EP 0x81 /* EP1 for data IN */
#define CDC_OUT_EP 0x01 /* EP1 for data OUT */
#define CDC_CMD_EP 0x82 /* EP2 for CDC commands */
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
#define CDC_DATA_MAX_PACKET_SIZE 64 /* Endpoint IN & OUT Packet size */
#define CDC_CMD_PACKET_SZE 8 /* Control Endpoint Packet size */
#define CDC_IN_FRAME_INTERVAL 5 /* Number of frames between IN transfers */
#define APP_RX_DATA_SIZE 2048 /* Total size of IN buffer:
APP_RX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > CDC_IN_FRAME_INTERVAL */
#define APP_FOPS VCP_fops
/**
* @}
*/
/** @defgroup USB_CONF_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup USB_CONF_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USB_CONF_Exported_Variables
* @{
*/
/**
* @}
*/
/** @defgroup USB_CONF_Exported_FunctionsPrototype
* @{
*/
/**
* @}
*/
#endif //__USBD_CONF__H__
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,303 @@
/**
******************************************************************************
* @file usbd_desc.c
* @author MCD Application Team
* @version V1.0.0
* @date 22-July-2011
* @brief This file provides the USBD descriptors and string formating method.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "usbd_core.h"
#include "usbd_desc.h"
#include "usbd_req.h"
#include "usbd_conf.h"
#include "usb_regs.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_DESC
* @brief USBD descriptors module
* @{
*/
/** @defgroup USBD_DESC_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBD_DESC_Private_Defines
* @{
*/
#define USBD_VID 0x0483
#define USBD_PID 0x5740
/** @defgroup USB_String_Descriptors
* @{
*/
#define USBD_LANGID_STRING 0x409
#define USBD_MANUFACTURER_STRING "NoizeTronics"
#define USBD_PRODUCT_HS_STRING "cm4_discovery vcp in hs mode"
#define USBD_SERIALNUMBER_HS_STRING "00000000050B"
#define USBD_PRODUCT_FS_STRING "cm4_discovery vcp in fs Mode"
#define USBD_SERIALNUMBER_FS_STRING "00000000050C"
#define USBD_CONFIGURATION_HS_STRING "VCP Config"
#define USBD_INTERFACE_HS_STRING "VCP Interface"
#define USBD_CONFIGURATION_FS_STRING "VCP Config"
#define USBD_INTERFACE_FS_STRING "VCP Interface"
/**
* @}
*/
/** @defgroup USBD_DESC_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBD_DESC_Private_Variables
* @{
*/
USBD_DEVICE USR_desc =
{
USBD_USR_DeviceDescriptor,
USBD_USR_LangIDStrDescriptor,
USBD_USR_ManufacturerStrDescriptor,
USBD_USR_ProductStrDescriptor,
USBD_USR_SerialStrDescriptor,
USBD_USR_ConfigStrDescriptor,
USBD_USR_InterfaceStrDescriptor,
};
/* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
{
0x12, /*bLength */
USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
0x00, /*bcdUSB */
0x02,
0x00, /*bDeviceClass*/
0x00, /*bDeviceSubClass*/
0x00, /*bDeviceProtocol*/
USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize*/
LOBYTE(USBD_VID), /*idVendor*/
HIBYTE(USBD_VID), /*idVendor*/
LOBYTE(USBD_PID), /*idVendor*/
HIBYTE(USBD_PID), /*idVendor*/
0x00, /*bcdDevice rel. 2.00*/
0x02,
USBD_IDX_MFC_STR, /*Index of manufacturer string*/
USBD_IDX_PRODUCT_STR, /*Index of product string*/
USBD_IDX_SERIAL_STR, /*Index of serial number string*/
USBD_CFG_MAX_NUM /*bNumConfigurations*/
} ; /* USB_DeviceDescriptor */
/* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
{
USB_LEN_DEV_QUALIFIER_DESC,
USB_DESC_TYPE_DEVICE_QUALIFIER,
0x00,
0x02,
0x00,
0x00,
0x00,
0x40,
0x01,
0x00,
};
/* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END =
{
USB_SIZ_STRING_LANGID,
USB_DESC_TYPE_STRING,
LOBYTE(USBD_LANGID_STRING),
HIBYTE(USBD_LANGID_STRING),
};
/**
* @}
*/
/** @defgroup USBD_DESC_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @defgroup USBD_DESC_Private_Functions
* @{
*/
/**
* @brief USBD_USR_DeviceDescriptor
* return the device descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
{
*length = sizeof(USBD_DeviceDesc);
return USBD_DeviceDesc;
}
/**
* @brief USBD_USR_LangIDStrDescriptor
* return the LangID string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length)
{
*length = sizeof(USBD_LangIDDesc);
return USBD_LangIDDesc;
}
/**
* @brief USBD_USR_ProductStrDescriptor
* return the product string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
{
if(speed == 0)
{
USBD_GetString (USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
}
else
{
USBD_GetString (USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
}
return USBD_StrDesc;
}
/**
* @brief USBD_USR_ManufacturerStrDescriptor
* return the manufacturer string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length)
{
USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
}
/**
* @brief USBD_USR_SerialStrDescriptor
* return the serial number string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
{
if(speed == USB_OTG_SPEED_HIGH)
{
USBD_GetString (USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length);
}
else
{
USBD_GetString (USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);
}
return USBD_StrDesc;
}
/**
* @brief USBD_USR_ConfigStrDescriptor
* return the configuration string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
{
if(speed == USB_OTG_SPEED_HIGH)
{
USBD_GetString (USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
}
else
{
USBD_GetString (USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
}
return USBD_StrDesc;
}
/**
* @brief USBD_USR_InterfaceStrDescriptor
* return the interface string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length)
{
if(speed == 0)
{
USBD_GetString (USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
}
else
{
USBD_GetString (USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
}
return USBD_StrDesc;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,114 @@
/**
******************************************************************************
* @file usbd_desc.h
* @author MCD Application Team
* @version V1.0.0
* @date 22-July-2011
* @brief header file for the usbd_desc.c file
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USB_DESC_H
#define __USB_DESC_H
/* Includes ------------------------------------------------------------------*/
#include "usbd_def.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup USB_DESC
* @brief general defines for the usb device library file
* @{
*/
/** @defgroup USB_DESC_Exported_Defines
* @{
*/
#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 USB_SIZ_DEVICE_DESC 18
#define USB_SIZ_STRING_LANGID 4
/**
* @}
*/
/** @defgroup USBD_DESC_Exported_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBD_DESC_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBD_DESC_Exported_Variables
* @{
*/
extern uint8_t USBD_DeviceDesc [USB_SIZ_DEVICE_DESC];
extern uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ];
extern uint8_t USBD_OtherSpeedCfgDesc[USB_LEN_CFG_DESC];
extern uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC];
extern uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID];
extern USBD_DEVICE USR_desc;
/**
* @}
*/
/** @defgroup USBD_DESC_Exported_FunctionsPrototype
* @{
*/
uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length);
uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length);
uint8_t * USBD_USR_ManufacturerStrDescriptor ( uint8_t speed , uint16_t *length);
uint8_t * USBD_USR_ProductStrDescriptor ( uint8_t speed , uint16_t *length);
uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length);
uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length);
uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length);
#ifdef USB_SUPPORT_USER_STRING_DESC
uint8_t * USBD_USR_USRStringDesc (uint8_t speed, uint8_t idx , uint16_t *length);
#endif /* USB_SUPPORT_USER_STRING_DESC */
/**
* @}
*/
#endif /* __USBD_DESC_H */
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,160 @@
/**
******************************************************************************
* @file usbd_usr.c
* @author MCD Application Team
* @version V1.0.0
* @date 22-July-2011
* @brief This file includes the user application layer
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "usbd_usr.h"
#include "usbd_ioreq.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_USR
* @brief This file includes the user application layer
* @{
*/
/** @defgroup USBD_USR_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBD_USR_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USBD_USR_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBD_USR_Private_Variables
* @{
*/
USBD_Usr_cb_TypeDef USR_cb =
{
USBD_USR_Init,
USBD_USR_DeviceReset,
USBD_USR_DeviceConfigured,
USBD_USR_DeviceSuspended,
USBD_USR_DeviceResumed,
};
/**
* @}
*/
/** @defgroup USBD_USR_Private_Constants
* @{
*/
/**
* @}
*/
/** @defgroup USBD_USR_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @defgroup USBD_USR_Private_Functions
* @{
*/
/**
* @brief USBD_USR_Init
* Displays the message on LCD for host lib initialization
* @param None
* @retval None
*/
void USBD_USR_Init(void)
{
}
/**
* @brief USBD_USR_DeviceReset
* Displays the message on LCD on device Reset Event
* @param speed : device speed
* @retval None
*/
void USBD_USR_DeviceReset(uint8_t speed )
{
}
/**
* @brief USBD_USR_DeviceConfigured
* Displays the message on LCD on device configuration Event
* @param None
* @retval Staus
*/
void USBD_USR_DeviceConfigured (void)
{
}
/**
* @brief USBD_USR_DeviceSuspended
* Displays the message on LCD on device suspend Event
* @param None
* @retval None
*/
void USBD_USR_DeviceSuspended(void)
{
}
/**
* @brief USBD_USR_DeviceResumed
* Displays the message on LCD on device resume Event
* @param None
* @retval None
*/
void USBD_USR_DeviceResumed(void)
{
}
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,3 @@
SUB_FOLDER += firmware/arch/stm32f4xx/driver/usb/vcp
INCLUDES += firmware/arch/stm32f4xx/driver/usb/vcp
#DOC_SRC += firmware/arch/stm32f4xx/driver/usb/vcp

View File

@@ -0,0 +1,93 @@
/*
* drv_usb_vport.c
*
* Created on: Feb 2, 2012
* Author: tkl
*/
#include <stdint.h>
#include <string.h>
#include "usb_vport.h"
//-----------------------------------------------------------------------------
struct {
const void *callback;
const void *parameter;
char *buffer;
unsigned int size;
}usb_vport_obj;
//------------------------------------------------------------------------------
typedef void* (*stm32_usb_vport_cb_t)(const void*);
//------------------------------------------------------------------------------
int stm32_usb_vport_init(const stm32_usb_vport_t *this) {
usb_vport_obj.callback = NULL;
usb_vport_obj.parameter = NULL;
usb_vport_obj.buffer = NULL;
usb_vport_obj.size = 0;
return 0;
}
//-----------------------------------------------------------------------------
int stm32_usb_vport_open(const void *this) {
// USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb);
return 1;
}
//-----------------------------------------------------------------------------
int stm32_usb_vport_close(const void *this) {
return 0;
}
//-----------------------------------------------------------------------------
int stm32_usb_vport_read(const void *this, char *buffer, int size) {
int ret = -1;
if(size >= usb_vport_obj.size) {
// no rest
memcpy(buffer, usb_vport_obj.buffer, usb_vport_obj.size);
usb_vport_obj.buffer = NULL;
ret = usb_vport_obj.size;
usb_vport_obj.size = 0;
}
else if(size < usb_vport_obj.size) {
memcpy(buffer, usb_vport_obj.buffer, size);
usb_vport_obj.buffer += size;
usb_vport_obj.size -= size;
ret = size;
/*
if(NULL != usb_vport_obj.callback) {
stm32_usb_vport_cb_t cb = usb_vport_obj.callback;
cb(usb_vport_obj.parameter);
}
*/
}
return ret;
}
//-----------------------------------------------------------------------------
int stm32_usb_vport_write(const void *this, const char *buffer, int size) {
return USB_VCOM_Send((char *)buffer, size);
}
//-----------------------------------------------------------------------------
int stm32_usb_vport_set_cb(const void *this, const void *callback, const void *param) {
if(NULL == callback) {
return -1;
}
usb_vport_obj.callback = callback;
usb_vport_obj.parameter = param;
return 0;
}
//-----------------------------------------------------------------------------
extern void data_in(unsigned char *buffer, unsigned int size) {
if(NULL != usb_vport_obj.callback) {
stm32_usb_vport_cb_t cb = usb_vport_obj.callback;
usb_vport_obj.buffer = (char *)buffer;
usb_vport_obj.size = size;
cb(usb_vport_obj.parameter);
}
}

View File

@@ -0,0 +1,54 @@
/*
* drv_usb_vport_interface.h
*
* Created on: Feb 2, 2012
* Author: tkl
*/
#ifndef DRV_USB_VPORT_INTERFACE_H_
#define DRV_USB_VPORT_INTERFACE_H_
#include "uart.h"
#include "usbd_cdc_core.h"
#include "usbd_usr.h"
#include "usbd_desc.h"
#include "usbd_cdc_vcp.h"
//! \brief Usb Device for stdout, stdin & stderr.
__ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END ;
//-----------------------------------------------------------------------------
typedef struct {
}stm32_usb_vport_t;
//-----------------------------------------------------------------------------
int stm32_usb_vport_init(const stm32_usb_vport_t *this);
//-----------------------------------------------------------------------------
//! \brief open the virual com port device
int stm32_usb_vport_open(const void *this);
//-----------------------------------------------------------------------------
//! \brief close the virual com port device
int stm32_usb_vport_close(const void *this);
//-----------------------------------------------------------------------------
int stm32_usb_vport_read(const void *this, char *buffer, int size);
//-----------------------------------------------------------------------------
int stm32_usb_vport_write(const void *this, const char *buffer, int size);
//-----------------------------------------------------------------------------
int stm32_usb_vport_set_cb(const void *this, const void *callback, const void *param);
//------------------------------------------------------------------------------
static const struct uart_fp usb_vport_fp = {
stm32_usb_vport_open,
stm32_usb_vport_close,
stm32_usb_vport_read,
stm32_usb_vport_write,
stm32_usb_vport_set_cb
};
#endif /* DRV_USB_VPORT_INTERFACE_H_ */

View File

@@ -0,0 +1,3 @@
SUB_FOLDER += firmware/arch/stm32f4xx/driver/usb_vport
INCLUDES += firmware/arch/stm32f4xx/driver/usb_vport
DOC_SRC += firmware/arch/stm32f4xx/driver/usb_vport