mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-20 09:28:49 +08:00
add mass_storage for stm32_radio
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@269 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : fsmc_nand.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Header for fsmc_nand.c file.
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __FSMC_NAND_H
|
||||
#define __FSMC_NAND_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Maker_ID;
|
||||
uint8_t Device_ID;
|
||||
uint8_t Third_ID;
|
||||
uint8_t Fourth_ID;
|
||||
}NAND_IDTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t Zone;
|
||||
uint16_t Block;
|
||||
uint16_t Page;
|
||||
} NAND_ADDRESS;
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* NAND Area definition for STM3210E-EVAL Board RevD */
|
||||
#define CMD_AREA (uint32_t)(1<<16) /* A16 = CLE high */
|
||||
#define ADDR_AREA (uint32_t)(1<<17) /* A17 = ALE high */
|
||||
|
||||
#define DATA_AREA ((uint32_t)0x00000000)
|
||||
|
||||
/* FSMC NAND memory command */
|
||||
#define NAND_CMD_AREA_A ((uint8_t)0x00)
|
||||
#define NAND_CMD_AREA_B ((uint8_t)0x01)
|
||||
#define NAND_CMD_AREA_C ((uint8_t)0x50)
|
||||
#define NAND_CMD_AREA_TRUE1 ((uint8_t)0x30)
|
||||
|
||||
#define NAND_CMD_WRITE0 ((uint8_t)0x80)
|
||||
#define NAND_CMD_WRITE_TRUE1 ((uint8_t)0x10)
|
||||
|
||||
#define NAND_CMD_ERASE0 ((uint8_t)0x60)
|
||||
#define NAND_CMD_ERASE1 ((uint8_t)0xD0)
|
||||
|
||||
#define NAND_CMD_READID ((uint8_t)0x90)
|
||||
#define NAND_CMD_STATUS ((uint8_t)0x70)
|
||||
#define NAND_CMD_LOCK_STATUS ((uint8_t)0x7A)
|
||||
#define NAND_CMD_RESET ((uint8_t)0xFF)
|
||||
|
||||
/* NAND memory status */
|
||||
#define NAND_VALID_ADDRESS ((uint32_t)0x00000100)
|
||||
#define NAND_INVALID_ADDRESS ((uint32_t)0x00000200)
|
||||
#define NAND_TIMEOUT_ERROR ((uint32_t)0x00000400)
|
||||
#define NAND_BUSY ((uint32_t)0x00000000)
|
||||
#define NAND_ERROR ((uint32_t)0x00000001)
|
||||
#define NAND_READY ((uint32_t)0x00000040)
|
||||
|
||||
/* FSMC NAND memory parameters */
|
||||
#define NAND_PAGE_SIZE ((uint16_t)0x0200) /* 512 bytes per page w/o Spare Area */
|
||||
#define NAND_BLOCK_SIZE ((uint16_t)0x0020) /* 32x512 bytes pages per block */
|
||||
#define NAND_ZONE_SIZE ((uint16_t)0x0400) /* 1024 Block per zone */
|
||||
#define NAND_SPARE_AREA_SIZE ((uint16_t)0x0010) /* last 16 bytes as spare area */
|
||||
#define NAND_MAX_ZONE ((uint16_t)0x0004) /* 4 zones of 1024 block */
|
||||
|
||||
/* FSMC NAND memory address computation */
|
||||
#define ADDR_1st_CYCLE(ADDR) (uint8_t)((ADDR)& 0xFF) /* 1st addressing cycle */
|
||||
#define ADDR_2nd_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF00) >> 8) /* 2nd addressing cycle */
|
||||
#define ADDR_3rd_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF0000) >> 16) /* 3rd addressing cycle */
|
||||
#define ADDR_4th_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF000000) >> 24) /* 4th addressing cycle */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void FSMC_NAND_Init(void);
|
||||
void FSMC_NAND_ReadID(NAND_IDTypeDef* NAND_ID);
|
||||
uint32_t FSMC_NAND_WriteSmallPage(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumPageToWrite);
|
||||
uint32_t FSMC_NAND_ReadSmallPage (uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumPageToRead);
|
||||
uint32_t FSMC_NAND_WriteSpareArea(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumSpareAreaTowrite);
|
||||
uint32_t FSMC_NAND_ReadSpareArea(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumSpareAreaToRead);
|
||||
uint32_t FSMC_NAND_EraseBlock(NAND_ADDRESS Address);
|
||||
uint32_t FSMC_NAND_Reset(void);
|
||||
uint32_t FSMC_NAND_GetStatus(void);
|
||||
uint32_t FSMC_NAND_ReadStatus(void);
|
||||
uint32_t FSMC_NAND_AddressIncrement(NAND_ADDRESS* Address);
|
||||
|
||||
#endif /* __FSMC_NAND_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,48 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : hw_config.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Hardware Configuration & Setup
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __HW_CONFIG_H
|
||||
#define __HW_CONFIG_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
#define BULK_MAX_PACKET_SIZE 0x00000040
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void Set_System(void);
|
||||
void Set_USBClock(void);
|
||||
void Enter_LowPowerMode(void);
|
||||
void Leave_LowPowerMode(void);
|
||||
void USB_Interrupts_Config(void);
|
||||
void Led_Config(void);
|
||||
void Led_RW_ON(void);
|
||||
void Led_RW_OFF(void);
|
||||
void USB_Configured_LED(void);
|
||||
void USB_NotConfigured_LED(void);
|
||||
void USB_Cable_Config (FunctionalState NewState);
|
||||
void Get_SerialNum(void);
|
||||
void MAL_Config(void);
|
||||
void USB_Disconnect_Config(void);
|
||||
/* External variables --------------------------------------------------------*/
|
||||
|
||||
#endif /*__HW_CONFIG_H*/
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,36 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : mass_mal.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Header for mass_mal.c file.
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MASS_MAL_H
|
||||
#define __MASS_MAL_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define MAL_OK 0
|
||||
#define MAL_FAIL 1
|
||||
#define MAX_LUN 1
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
uint16_t MAL_Init (uint8_t lun);
|
||||
uint16_t MAL_GetStatus (uint8_t lun);
|
||||
uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length);
|
||||
uint16_t MAL_Write(uint8_t lun, uint32_t Memory_Offset, uint32_t *Writebuff, uint16_t Transfer_Length);
|
||||
#endif /* __MASS_MAL_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,33 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : memory.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Memory management layer
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __memory_H
|
||||
#define __memory_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x.h"
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define TXFR_IDLE 0
|
||||
#define TXFR_ONGOING 1
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void Write_Memory (uint8_t lun, uint32_t Memory_Offset, uint32_t Transfer_Length);
|
||||
void Read_Memory (uint8_t lun, uint32_t Memory_Offset, uint32_t Transfer_Length);
|
||||
#endif /* __memory_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,67 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : nand_if.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : All functions related to the NAND process
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __NAND_IF_H
|
||||
#define __NAND_IF_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x.h"
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define NAND_OK 0
|
||||
#define NAND_FAIL 1
|
||||
|
||||
#define FREE_BLOCK (1 << 12 )
|
||||
#define BAD_BLOCK (1 << 13 )
|
||||
#define VALID_BLOCK (1 << 14 )
|
||||
#define USED_BLOCK (1 << 15 )
|
||||
|
||||
#define MAX_PHY_BLOCKS_PER_ZONE 1024
|
||||
#define MAX_LOG_BLOCKS_PER_ZONE 1000
|
||||
/* Private Structures---------------------------------------------------------*/
|
||||
typedef struct __SPARE_AREA {
|
||||
uint16_t LogicalIndex;
|
||||
uint16_t DataStatus;
|
||||
uint16_t BlockStatus;
|
||||
} SPARE_AREA;
|
||||
|
||||
typedef enum {
|
||||
WRITE_IDLE = 0,
|
||||
POST_WRITE,
|
||||
PRE_WRITE,
|
||||
WRITE_CLEANUP,
|
||||
WRITE_ONGOING
|
||||
}WRITE_STATE;
|
||||
|
||||
typedef enum {
|
||||
OLD_BLOCK = 0,
|
||||
UNUSED_BLOCK
|
||||
}BLOCK_STATE;
|
||||
|
||||
/* Private macro --------------------------------------------------------------*/
|
||||
//#define WEAR_LEVELLING_SUPPORT
|
||||
#define WEAR_DEPTH 10
|
||||
#define PAGE_TO_WRITE (Transfer_Length/512)
|
||||
/* Private variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes ------------------------------------------------*/
|
||||
/* exported functions ---------------------------------------------------------*/
|
||||
uint16_t NAND_Init (void);
|
||||
uint16_t NAND_Write (uint32_t Memory_Offset, uint32_t *Writebuff, uint16_t Transfer_Length);
|
||||
uint16_t NAND_Read (uint32_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length);
|
||||
uint16_t NAND_Format (void);
|
||||
SPARE_AREA ReadSpareArea (uint32_t address);
|
||||
#endif
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,29 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : platform_config.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Evaluation board specific configuration file.
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __PLATFORM_CONFIG_H
|
||||
#define __PLATFORM_CONFIG_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#define USB_DISCONNECT GPIOA
|
||||
#define USB_DISCONNECT_PIN GPIO_Pin_3
|
||||
#define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOA
|
||||
|
||||
#endif /* __PLATFORM_CONFIG_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,72 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : stm32f10x_conf.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Library configuration file.
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32F10x_CONF_H
|
||||
#define __STM32F10x_CONF_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Uncomment the line below to enable peripheral header file inclusion */
|
||||
/* #include "stm32f10x_adc.h" */
|
||||
/* #include "stm32f10x_bkp.h" */
|
||||
/* #include "stm32f10x_can.h" */
|
||||
/* #include "stm32f10x_crc.h" */
|
||||
/* #include "stm32f10x_dac.h" */
|
||||
/* #include "stm32f10x_dbgmcu.h" */
|
||||
#include "stm32f10x_dma.h"
|
||||
#include "stm32f10x_exti.h"
|
||||
#include "stm32f10x_flash.h"
|
||||
#include "stm32f10x_fsmc.h"
|
||||
#include "stm32f10x_gpio.h"
|
||||
/* #include "stm32f10x_i2c.h" */
|
||||
/* #include "stm32f10x_iwdg.h" */
|
||||
/* #include "stm32f10x_pwr.h" */
|
||||
#include "stm32f10x_rcc.h"
|
||||
/* #include "stm32f10x_rtc.h" */
|
||||
#include "stm32f10x_sdio.h"
|
||||
#include "stm32f10x_spi.h"
|
||||
/* #include "stm32f10x_tim.h" */
|
||||
#include "stm32f10x_usart.h"
|
||||
/* #include "stm32f10x_wwdg.h" */
|
||||
#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Uncomment the line below to expanse the "assert_param" macro in the
|
||||
Standard Peripheral Library drivers code */
|
||||
/* #define USE_FULL_ASSERT 1 */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef USE_FULL_ASSERT
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : assert_param
|
||||
* Description : The assert_param macro is used for function's parameters check.
|
||||
* Input : - expr: If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t* file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#endif /* __STM32F10x_CONF_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,87 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_bot.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : BOT State Machine management
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_BOT_H
|
||||
#define __USB_BOT_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Bulk-only Command Block Wrapper */
|
||||
|
||||
typedef struct _Bulk_Only_CBW
|
||||
{
|
||||
uint32_t dSignature;
|
||||
uint32_t dTag;
|
||||
uint32_t dDataLength;
|
||||
uint8_t bmFlags;
|
||||
uint8_t bLUN;
|
||||
uint8_t bCBLength;
|
||||
uint8_t CB[16];
|
||||
}
|
||||
Bulk_Only_CBW;
|
||||
|
||||
/* Bulk-only Command Status Wrapper */
|
||||
typedef struct _Bulk_Only_CSW
|
||||
{
|
||||
uint32_t dSignature;
|
||||
uint32_t dTag;
|
||||
uint32_t dDataResidue;
|
||||
uint8_t bStatus;
|
||||
}
|
||||
Bulk_Only_CSW;
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Bulk-Only Transfer State machine ********************/
|
||||
/*****************************************************************************/
|
||||
#define BOT_IDLE 0 /* Idle state */
|
||||
#define BOT_DATA_OUT 1 /* Data Out state */
|
||||
#define BOT_DATA_IN 2 /* Data In state */
|
||||
#define BOT_DATA_IN_LAST 3 /* Last Data In Last */
|
||||
#define BOT_CSW_Send 4 /* Command Status Wrapper */
|
||||
#define BOT_ERROR 5 /* error state */
|
||||
|
||||
#define BOT_CBW_SIGNATURE 0x43425355
|
||||
#define BOT_CSW_SIGNATURE 0x53425355
|
||||
#define BOT_CBW_PACKET_LENGTH 31
|
||||
|
||||
#define CSW_DATA_LENGTH 0x000D
|
||||
|
||||
/* CSW Status Definitions */
|
||||
#define CSW_CMD_PASSED 0x00
|
||||
#define CSW_CMD_FAILED 0x01
|
||||
#define CSW_PHASE_ERROR 0x02
|
||||
|
||||
#define SEND_CSW_DISABLE 0
|
||||
#define SEND_CSW_ENABLE 1
|
||||
|
||||
#define DIR_IN 0
|
||||
#define DIR_OUT 1
|
||||
#define BOTH_DIR 2
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void Mass_Storage_In (void);
|
||||
void Mass_Storage_Out (void);
|
||||
void CBW_Decode(void);
|
||||
void Transfer_Data_Request(uint8_t* Data_Pointer, uint16_t Data_Len);
|
||||
void Set_CSW (uint8_t CSW_Status, uint8_t Send_Permission);
|
||||
void Bot_Abort(uint8_t Direction);
|
||||
|
||||
#endif /* __USB_BOT_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_conf.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Mass Storage Demo configuration header
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_CONF_H
|
||||
#define __USB_CONF_H
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* EP_NUM */
|
||||
/* defines how many endpoints are used by the device */
|
||||
/*-------------------------------------------------------------*/
|
||||
#define EP_NUM (3)
|
||||
|
||||
#ifndef STM32F10X_CL
|
||||
/*-------------------------------------------------------------*/
|
||||
/* -------------- Buffer Description Table -----------------*/
|
||||
/*-------------------------------------------------------------*/
|
||||
/* buffer table base address */
|
||||
|
||||
#define BTABLE_ADDRESS (0x00)
|
||||
|
||||
/* EP0 */
|
||||
/* rx/tx buffer base address */
|
||||
#define ENDP0_RXADDR (0x18)
|
||||
#define ENDP0_TXADDR (0x58)
|
||||
|
||||
/* EP1 */
|
||||
/* tx buffer base address */
|
||||
#define ENDP1_TXADDR (0x98)
|
||||
|
||||
/* EP2 */
|
||||
/* Rx buffer base address */
|
||||
#define ENDP2_RXADDR (0xD8)
|
||||
|
||||
|
||||
/* ISTR events */
|
||||
/* IMR_MSK */
|
||||
/* mask defining which events has to be handled */
|
||||
/* by the device application software */
|
||||
#define IMR_MSK (CNTR_CTRM | CNTR_RESETM)
|
||||
#endif /* STM32F10X_CL */
|
||||
|
||||
/* 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
|
||||
|
||||
#ifdef STM32F10X_CL
|
||||
|
||||
/* OTGD-FS-DEVICE IP interrupts Enable definitions */
|
||||
/* Uncomment the define to enable the selected interrupt */
|
||||
//#define INTR_MODEMISMATCH
|
||||
#define INTR_SOFINTR
|
||||
#define INTR_RXSTSQLVL /* Mandatory */
|
||||
//#define INTR_NPTXFEMPTY
|
||||
//#define INTR_GINNAKEFF
|
||||
//#define INTR_GOUTNAKEFF
|
||||
//#define INTR_ERLYSUSPEND
|
||||
#define INTR_USBSUSPEND /* Mandatory */
|
||||
#define INTR_USBRESET /* Mandatory */
|
||||
#define INTR_ENUMDONE /* Mandatory */
|
||||
//#define INTR_ISOOUTDROP
|
||||
#define INTR_EOPFRAME
|
||||
//#define INTR_EPMISMATCH
|
||||
#define INTR_INEPINTR /* Mandatory */
|
||||
#define INTR_OUTEPINTR /* Mandatory */
|
||||
//#define INTR_INCOMPLISOIN
|
||||
//#define INTR_INCOMPLISOOUT
|
||||
#define INTR_WKUPINTR /* Mandatory */
|
||||
|
||||
/* OTGD-FS-DEVICE IP interrupts subroutines */
|
||||
/* Comment the define to enable the selected interrupt subroutine and replace it
|
||||
by user code */
|
||||
#define INTR_MODEMISMATCH_Callback NOP_Process
|
||||
#define INTR_SOFINTR_Callback NOP_Process
|
||||
#define INTR_RXSTSQLVL_Callback NOP_Process
|
||||
#define INTR_NPTXFEMPTY_Callback NOP_Process
|
||||
#define INTR_NPTXFEMPTY_Callback NOP_Process
|
||||
#define INTR_GINNAKEFF_Callback NOP_Process
|
||||
#define INTR_GOUTNAKEFF_Callback NOP_Process
|
||||
#define INTR_ERLYSUSPEND_Callback NOP_Process
|
||||
#define INTR_USBSUSPEND_Callback NOP_Process
|
||||
#define INTR_USBRESET_Callback NOP_Process
|
||||
#define INTR_ENUMDONE_Callback NOP_Process
|
||||
#define INTR_ISOOUTDROP_Callback NOP_Process
|
||||
#define INTR_EOPFRAME_Callback NOP_Process
|
||||
#define INTR_EPMISMATCH_Callback NOP_Process
|
||||
#define INTR_INEPINTR_Callback NOP_Process
|
||||
#define INTR_OUTEPINTR_Callback NOP_Process
|
||||
#define INTR_INCOMPLISOIN_Callback NOP_Process
|
||||
#define INTR_INCOMPLISOOUT_Callback NOP_Process
|
||||
#define INTR_WKUPINTR_Callback NOP_Process
|
||||
|
||||
/* Isochronous data update */
|
||||
#define INTR_RXSTSQLVL_ISODU_Callback NOP_Process
|
||||
|
||||
/* Isochronous transfer parameters */
|
||||
/* Size of a single Isochronous buffer (size of a single transfer) */
|
||||
#define ISOC_BUFFER_SZE 1
|
||||
/* Number of sub-buffers (number of single buffers/transfers), should be even */
|
||||
#define NUM_SUB_BUFFERS 2
|
||||
|
||||
#endif /* STM32F10X_CL */
|
||||
|
||||
#endif /* __USB_CONF_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,49 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_desc.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Descriptor Header for Mass Storage Device
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_DESC_H
|
||||
#define __USB_DESC_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x.h"
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
#define MASS_SIZ_DEVICE_DESC 18
|
||||
#define MASS_SIZ_CONFIG_DESC 32
|
||||
|
||||
#define MASS_SIZ_STRING_LANGID 4
|
||||
#define MASS_SIZ_STRING_VENDOR 38
|
||||
#define MASS_SIZ_STRING_PRODUCT 38
|
||||
#define MASS_SIZ_STRING_SERIAL 26
|
||||
#define MASS_SIZ_STRING_INTERFACE 16
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
extern const uint8_t MASS_DeviceDescriptor[MASS_SIZ_DEVICE_DESC];
|
||||
extern const uint8_t MASS_ConfigDescriptor[MASS_SIZ_CONFIG_DESC];
|
||||
|
||||
extern const uint8_t MASS_StringLangID[MASS_SIZ_STRING_LANGID];
|
||||
extern const uint8_t MASS_StringVendor[MASS_SIZ_STRING_VENDOR];
|
||||
extern const uint8_t MASS_StringProduct[MASS_SIZ_STRING_PRODUCT];
|
||||
extern uint8_t MASS_StringSerial[MASS_SIZ_STRING_SERIAL];
|
||||
extern const uint8_t MASS_StringInterface[MASS_SIZ_STRING_INTERFACE];
|
||||
|
||||
#endif /* __USB_DESC_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_istr.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : This file includes the peripherals header files in the
|
||||
* user application.
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* 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 ------------------------------------------------------- */
|
||||
|
||||
#ifndef STM32F10X_CL
|
||||
void USB_Istr(void);
|
||||
#else /* STM32F10X_CL */
|
||||
u32 STM32_PCD_OTG_ISR_Handler(void);
|
||||
#endif /* STM32F10X_CL */
|
||||
|
||||
/* 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);
|
||||
|
||||
#ifndef STM32F10X_CL
|
||||
|
||||
#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
|
||||
|
||||
#else /* STM32F10X_CL */
|
||||
|
||||
/* Interrupt subroutines user callbacks prototypes.
|
||||
These callbacks are called into the respective interrupt sunroutine functinos
|
||||
and can be tailored for various user application purposes.
|
||||
Note: Make sure that the correspondant interrupt is enabled through the
|
||||
definition in usb_conf.h file */
|
||||
void INTR_MODEMISMATCH_Callback(void);
|
||||
void INTR_SOFINTR_Callback(void);
|
||||
void INTR_RXSTSQLVL_Callback(void);
|
||||
void INTR_NPTXFEMPTY_Callback(void);
|
||||
void INTR_GINNAKEFF_Callback(void);
|
||||
void INTR_GOUTNAKEFF_Callback(void);
|
||||
void INTR_ERLYSUSPEND_Callback(void);
|
||||
void INTR_USBSUSPEND_Callback(void);
|
||||
void INTR_USBRESET_Callback(void);
|
||||
void INTR_ENUMDONE_Callback(void);
|
||||
void INTR_ISOOUTDROP_Callback(void);
|
||||
void INTR_EOPFRAME_Callback(void);
|
||||
void INTR_EPMISMATCH_Callback(void);
|
||||
void INTR_INEPINTR_Callback(void);
|
||||
void INTR_OUTEPINTR_Callback(void);
|
||||
void INTR_INCOMPLISOIN_Callback(void);
|
||||
void INTR_INCOMPLISOOUT_Callback(void);
|
||||
void INTR_WKUPINTR_Callback(void);
|
||||
|
||||
/* Isochronous data update */
|
||||
void INTR_RXSTSQLVL_ISODU_Callback(void);
|
||||
|
||||
#endif /* STM32F10X_CL */
|
||||
|
||||
|
||||
#endif /*__USB_ISTR_H*/
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,58 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_prop.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : All processing related to Mass Storage Demo (Endpoint 0)
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __usb_prop_H
|
||||
#define __usb_prop_H
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define Mass_Storage_GetConfiguration NOP_Process
|
||||
/* #define Mass_Storage_SetConfiguration NOP_Process*/
|
||||
#define Mass_Storage_GetInterface NOP_Process
|
||||
#define Mass_Storage_SetInterface NOP_Process
|
||||
#define Mass_Storage_GetStatus NOP_Process
|
||||
/* #define Mass_Storage_ClearFeature NOP_Process*/
|
||||
#define Mass_Storage_SetEndPointFeature NOP_Process
|
||||
#define Mass_Storage_SetDeviceFeature NOP_Process
|
||||
/*#define Mass_Storage_SetDeviceAddress NOP_Process*/
|
||||
|
||||
/* MASS Storage Requests*/
|
||||
#define GET_MAX_LUN 0xFE
|
||||
#define MASS_STORAGE_RESET 0xFF
|
||||
#define LUN_DATA_LENGTH 1
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void MASS_init(void);
|
||||
void MASS_Reset(void);
|
||||
void Mass_Storage_SetConfiguration(void);
|
||||
void Mass_Storage_ClearFeature(void);
|
||||
void Mass_Storage_SetDeviceAddress (void);
|
||||
void MASS_Status_In (void);
|
||||
void MASS_Status_Out (void);
|
||||
RESULT MASS_Data_Setup(uint8_t);
|
||||
RESULT MASS_NoData_Setup(uint8_t);
|
||||
RESULT MASS_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting);
|
||||
uint8_t *MASS_GetDeviceDescriptor(uint16_t );
|
||||
uint8_t *MASS_GetConfigDescriptor(uint16_t);
|
||||
uint8_t *MASS_GetStringDescriptor(uint16_t);
|
||||
uint8_t *Get_Max_Lun(uint16_t Length);
|
||||
|
||||
#endif /* __usb_prop_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_pwr.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Connection/disconnection & power management header
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_PWR_H
|
||||
#define __USB_PWR_H
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_core.h"
|
||||
/* 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 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,139 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_scsi.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : All processing related to the SCSI commands
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_SCSI_H
|
||||
#define __USB_SCSI_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x.h"
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* SCSI Commands */
|
||||
#define SCSI_FORMAT_UNIT 0x04
|
||||
#define SCSI_INQUIRY 0x12
|
||||
#define SCSI_MODE_SELECT6 0x15
|
||||
#define SCSI_MODE_SELECT10 0x55
|
||||
#define SCSI_MODE_SENSE6 0x1A
|
||||
#define SCSI_MODE_SENSE10 0x5A
|
||||
#define SCSI_ALLOW_MEDIUM_REMOVAL 0x1E
|
||||
#define SCSI_READ6 0x08
|
||||
#define SCSI_READ10 0x28
|
||||
#define SCSI_READ12 0xA8
|
||||
#define SCSI_READ16 0x88
|
||||
|
||||
#define SCSI_READ_CAPACITY10 0x25
|
||||
#define SCSI_READ_CAPACITY16 0x9E
|
||||
|
||||
#define SCSI_REQUEST_SENSE 0x03
|
||||
#define SCSI_START_STOP_UNIT 0x1B
|
||||
#define SCSI_TEST_UNIT_READY 0x00
|
||||
#define SCSI_WRITE6 0x0A
|
||||
#define SCSI_WRITE10 0x2A
|
||||
#define SCSI_WRITE12 0xAA
|
||||
#define SCSI_WRITE16 0x8A
|
||||
|
||||
#define SCSI_VERIFY10 0x2F
|
||||
#define SCSI_VERIFY12 0xAF
|
||||
#define SCSI_VERIFY16 0x8F
|
||||
|
||||
#define SCSI_SEND_DIAGNOSTIC 0x1D
|
||||
#define SCSI_READ_FORMAT_CAPACITIES 0x23
|
||||
|
||||
#define NO_SENSE 0
|
||||
#define RECOVERED_ERROR 1
|
||||
#define NOT_READY 2
|
||||
#define MEDIUM_ERROR 3
|
||||
#define HARDWARE_ERROR 4
|
||||
#define ILLEGAL_REQUEST 5
|
||||
#define UNIT_ATTENTION 6
|
||||
#define DATA_PROTECT 7
|
||||
#define BLANK_CHECK 8
|
||||
#define VENDOR_SPECIFIC 9
|
||||
#define COPY_ABORTED 10
|
||||
#define ABORTED_COMMAND 11
|
||||
#define VOLUME_OVERFLOW 13
|
||||
#define MISCOMPARE 14
|
||||
|
||||
|
||||
#define INVALID_COMMAND 0x20
|
||||
#define INVALID_FIELED_IN_COMMAND 0x24
|
||||
#define PARAMETER_LIST_LENGTH_ERROR 0x1A
|
||||
#define INVALID_FIELD_IN_PARAMETER_LIST 0x26
|
||||
#define ADDRESS_OUT_OF_RANGE 0x21
|
||||
#define MEDIUM_NOT_PRESENT 0x3A
|
||||
#define MEDIUM_HAVE_CHANGED 0x28
|
||||
|
||||
#define READ_FORMAT_CAPACITY_DATA_LEN 0x0C
|
||||
#define READ_CAPACITY10_DATA_LEN 0x08
|
||||
#define MODE_SENSE10_DATA_LEN 0x08
|
||||
#define MODE_SENSE6_DATA_LEN 0x04
|
||||
#define REQUEST_SENSE_DATA_LEN 0x12
|
||||
#define STANDARD_INQUIRY_DATA_LEN 0x24
|
||||
#define BLKVFY 0x04
|
||||
|
||||
extern uint8_t Page00_Inquiry_Data[];
|
||||
extern uint8_t Standard_Inquiry_Data[];
|
||||
extern uint8_t Standard_Inquiry_Data2[];
|
||||
extern uint8_t Mode_Sense6_data[];
|
||||
extern uint8_t Mode_Sense10_data[];
|
||||
extern uint8_t Scsi_Sense_Data[];
|
||||
extern uint8_t ReadCapacity10_Data[];
|
||||
extern uint8_t ReadFormatCapacity_Data [];
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void SCSI_Inquiry_Cmd(uint8_t lun);
|
||||
void SCSI_ReadFormatCapacity_Cmd(uint8_t lun);
|
||||
void SCSI_ReadCapacity10_Cmd(uint8_t lun);
|
||||
void SCSI_RequestSense_Cmd (uint8_t lun);
|
||||
void SCSI_Start_Stop_Unit_Cmd(uint8_t lun);
|
||||
void SCSI_ModeSense6_Cmd (uint8_t lun);
|
||||
void SCSI_ModeSense10_Cmd (uint8_t lun);
|
||||
void SCSI_Write10_Cmd(uint8_t lun , uint32_t LBA , uint32_t BlockNbr);
|
||||
void SCSI_Read10_Cmd(uint8_t lun , uint32_t LBA , uint32_t BlockNbr);
|
||||
void SCSI_Verify10_Cmd(uint8_t lun);
|
||||
|
||||
void SCSI_Invalid_Cmd(uint8_t lun);
|
||||
void SCSI_Valid_Cmd(uint8_t lun);
|
||||
bool SCSI_Address_Management(uint8_t lun , uint8_t Cmd , uint32_t LBA , uint32_t BlockNbr);
|
||||
|
||||
void Set_Scsi_Sense_Data(uint8_t lun , uint8_t Sens_Key, uint8_t Asc);
|
||||
void SCSI_TestUnitReady_Cmd (uint8_t lun);
|
||||
void SCSI_Format_Cmd (uint8_t lun);
|
||||
|
||||
//#define SCSI_TestUnitReady_Cmd SCSI_Valid_Cmd
|
||||
#define SCSI_Prevent_Removal_Cmd SCSI_Valid_Cmd
|
||||
|
||||
/* Invalid (Unsupported) commands */
|
||||
#define SCSI_READ_CAPACITY16_Cmd SCSI_Invalid_Cmd
|
||||
//#define SCSI_FormatUnit_Cmd SCSI_Invalid_Cmd
|
||||
#define SCSI_Write6_Cmd SCSI_Invalid_Cmd
|
||||
#define SCSI_Write16_Cmd SCSI_Invalid_Cmd
|
||||
#define SCSI_Write12_Cmd SCSI_Invalid_Cmd
|
||||
#define SCSI_Read6_Cmd SCSI_Invalid_Cmd
|
||||
#define SCSI_Read12_Cmd SCSI_Invalid_Cmd
|
||||
#define SCSI_Read16_Cmd SCSI_Invalid_Cmd
|
||||
#define SCSI_Send_Diagnostic_Cmd SCSI_Invalid_Cmd
|
||||
#define SCSI_Mode_Select6_Cmd SCSI_Invalid_Cmd
|
||||
#define SCSI_Mode_Select10_Cmd SCSI_Invalid_Cmd
|
||||
#define SCSI_Verify12_Cmd SCSI_Invalid_Cmd
|
||||
#define SCSI_Verify16_Cmd SCSI_Invalid_Cmd
|
||||
|
||||
#endif /* __USB_SCSI_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,490 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : fsmc_nand.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.0.1
|
||||
* Date : 04/27/2009
|
||||
* Description : This file provides a set of functions needed to drive the
|
||||
* NAND512W3A2 memory mounted on STM3210E-EVAL board.
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "fsmc_nand.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
#define FSMC_Bank_NAND FSMC_Bank2_NAND
|
||||
#define Bank_NAND_ADDR Bank2_NAND_ADDR
|
||||
#define Bank2_NAND_ADDR ((uint32_t)0x70000000)
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
#define ROW_ADDRESS (Address.Page + (Address.Block + (Address.Zone * NAND_ZONE_SIZE)) * NAND_BLOCK_SIZE)
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/*******************************************************************************
|
||||
* Function Name : FSMC_NAND_Init
|
||||
* Description : Configures the FSMC and GPIOs to interface with the NAND memory.
|
||||
* This function must be called before any write/read operation
|
||||
* on the NAND.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void FSMC_NAND_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
FSMC_NANDInitTypeDef FSMC_NANDInitStructure;
|
||||
FSMC_NAND_PCCARDTimingInitTypeDef p;
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
|
||||
RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, ENABLE);
|
||||
|
||||
/*-- GPIO Configuration ------------------------------------------------------*/
|
||||
/* CLE, ALE, D0->D3, NOE, NWE and NCE2 NAND pin configuration */
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_14 | GPIO_Pin_15 |
|
||||
GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
|
||||
GPIO_Pin_7;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
|
||||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||
|
||||
/* D4->D7 NAND pin configuration */
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
|
||||
|
||||
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||||
|
||||
|
||||
/* NWAIT NAND pin configuration */
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
|
||||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||
|
||||
/* INT2 NAND pin configuration */
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
|
||||
GPIO_Init(GPIOG, &GPIO_InitStructure);
|
||||
|
||||
/*-- FSMC Configuration ------------------------------------------------------*/
|
||||
p.FSMC_SetupTime = 0x1;
|
||||
p.FSMC_WaitSetupTime = 0x3;
|
||||
p.FSMC_HoldSetupTime = 0x2;
|
||||
p.FSMC_HiZSetupTime = 0x1;
|
||||
|
||||
FSMC_NANDInitStructure.FSMC_Bank = FSMC_Bank2_NAND;
|
||||
FSMC_NANDInitStructure.FSMC_Waitfeature = FSMC_Waitfeature_Enable;
|
||||
FSMC_NANDInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
|
||||
FSMC_NANDInitStructure.FSMC_ECC = FSMC_ECC_Enable;
|
||||
FSMC_NANDInitStructure.FSMC_ECCPageSize = FSMC_ECCPageSize_512Bytes;
|
||||
FSMC_NANDInitStructure.FSMC_TCLRSetupTime = 0x00;
|
||||
FSMC_NANDInitStructure.FSMC_TARSetupTime = 0x00;
|
||||
FSMC_NANDInitStructure.FSMC_CommonSpaceTimingStruct = &p;
|
||||
FSMC_NANDInitStructure.FSMC_AttributeSpaceTimingStruct = &p;
|
||||
|
||||
FSMC_NANDInit(&FSMC_NANDInitStructure);
|
||||
|
||||
/* FSMC NAND Bank Cmd Test */
|
||||
FSMC_NANDCmd(FSMC_Bank2_NAND, ENABLE);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function Name : FSMC_NAND_ReadID
|
||||
* Description : Reads NAND memory's ID.
|
||||
* Input : - NAND_ID: pointer to a NAND_IDTypeDef structure which will hold
|
||||
* the Manufacturer and Device ID.
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void FSMC_NAND_ReadID(NAND_IDTypeDef* NAND_ID)
|
||||
{
|
||||
uint32_t data = 0;
|
||||
|
||||
/* Send Command to the command area */
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = 0x90;
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
|
||||
|
||||
/* Sequence to read ID from NAND flash */
|
||||
data = *(__IO uint32_t *)(Bank_NAND_ADDR | DATA_AREA);
|
||||
|
||||
NAND_ID->Maker_ID = ADDR_1st_CYCLE (data);
|
||||
NAND_ID->Device_ID = ADDR_2nd_CYCLE (data);
|
||||
NAND_ID->Third_ID = ADDR_3rd_CYCLE (data);
|
||||
NAND_ID->Fourth_ID = ADDR_4th_CYCLE (data);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function Name : FSMC_NAND_WriteSmallPage
|
||||
* Description : This routine is for writing one or several 512 Bytes Page size.
|
||||
* Input : - pBuffer: pointer on the Buffer containing data to be written
|
||||
* - Address: First page address
|
||||
* - NumPageToWrite: Number of page to write
|
||||
* Output : None
|
||||
* Return : New status of the NAND operation. This parameter can be:
|
||||
* - NAND_TIMEOUT_ERROR: when the previous operation generate
|
||||
* a Timeout error
|
||||
* - NAND_READY: when memory is ready for the next operation
|
||||
* And the new status of the increment address operation. It can be:
|
||||
* - NAND_VALID_ADDRESS: When the new address is valid address
|
||||
* - NAND_INVALID_ADDRESS: When the new address is invalid address
|
||||
*******************************************************************************/
|
||||
uint32_t FSMC_NAND_WriteSmallPage(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumPageToWrite)
|
||||
{
|
||||
uint32_t index = 0x00, numpagewritten = 0x00, addressstatus = NAND_VALID_ADDRESS;
|
||||
uint32_t status = NAND_READY, size = 0x00;
|
||||
|
||||
while((NumPageToWrite != 0x00) && (addressstatus == NAND_VALID_ADDRESS) && (status == NAND_READY))
|
||||
{
|
||||
/* Page write command and address */
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_A;
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE0;
|
||||
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
|
||||
|
||||
/* Calculate the size */
|
||||
size = NAND_PAGE_SIZE + (NAND_PAGE_SIZE * numpagewritten);
|
||||
|
||||
/* Write data */
|
||||
for(; index < size; index++)
|
||||
{
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | DATA_AREA) = pBuffer[index];
|
||||
}
|
||||
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE_TRUE1;
|
||||
|
||||
/* Check status for successful operation */
|
||||
status = FSMC_NAND_GetStatus();
|
||||
|
||||
if(status == NAND_READY)
|
||||
{
|
||||
numpagewritten++;
|
||||
|
||||
NumPageToWrite--;
|
||||
|
||||
/* Calculate Next small page Address */
|
||||
addressstatus = FSMC_NAND_AddressIncrement(&Address);
|
||||
}
|
||||
}
|
||||
|
||||
return (status | addressstatus);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function Name : FSMC_NAND_ReadSmallPage
|
||||
* Description : This routine is for sequential read from one or several
|
||||
* 512 Bytes Page size.
|
||||
* Input : - pBuffer: pointer on the Buffer to fill
|
||||
* - Address: First page address
|
||||
* - NumPageToRead: Number of page to read
|
||||
* Output : None
|
||||
* Return : New status of the NAND operation. This parameter can be:
|
||||
* - NAND_TIMEOUT_ERROR: when the previous operation generate
|
||||
* a Timeout error
|
||||
* - NAND_READY: when memory is ready for the next operation
|
||||
* And the new status of the increment address operation. It can be:
|
||||
* - NAND_VALID_ADDRESS: When the new address is valid address
|
||||
* - NAND_INVALID_ADDRESS: When the new address is invalid address
|
||||
*******************************************************************************/
|
||||
uint32_t FSMC_NAND_ReadSmallPage(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumPageToRead)
|
||||
{
|
||||
uint32_t index = 0x00, numpageread = 0x00, addressstatus = NAND_VALID_ADDRESS;
|
||||
uint32_t status = NAND_READY, size = 0x00;
|
||||
|
||||
while((NumPageToRead != 0x0) && (addressstatus == NAND_VALID_ADDRESS))
|
||||
{
|
||||
/* Page Read command and page address */
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_A;
|
||||
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
|
||||
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_TRUE1;
|
||||
|
||||
/* Calculate the size */
|
||||
size = NAND_PAGE_SIZE + (NAND_PAGE_SIZE * numpageread);
|
||||
|
||||
/* Get Data into Buffer */
|
||||
for(; index < size; index++)
|
||||
{
|
||||
pBuffer[index]= *(__IO uint8_t *)(Bank_NAND_ADDR | DATA_AREA);
|
||||
}
|
||||
|
||||
numpageread++;
|
||||
|
||||
NumPageToRead--;
|
||||
|
||||
/* Calculate page address */
|
||||
addressstatus = FSMC_NAND_AddressIncrement(&Address);
|
||||
}
|
||||
|
||||
status = FSMC_NAND_GetStatus();
|
||||
|
||||
return (status | addressstatus);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function Name : FSMC_NAND_WriteSpareArea
|
||||
* Description : This routine write the spare area information for the specified
|
||||
* pages addresses.
|
||||
* Input : - pBuffer: pointer on the Buffer containing data to be written
|
||||
* - Address: First page address
|
||||
* - NumSpareAreaTowrite: Number of Spare Area to write
|
||||
* Output : None
|
||||
* Return : New status of the NAND operation. This parameter can be:
|
||||
* - NAND_TIMEOUT_ERROR: when the previous operation generate
|
||||
* a Timeout error
|
||||
* - NAND_READY: when memory is ready for the next operation
|
||||
* And the new status of the increment address operation. It can be:
|
||||
* - NAND_VALID_ADDRESS: When the new address is valid address
|
||||
* - NAND_INVALID_ADDRESS: When the new address is invalid address
|
||||
*******************************************************************************/
|
||||
uint32_t FSMC_NAND_WriteSpareArea(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumSpareAreaTowrite)
|
||||
{
|
||||
uint32_t index = 0x00, numsparesreawritten = 0x00, addressstatus = NAND_VALID_ADDRESS;
|
||||
uint32_t status = NAND_READY, size = 0x00;
|
||||
|
||||
while((NumSpareAreaTowrite != 0x00) && (addressstatus == NAND_VALID_ADDRESS) && (status == NAND_READY))
|
||||
{
|
||||
/* Page write Spare area command and address */
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_C;
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE0;
|
||||
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
|
||||
|
||||
/* Calculate the size */
|
||||
size = NAND_SPARE_AREA_SIZE + (NAND_SPARE_AREA_SIZE * numsparesreawritten);
|
||||
|
||||
/* Write the data */
|
||||
for(; index < size; index++)
|
||||
{
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | DATA_AREA) = pBuffer[index];
|
||||
}
|
||||
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE_TRUE1;
|
||||
|
||||
/* Check status for successful operation */
|
||||
status = FSMC_NAND_GetStatus();
|
||||
|
||||
if(status == NAND_READY)
|
||||
{
|
||||
numsparesreawritten++;
|
||||
|
||||
NumSpareAreaTowrite--;
|
||||
|
||||
/* Calculate Next page Address */
|
||||
addressstatus = FSMC_NAND_AddressIncrement(&Address);
|
||||
}
|
||||
}
|
||||
|
||||
return (status | addressstatus);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function Name : FSMC_NAND_ReadSpareArea
|
||||
* Description : This routine read the spare area information from the specified
|
||||
* pages addresses.
|
||||
* Input : - pBuffer: pointer on the Buffer to fill
|
||||
* - Address: First page address
|
||||
* - NumSpareAreaToRead: Number of Spare Area to read
|
||||
* Output : None
|
||||
* Return : New status of the NAND operation. This parameter can be:
|
||||
* - NAND_TIMEOUT_ERROR: when the previous operation generate
|
||||
* a Timeout error
|
||||
* - NAND_READY: when memory is ready for the next operation
|
||||
* And the new status of the increment address operation. It can be:
|
||||
* - NAND_VALID_ADDRESS: When the new address is valid address
|
||||
* - NAND_INVALID_ADDRESS: When the new address is invalid address
|
||||
*******************************************************************************/
|
||||
uint32_t FSMC_NAND_ReadSpareArea(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumSpareAreaToRead)
|
||||
{
|
||||
uint32_t numsparearearead = 0x00, index = 0x00, addressstatus = NAND_VALID_ADDRESS;
|
||||
uint32_t status = NAND_READY, size = 0x00;
|
||||
|
||||
while((NumSpareAreaToRead != 0x0) && (addressstatus == NAND_VALID_ADDRESS))
|
||||
{
|
||||
/* Page Read command and page address */
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_C;
|
||||
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
|
||||
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_TRUE1;
|
||||
|
||||
/* Data Read */
|
||||
size = NAND_SPARE_AREA_SIZE + (NAND_SPARE_AREA_SIZE * numsparearearead);
|
||||
|
||||
/* Get Data into Buffer */
|
||||
for ( ;index < size; index++)
|
||||
{
|
||||
pBuffer[index] = *(__IO uint8_t *)(Bank_NAND_ADDR | DATA_AREA);
|
||||
}
|
||||
|
||||
numsparearearead++;
|
||||
|
||||
NumSpareAreaToRead--;
|
||||
|
||||
/* Calculate page address */
|
||||
addressstatus = FSMC_NAND_AddressIncrement(&Address);
|
||||
}
|
||||
|
||||
status = FSMC_NAND_GetStatus();
|
||||
|
||||
return (status | addressstatus);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function Name : FSMC_NAND_EraseBlock
|
||||
* Description : This routine erase complete block from NAND FLASH
|
||||
* Input : - Address: Any address into block to be erased
|
||||
* Output : None
|
||||
* Return : New status of the NAND operation. This parameter can be:
|
||||
* - NAND_TIMEOUT_ERROR: when the previous operation generate
|
||||
* a Timeout error
|
||||
* - NAND_READY: when memory is ready for the next operation
|
||||
*******************************************************************************/
|
||||
uint32_t FSMC_NAND_EraseBlock(NAND_ADDRESS Address)
|
||||
{
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_ERASE0;
|
||||
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
|
||||
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_ERASE1;
|
||||
|
||||
return (FSMC_NAND_GetStatus());
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function Name : FSMC_NAND_Reset
|
||||
* Description : This routine reset the NAND FLASH
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : NAND_READY
|
||||
*******************************************************************************/
|
||||
uint32_t FSMC_NAND_Reset(void)
|
||||
{
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_RESET;
|
||||
|
||||
return (NAND_READY);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function Name : FSMC_NAND_GetStatus
|
||||
* Description : Get the NAND operation status
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : New status of the NAND operation. This parameter can be:
|
||||
* - NAND_TIMEOUT_ERROR: when the previous operation generate
|
||||
* a Timeout error
|
||||
* - NAND_READY: when memory is ready for the next operation
|
||||
*******************************************************************************/
|
||||
uint32_t FSMC_NAND_GetStatus(void)
|
||||
{
|
||||
uint32_t timeout = 0x1000000, status = NAND_READY;
|
||||
|
||||
status = FSMC_NAND_ReadStatus();
|
||||
|
||||
/* Wait for a NAND operation to complete or a TIMEOUT to occur */
|
||||
while ((status != NAND_READY) &&( timeout != 0x00))
|
||||
{
|
||||
status = FSMC_NAND_ReadStatus();
|
||||
timeout --;
|
||||
}
|
||||
|
||||
if(timeout == 0x00)
|
||||
{
|
||||
status = NAND_TIMEOUT_ERROR;
|
||||
}
|
||||
|
||||
/* Return the operation status */
|
||||
return (status);
|
||||
}
|
||||
/******************************************************************************
|
||||
* Function Name : FSMC_NAND_ReadStatus
|
||||
* Description : Reads the NAND memory status using the Read status command
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : The status of the NAND memory. This parameter can be:
|
||||
* - NAND_BUSY: when memory is busy
|
||||
* - NAND_READY: when memory is ready for the next operation
|
||||
* - NAND_ERROR: when the previous operation gererates error
|
||||
*******************************************************************************/
|
||||
uint32_t FSMC_NAND_ReadStatus(void)
|
||||
{
|
||||
uint32_t data = 0x00, status = NAND_BUSY;
|
||||
|
||||
/* Read status operation ------------------------------------ */
|
||||
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_STATUS;
|
||||
data = *(__IO uint8_t *)(Bank_NAND_ADDR);
|
||||
|
||||
if((data & NAND_ERROR) == NAND_ERROR)
|
||||
{
|
||||
status = NAND_ERROR;
|
||||
}
|
||||
else if((data & NAND_READY) == NAND_READY)
|
||||
{
|
||||
status = NAND_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = NAND_BUSY;
|
||||
}
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Function Name : NAND_AddressIncrement
|
||||
* Description : Increment the NAND memory address
|
||||
* Input : - Address: address to be incremented.
|
||||
* Output : None
|
||||
* Return : The new status of the increment address operation. It can be:
|
||||
* - NAND_VALID_ADDRESS: When the new address is valid address
|
||||
* - NAND_INVALID_ADDRESS: When the new address is invalid address
|
||||
*******************************************************************************/
|
||||
uint32_t FSMC_NAND_AddressIncrement(NAND_ADDRESS* Address)
|
||||
{
|
||||
uint32_t status = NAND_VALID_ADDRESS;
|
||||
|
||||
Address->Page++;
|
||||
|
||||
if(Address->Page == NAND_BLOCK_SIZE)
|
||||
{
|
||||
Address->Page = 0;
|
||||
Address->Block++;
|
||||
|
||||
if(Address->Block == NAND_ZONE_SIZE)
|
||||
{
|
||||
Address->Block = 0;
|
||||
Address->Zone++;
|
||||
|
||||
if(Address->Zone == NAND_MAX_ZONE)
|
||||
{
|
||||
status = NAND_INVALID_ADDRESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,256 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : hw_config.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.0.1
|
||||
* Date : 04/27/2009
|
||||
* Description : Hardware Configuration & Setup
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "hw_config.h"
|
||||
#include "platform_config.h"
|
||||
#include "mass_mal.h"
|
||||
#include "usb_desc.h"
|
||||
#include "usb_pwr.h"
|
||||
|
||||
void Set_System(void)
|
||||
{
|
||||
/* Enable and GPIOD clock */
|
||||
USB_Disconnect_Config();
|
||||
|
||||
/* MAL configuration */
|
||||
MAL_Config();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Set_USBClock
|
||||
* Description : Configures USB Clock input (48MHz)
|
||||
* Input : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Set_USBClock(void)
|
||||
{
|
||||
/* USBCLK = PLLCLK */
|
||||
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
|
||||
|
||||
/* Enable USB clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Enter_LowPowerMode
|
||||
* Description : Power-off system clocks and power while entering suspend mode
|
||||
* Input : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Enter_LowPowerMode(void)
|
||||
{
|
||||
/* Set the device state to suspend */
|
||||
bDeviceState = SUSPENDED;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Leave_LowPowerMode
|
||||
* Description : Restores system clocks and power while exiting suspend mode
|
||||
* Input : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Leave_LowPowerMode(void)
|
||||
{
|
||||
DEVICE_INFO *pInfo = &Device_Info;
|
||||
|
||||
/* Set the device state to the correct state */
|
||||
if (pInfo->Current_Configuration != 0)
|
||||
{
|
||||
/* Device configured */
|
||||
bDeviceState = CONFIGURED;
|
||||
}
|
||||
else
|
||||
{
|
||||
bDeviceState = ATTACHED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USB_Interrupts_Config
|
||||
* Description : Configures the USB interrupts
|
||||
* Input : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void USB_Interrupts_Config(void)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
#if 0
|
||||
NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
#endif /* USE_STM3210E_EVAL */
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Led_Config
|
||||
* Description : configure the Read/Write LEDs.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Led_Config(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Led_RW_ON
|
||||
* Description : Turn ON the Read/Write LEDs.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Led_RW_ON(void)
|
||||
{
|
||||
//GPIO_SetBits(USB_LED_PORT, GPIO_Pin_8);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Led_RW_OFF
|
||||
* Description : Turn off the Read/Write LEDs.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Led_RW_OFF(void)
|
||||
{
|
||||
//GPIO_ResetBits(USB_LED_PORT, GPIO_Pin_8);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : USB_Configured_LED
|
||||
* Description : Turn ON the Read/Write LEDs.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void USB_Configured_LED(void)
|
||||
{
|
||||
//GPIO_SetBits(USB_LED_PORT, GPIO_Pin_6);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USB_NotConfigured_LED
|
||||
* Description : Turn off the Read/Write LEDs.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void USB_NotConfigured_LED(void)
|
||||
{
|
||||
//GPIO_ResetBits(USB_LED_PORT, GPIO_Pin_6);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USB_Cable_Config
|
||||
* Description : Software Connection/Disconnection of USB Cable.
|
||||
* Input : None.
|
||||
* Return : Status
|
||||
*******************************************************************************/
|
||||
void USB_Cable_Config (FunctionalState NewState)
|
||||
{
|
||||
if (NewState != DISABLE)
|
||||
{
|
||||
GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Get_SerialNum.
|
||||
* Description : Create the serial number string descriptor.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Get_SerialNum(void)
|
||||
{
|
||||
uint32_t Device_Serial0, Device_Serial1, Device_Serial2;
|
||||
|
||||
Device_Serial0 = *(__IO uint32_t*)(0x1FFFF7E8);
|
||||
Device_Serial1 = *(__IO uint32_t*)(0x1FFFF7EC);
|
||||
Device_Serial2 = *(__IO uint32_t*)(0x1FFFF7F0);
|
||||
|
||||
if (Device_Serial0 != 0)
|
||||
{
|
||||
MASS_StringSerial[2] = (uint8_t)(Device_Serial0 & 0x000000FF);
|
||||
MASS_StringSerial[4] = (uint8_t)((Device_Serial0 & 0x0000FF00) >> 8);
|
||||
MASS_StringSerial[6] = (uint8_t)((Device_Serial0 & 0x00FF0000) >> 16);
|
||||
MASS_StringSerial[8] = (uint8_t)((Device_Serial0 & 0xFF000000) >> 24);
|
||||
|
||||
MASS_StringSerial[10] = (uint8_t)(Device_Serial1 & 0x000000FF);
|
||||
MASS_StringSerial[12] = (uint8_t)((Device_Serial1 & 0x0000FF00) >> 8);
|
||||
MASS_StringSerial[14] = (uint8_t)((Device_Serial1 & 0x00FF0000) >> 16);
|
||||
MASS_StringSerial[16] = (uint8_t)((Device_Serial1 & 0xFF000000) >> 24);
|
||||
|
||||
MASS_StringSerial[18] = (uint8_t)(Device_Serial2 & 0x000000FF);
|
||||
MASS_StringSerial[20] = (uint8_t)((Device_Serial2 & 0x0000FF00) >> 8);
|
||||
MASS_StringSerial[22] = (uint8_t)((Device_Serial2 & 0x00FF0000) >> 16);
|
||||
MASS_StringSerial[24] = (uint8_t)((Device_Serial2 & 0xFF000000) >> 24);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MAL_Config
|
||||
* Description : MAL_layer configuration
|
||||
* Input : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void MAL_Config(void)
|
||||
{
|
||||
MAL_Init(0);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USB_Disconnect_Config
|
||||
* Description : Disconnect pin configuration
|
||||
* Input : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void USB_Disconnect_Config(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_DISCONNECT, ENABLE);
|
||||
|
||||
/* config USB cable pin */
|
||||
GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,84 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : mass_mal.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.0.1
|
||||
* Date : 04/27/2009
|
||||
* Description : Medium Access Layer interface
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "platform_config.h"
|
||||
#include "sdcard.h"
|
||||
#include "mass_mal.h"
|
||||
#include "rtthread.h"
|
||||
|
||||
uint32_t Mass_Memory_Size[2];
|
||||
uint32_t Mass_Block_Size[2];
|
||||
uint32_t Mass_Block_Count[2];
|
||||
|
||||
rt_device_t dev_sdio = RT_NULL;
|
||||
|
||||
uint16_t MAL_Init(uint8_t lun)
|
||||
{
|
||||
uint16_t status = MAL_OK;
|
||||
|
||||
switch (lun)
|
||||
{
|
||||
case 0:
|
||||
status = MAL_OK;
|
||||
break;
|
||||
default:
|
||||
return MAL_FAIL;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
uint16_t MAL_Write(uint8_t lun, uint32_t Memory_Offset, uint32_t *Writebuff, uint16_t Transfer_Length)
|
||||
{
|
||||
|
||||
switch (lun)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
dev_sdio->write(dev_sdio,Memory_Offset,Writebuff,Transfer_Length);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return MAL_FAIL;
|
||||
}
|
||||
return MAL_OK;
|
||||
}
|
||||
|
||||
uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length)
|
||||
{
|
||||
|
||||
switch (lun)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
dev_sdio->read(dev_sdio,Memory_Offset,Readbuff,Transfer_Length);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return MAL_FAIL;
|
||||
}
|
||||
return MAL_OK;
|
||||
}
|
||||
|
||||
uint16_t MAL_GetStatus (uint8_t lun)
|
||||
{
|
||||
if(lun == 0)
|
||||
{
|
||||
return MAL_OK;
|
||||
}
|
||||
return MAL_FAIL;
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,168 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : memory.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Memory management layer
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "memory.h"
|
||||
#include "usb_scsi.h"
|
||||
#include "usb_bot.h"
|
||||
#include "usb_regs.h"
|
||||
#include "usb_mem.h"
|
||||
#include "usb_conf.h"
|
||||
#include "hw_config.h"
|
||||
#include "mass_mal.h"
|
||||
#include "usb_lib.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
__IO uint32_t Block_Read_count = 0;
|
||||
__IO uint32_t Block_offset;
|
||||
__IO uint32_t Counter = 0;
|
||||
uint32_t Idx;
|
||||
uint32_t Data_Buffer[BULK_MAX_PACKET_SIZE *2]; /* 512 bytes*/
|
||||
uint8_t TransferState = TXFR_IDLE;
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
extern uint8_t Bulk_Data_Buff[BULK_MAX_PACKET_SIZE]; /* data buffer*/
|
||||
extern uint16_t Data_Len;
|
||||
extern uint8_t Bot_State;
|
||||
extern Bulk_Only_CBW CBW;
|
||||
extern Bulk_Only_CSW CSW;
|
||||
extern uint32_t Mass_Memory_Size[2];
|
||||
extern uint32_t Mass_Block_Size[2];
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Extern function prototypes ------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Read_Memory
|
||||
* Description : Handle the Read operation from the microSD card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Read_Memory(uint8_t lun, uint32_t Memory_Offset, uint32_t Transfer_Length)
|
||||
{
|
||||
static uint32_t Offset, Length;
|
||||
|
||||
if (TransferState == TXFR_IDLE )
|
||||
{
|
||||
Offset = Memory_Offset * Mass_Block_Size[lun];
|
||||
Length = Transfer_Length * Mass_Block_Size[lun];
|
||||
TransferState = TXFR_ONGOING;
|
||||
}
|
||||
|
||||
if (TransferState == TXFR_ONGOING )
|
||||
{
|
||||
if (!Block_Read_count)
|
||||
{
|
||||
MAL_Read(lun ,
|
||||
Offset ,
|
||||
Data_Buffer,
|
||||
Mass_Block_Size[lun]);
|
||||
|
||||
USB_SIL_Write(EP1_IN, (uint8_t *)Data_Buffer, BULK_MAX_PACKET_SIZE);
|
||||
|
||||
Block_Read_count = Mass_Block_Size[lun] - BULK_MAX_PACKET_SIZE;
|
||||
Block_offset = BULK_MAX_PACKET_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
USB_SIL_Write(EP1_IN, (uint8_t *)Data_Buffer + Block_offset, BULK_MAX_PACKET_SIZE);
|
||||
|
||||
Block_Read_count -= BULK_MAX_PACKET_SIZE;
|
||||
Block_offset += BULK_MAX_PACKET_SIZE;
|
||||
}
|
||||
|
||||
SetEPTxCount(ENDP1, BULK_MAX_PACKET_SIZE);
|
||||
SetEPTxStatus(ENDP1, EP_TX_VALID);
|
||||
Offset += BULK_MAX_PACKET_SIZE;
|
||||
Length -= BULK_MAX_PACKET_SIZE;
|
||||
|
||||
CSW.dDataResidue -= BULK_MAX_PACKET_SIZE;
|
||||
Led_RW_ON();
|
||||
}
|
||||
if (Length == 0)
|
||||
{
|
||||
Block_Read_count = 0;
|
||||
Block_offset = 0;
|
||||
Offset = 0;
|
||||
Bot_State = BOT_DATA_IN_LAST;
|
||||
TransferState = TXFR_IDLE;
|
||||
Led_RW_OFF();
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Write_Memory
|
||||
* Description : Handle the Write operation to the microSD card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Write_Memory (uint8_t lun, uint32_t Memory_Offset, uint32_t Transfer_Length)
|
||||
{
|
||||
|
||||
static uint32_t W_Offset, W_Length;
|
||||
|
||||
uint32_t temp = Counter + 64;
|
||||
|
||||
if (TransferState == TXFR_IDLE )
|
||||
{
|
||||
W_Offset = Memory_Offset * Mass_Block_Size[lun];
|
||||
W_Length = Transfer_Length * Mass_Block_Size[lun];
|
||||
TransferState = TXFR_ONGOING;
|
||||
}
|
||||
|
||||
if (TransferState == TXFR_ONGOING )
|
||||
{
|
||||
|
||||
for (Idx = 0 ; Counter < temp; Counter++)
|
||||
{
|
||||
*((uint8_t *)Data_Buffer + Counter) = Bulk_Data_Buff[Idx++];
|
||||
}
|
||||
|
||||
W_Offset += Data_Len;
|
||||
W_Length -= Data_Len;
|
||||
|
||||
if (!(W_Length % Mass_Block_Size[lun]))
|
||||
{
|
||||
Counter = 0;
|
||||
MAL_Write(lun ,
|
||||
W_Offset - Mass_Block_Size[lun],
|
||||
Data_Buffer,
|
||||
Mass_Block_Size[lun]);
|
||||
}
|
||||
|
||||
CSW.dDataResidue -= Data_Len;
|
||||
#ifndef STM32F10X_CL
|
||||
SetEPRxStatus(ENDP2, EP_RX_VALID); /* enable the next transaction*/
|
||||
#endif /* STM32F10X_CL */
|
||||
|
||||
Led_RW_ON();
|
||||
}
|
||||
|
||||
if ((W_Length == 0) || (Bot_State == BOT_CSW_Send))
|
||||
{
|
||||
Counter = 0;
|
||||
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
||||
TransferState = TXFR_IDLE;
|
||||
Led_RW_OFF();
|
||||
}
|
||||
}
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,145 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : scsi_data.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.0.1
|
||||
* Date : 04/27/2009
|
||||
* Description : Initialization of the SCSI data
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_scsi.h"
|
||||
#include "memory.h"
|
||||
uint8_t Page00_Inquiry_Data[] =
|
||||
{
|
||||
0x00, /* PERIPHERAL QUALIFIER & PERIPHERAL DEVICE TYPE*/
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00 /* Supported Pages 00*/
|
||||
};
|
||||
uint8_t Standard_Inquiry_Data[] =
|
||||
{
|
||||
0x00, /* Direct Access Device */
|
||||
0x80, /* RMB = 1: Removable Medium */
|
||||
0x02, /* Version: No conformance claim to standard */
|
||||
0x02,
|
||||
|
||||
36 - 4, /* Additional Length */
|
||||
0x00, /* SCCS = 1: Storage Controller Component */
|
||||
0x00,
|
||||
0x00,
|
||||
/* Vendor Identification */
|
||||
'S', 'T', 'M', ' ', 'C', 'M', '-', '3',
|
||||
/* Product Identification */
|
||||
'S', 'D', ' ', 'F', 'l', 'a', 's', 'h', ' ',
|
||||
'D', 'i', 's', 'k', ' ', ' ', ' ',
|
||||
/* Product Revision Level */
|
||||
'1', '.', '0', ' '
|
||||
};
|
||||
uint8_t Standard_Inquiry_Data2[] =
|
||||
{
|
||||
0x00, /* Direct Access Device *///磁盘设备
|
||||
//其中最高位D7为RMB。RMB=0,表示不可移除设备。如果RMB=1,则为可移除设备。
|
||||
0x80, /* RMB = 1: Removable Medium */
|
||||
|
||||
0x02, /* Version: No conformance claim to standard */
|
||||
0x02, //数据响应格式
|
||||
|
||||
36 - 4, //附加数据长度,为31字节
|
||||
0x00, /* SCCS = 1: Storage Controller Component */
|
||||
0x00,
|
||||
0x00,
|
||||
/* Vendor Identification */
|
||||
'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ',
|
||||
/* Product Identification */
|
||||
'N', 'A', 'N', 'D', ' ', 'F', 'l', 'a', 's', 'h', ' ',
|
||||
'D', 'i', 's', 'k', ' ',
|
||||
/* Product Revision Level */
|
||||
'1', '.', '0', ' '
|
||||
};
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
uint8_t Mode_Sense6_data[] =
|
||||
{
|
||||
0x03,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
|
||||
uint8_t Mode_Sense10_data[] =
|
||||
{
|
||||
0x00,
|
||||
0x06,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00
|
||||
};
|
||||
uint8_t Scsi_Sense_Data[] =
|
||||
{
|
||||
0x70, /*RespCode*/
|
||||
0x00, /*SegmentNumber*/
|
||||
NO_SENSE, /* Sens_Key*/
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00, /*Information*/
|
||||
0x0A, /*AdditionalSenseLength*/
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00, /*CmdInformation*/
|
||||
NO_SENSE, /*Asc*/
|
||||
0x00, /*ASCQ*/
|
||||
0x00, /*FRUC*/
|
||||
0x00, /*TBD*/
|
||||
0x00,
|
||||
0x00 /*SenseKeySpecific*/
|
||||
};
|
||||
uint8_t ReadCapacity10_Data[] =
|
||||
{
|
||||
/* Last Logical Block */
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
||||
/* Block Length */
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
uint8_t ReadFormatCapacity_Data [] =
|
||||
{
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x08, /* Capacity List Length */
|
||||
|
||||
/* Block Count */
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
||||
/* Block Length */
|
||||
0x02,/* Descriptor Code: Formatted Media */
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,347 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_bot.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.0.1
|
||||
* Date : 04/27/2009
|
||||
* Description : BOT State Machine management
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_scsi.h"
|
||||
#include "hw_config.h"
|
||||
#include "usb_regs.h"
|
||||
#include "usb_mem.h"
|
||||
#include "usb_conf.h"
|
||||
#include "usb_bot.h"
|
||||
#include "memory.h"
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
uint8_t Bot_State;
|
||||
uint8_t Bulk_Data_Buff[BULK_MAX_PACKET_SIZE]; /* data buffer*/
|
||||
uint16_t Data_Len;
|
||||
Bulk_Only_CBW CBW;
|
||||
Bulk_Only_CSW CSW;
|
||||
uint32_t SCSI_LBA , SCSI_BlkLen;
|
||||
extern uint32_t Max_Lun;
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Extern function prototypes ------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Mass_Storage_In
|
||||
* Description : Mass Storage IN transfer.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Mass_Storage_In (void)
|
||||
{
|
||||
switch (Bot_State)
|
||||
{
|
||||
case BOT_CSW_Send:
|
||||
case BOT_ERROR:
|
||||
Bot_State = BOT_IDLE;
|
||||
SetEPRxStatus(ENDP2, EP_RX_VALID);/* enable the Endpoint to recive the next cmd*/
|
||||
break;
|
||||
case BOT_DATA_IN:
|
||||
switch (CBW.CB[0])
|
||||
{
|
||||
case SCSI_READ10:
|
||||
SCSI_Read10_Cmd(CBW.bLUN , SCSI_LBA , SCSI_BlkLen);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BOT_DATA_IN_LAST:
|
||||
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
||||
SetEPRxStatus(ENDP2, EP_RX_VALID);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Mass_Storage_Out
|
||||
* Description : Mass Storage OUT transfer.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Mass_Storage_Out (void)
|
||||
{
|
||||
uint8_t CMD;
|
||||
CMD = CBW.CB[0];//得到上一次的?
|
||||
//得到端点2接收到的数据长度
|
||||
Data_Len = GetEPRxCount(ENDP2);
|
||||
|
||||
//print(" MS_Out:");//print_dec(Data_Len);
|
||||
|
||||
//读出数据到 Bulk_Data_Buff
|
||||
PMAToUserBufferCopy(Bulk_Data_Buff, ENDP2_RXADDR, Data_Len);
|
||||
|
||||
switch (Bot_State)
|
||||
{
|
||||
case BOT_IDLE://空闲状态 进入CBW解码
|
||||
//print("BOT_IDLE");
|
||||
CBW_Decode();
|
||||
break;
|
||||
case BOT_DATA_OUT://数据输出状态
|
||||
//print("BOT_DATA_OUT");
|
||||
if (CMD == SCSI_WRITE10)
|
||||
{
|
||||
//print(" CMD == SCSI_WRITE10");
|
||||
SCSI_Write10_Cmd(CBW.bLUN , SCSI_LBA , SCSI_BlkLen);
|
||||
break;
|
||||
}
|
||||
Bot_Abort(DIR_OUT);
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
Set_CSW (CSW_PHASE_ERROR, SEND_CSW_DISABLE);
|
||||
break;
|
||||
default:
|
||||
Bot_Abort(BOTH_DIR);
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
Set_CSW (CSW_PHASE_ERROR, SEND_CSW_DISABLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : CBW_Decode
|
||||
* Description : Decode the received CBW and call the related SCSI command
|
||||
* routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void CBW_Decode(void)
|
||||
{
|
||||
uint32_t Counter;
|
||||
|
||||
//从Bulk_Data_Buff复制数据到CBW
|
||||
for (Counter = 0; Counter < Data_Len; Counter++)
|
||||
{
|
||||
*((uint8_t *)&CBW + Counter) = Bulk_Data_Buff[Counter];
|
||||
}
|
||||
//复制TAG用于返回
|
||||
CSW.dTag = CBW.dTag;
|
||||
CSW.dDataResidue = CBW.dDataLength;
|
||||
//如果数据长度不等于CBW的长度
|
||||
if (Data_Len != BOT_CBW_PACKET_LENGTH)
|
||||
{
|
||||
//print(" Data_Len != BOT_CBW_PACKET_LENGTH");
|
||||
Bot_Abort(BOTH_DIR);
|
||||
/* reset the CBW.dSignature to desible the clear feature until receiving a Mass storage reset*/
|
||||
CBW.dSignature = 0;
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, PARAMETER_LIST_LENGTH_ERROR);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
//读写数据
|
||||
if ((CBW.CB[0] == SCSI_READ10 ) || (CBW.CB[0] == SCSI_WRITE10 ))
|
||||
{
|
||||
/* Calculate Logical Block Address */
|
||||
//计算逻辑块地址 每个扇区512字节
|
||||
SCSI_LBA = (CBW.CB[2] << 24) | (CBW.CB[3] << 16) | (CBW.CB[4] << 8) | CBW.CB[5];
|
||||
/* Calculate the Number of Blocks to transfer */
|
||||
//计算传送的块大小 以扇区为单位?
|
||||
SCSI_BlkLen = (CBW.CB[7] << 8) | CBW.CB[8];
|
||||
}
|
||||
|
||||
//USBC
|
||||
if (CBW.dSignature == BOT_CBW_SIGNATURE)
|
||||
{
|
||||
/* Valid CBW */
|
||||
//有效但参数错误
|
||||
if ((CBW.bLUN > Max_Lun) || (CBW.bCBLength < 1) || (CBW.bCBLength > 16))
|
||||
{
|
||||
Bot_Abort(BOTH_DIR);
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (CBW.CB[0])
|
||||
{
|
||||
case SCSI_REQUEST_SENSE:
|
||||
SCSI_RequestSense_Cmd (CBW.bLUN);
|
||||
break;
|
||||
case SCSI_INQUIRY:
|
||||
SCSI_Inquiry_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_START_STOP_UNIT:
|
||||
SCSI_Start_Stop_Unit_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_ALLOW_MEDIUM_REMOVAL:
|
||||
SCSI_Start_Stop_Unit_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_MODE_SENSE6:
|
||||
SCSI_ModeSense6_Cmd (CBW.bLUN);
|
||||
break;
|
||||
case SCSI_MODE_SENSE10:
|
||||
SCSI_ModeSense10_Cmd (CBW.bLUN);
|
||||
break;
|
||||
case SCSI_READ_FORMAT_CAPACITIES:
|
||||
SCSI_ReadFormatCapacity_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_READ_CAPACITY10:
|
||||
SCSI_ReadCapacity10_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_TEST_UNIT_READY:
|
||||
SCSI_TestUnitReady_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_READ10:
|
||||
//读数据
|
||||
SCSI_Read10_Cmd(CBW.bLUN, SCSI_LBA , SCSI_BlkLen);
|
||||
break;
|
||||
case SCSI_WRITE10:
|
||||
//写数据
|
||||
SCSI_Write10_Cmd(CBW.bLUN, SCSI_LBA , SCSI_BlkLen);
|
||||
break;
|
||||
case SCSI_VERIFY10:
|
||||
SCSI_Verify10_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_FORMAT_UNIT:
|
||||
SCSI_Format_Cmd(CBW.bLUN);
|
||||
break;
|
||||
/*Unsupported command*/
|
||||
|
||||
case SCSI_MODE_SELECT10:
|
||||
SCSI_Mode_Select10_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_MODE_SELECT6:
|
||||
SCSI_Mode_Select6_Cmd(CBW.bLUN);
|
||||
break;
|
||||
|
||||
case SCSI_SEND_DIAGNOSTIC:
|
||||
SCSI_Send_Diagnostic_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_READ6:
|
||||
SCSI_Read6_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_READ12:
|
||||
SCSI_Read12_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_READ16:
|
||||
SCSI_Read16_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_READ_CAPACITY16:
|
||||
SCSI_READ_CAPACITY16_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_WRITE6:
|
||||
SCSI_Write6_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_WRITE12:
|
||||
SCSI_Write12_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_WRITE16:
|
||||
SCSI_Write16_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_VERIFY12:
|
||||
SCSI_Verify12_Cmd(CBW.bLUN);
|
||||
break;
|
||||
case SCSI_VERIFY16:
|
||||
SCSI_Verify16_Cmd(CBW.bLUN);
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
Bot_Abort(BOTH_DIR);
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//无效的CBW
|
||||
/* Invalid CBW */
|
||||
Bot_Abort(BOTH_DIR);
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Transfer_Data_Request
|
||||
* Description : Send the request response to the PC HOST.
|
||||
* Input : uint8_t* Data_Address : point to the data to transfer.
|
||||
* uint16_t Data_Length : the nember of Bytes to transfer.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Transfer_Data_Request(uint8_t* Data_Pointer, uint16_t Data_Len)
|
||||
{
|
||||
UserToPMABufferCopy(Data_Pointer, ENDP1_TXADDR, Data_Len);
|
||||
|
||||
SetEPTxCount(ENDP1, Data_Len);
|
||||
SetEPTxStatus(ENDP1, EP_TX_VALID);
|
||||
Bot_State = BOT_DATA_IN_LAST;
|
||||
CSW.dDataResidue -= Data_Len;
|
||||
CSW.bStatus = CSW_CMD_PASSED;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Set_CSW
|
||||
* Description : Set the SCW with the needed fields.
|
||||
* Input : uint8_t CSW_Status this filed can be CSW_CMD_PASSED,CSW_CMD_FAILED,
|
||||
* or CSW_PHASE_ERROR.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Set_CSW (uint8_t CSW_Status, uint8_t Send_Permission)
|
||||
{
|
||||
CSW.dSignature = BOT_CSW_SIGNATURE;
|
||||
CSW.bStatus = CSW_Status;
|
||||
|
||||
UserToPMABufferCopy(((uint8_t *)& CSW), ENDP1_TXADDR, CSW_DATA_LENGTH);
|
||||
|
||||
SetEPTxCount(ENDP1, CSW_DATA_LENGTH);
|
||||
Bot_State = BOT_ERROR;
|
||||
if (Send_Permission)
|
||||
{
|
||||
Bot_State = BOT_CSW_Send;
|
||||
SetEPTxStatus(ENDP1, EP_TX_VALID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Bot_Abort
|
||||
* Description : Stall the needed Endpoint according to the selected direction.
|
||||
* Input : Endpoint direction IN, OUT or both directions
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Bot_Abort(uint8_t Direction)
|
||||
{
|
||||
switch (Direction)
|
||||
{
|
||||
case DIR_IN :
|
||||
SetEPTxStatus(ENDP1, EP_TX_STALL);
|
||||
break;
|
||||
case DIR_OUT :
|
||||
SetEPRxStatus(ENDP2, EP_RX_STALL);
|
||||
break;
|
||||
case BOTH_DIR :
|
||||
SetEPTxStatus(ENDP1, EP_TX_STALL);
|
||||
SetEPRxStatus(ENDP2, EP_RX_STALL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,161 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_desc.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.0.1
|
||||
* Date : 04/27/2009
|
||||
* Description : Descriptors for Mass Storage Device
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_desc.h"
|
||||
|
||||
const uint8_t MASS_DeviceDescriptor[MASS_SIZ_DEVICE_DESC] =
|
||||
{
|
||||
0x12, /* bLength */
|
||||
0x01, /* bDescriptorType */
|
||||
0x00, /* bcdUSB, version 2.00 */
|
||||
0x02,
|
||||
0x00, /* bDeviceClass : each interface define the device class */
|
||||
0x00, /* bDeviceSubClass */
|
||||
0x00, /* bDeviceProtocol */
|
||||
0x40, /* bMaxPacketSize0 0x40 = 64 */
|
||||
0x83, /* idVendor (0483) */
|
||||
0x04,
|
||||
0x20, /* idProduct */
|
||||
0x57,
|
||||
0x00, /* bcdDevice 2.00*/
|
||||
0x02,
|
||||
1, /* index of string Manufacturer */
|
||||
/**/
|
||||
2, /* index of string descriptor of product*/
|
||||
/* */
|
||||
3, /* */
|
||||
/* */
|
||||
/* */
|
||||
0x01 /*bNumConfigurations */
|
||||
};
|
||||
|
||||
const uint8_t MASS_ConfigDescriptor[MASS_SIZ_CONFIG_DESC] =
|
||||
{
|
||||
|
||||
0x09, /* bLength: Configuation Descriptor size */
|
||||
0x02, /* bDescriptorType: Configuration */
|
||||
MASS_SIZ_CONFIG_DESC,
|
||||
|
||||
0x00,
|
||||
0x01, /* bNumInterfaces: 1 interface */
|
||||
0x01, /* bConfigurationValue: */
|
||||
/* Configuration value */
|
||||
0x00, /* iConfiguration: */
|
||||
/* Index of string descriptor */
|
||||
/* describing the configuration */
|
||||
0xC0, /* bmAttributes: */
|
||||
/* bus powered */
|
||||
100, /* MaxPower 100 mA */
|
||||
|
||||
/*****************接口描述符*******************/
|
||||
//bLength字段。接口描述符的长度为9字节。
|
||||
0x09,
|
||||
|
||||
//bDescriptorType字段。接口描述符的编号为0x04。
|
||||
0x04,
|
||||
|
||||
//bInterfaceNumber字段。该接口的编号,第一个接口,编号为0。
|
||||
0x00,
|
||||
|
||||
//bAlternateSetting字段。该接口的备用编号,为0。
|
||||
0x00,
|
||||
|
||||
//bNumEndpoints字段。非0端点的数目。该接口有2个批量端点
|
||||
0x02,
|
||||
|
||||
//bInterfaceClass字段。该接口所使用的类。大容量存储设备接口类的代码为0x08。
|
||||
0x08,
|
||||
|
||||
//bInterfaceSubClass字段。该接口所使用的子类。SCSI透明命令集的子类代码为0x06。
|
||||
0x06,
|
||||
|
||||
//bInterfaceProtocol字段。协议为仅批量传输,代码为0x50。
|
||||
0x50,
|
||||
|
||||
//iConfiguration字段。该接口的字符串索引值。
|
||||
4, /* iInterface: */
|
||||
|
||||
/*************标准批量数据输入端点描述符****************/
|
||||
/* 18 */
|
||||
0x07, /*Endpoint descriptor length = 7*/
|
||||
0x05, /*Endpoint descriptor type *///bDescriptorType字段。端点描述符编号为0x05。
|
||||
|
||||
//bEndpointAddress字段。端点的地址。我们使用D12的输入端点2。
|
||||
//D7位表示数据方向,输入端点D7为1。所以输入端点2的地址为0x82。
|
||||
0x81, /*Endpoint address (IN, address 1) */
|
||||
|
||||
//bmAttributes字段。D1~D0为端点传输类型选择。
|
||||
//该端点为批端点。批量端点的编号为2。其它位保留为0。
|
||||
0x02, /*Bulk endpoint type */
|
||||
|
||||
0x40, /*Maximum packet size (64 bytes) */
|
||||
0x00,
|
||||
0x00, /*Polling interval in milliseconds */
|
||||
|
||||
/*************标准批量数据输出端点描述符****************/
|
||||
/* 25 */
|
||||
0x07, /*Endpoint descriptor length = 7 */
|
||||
0x05, /*Endpoint descriptor type */
|
||||
0x02, /*Endpoint address (OUT, address 2) */
|
||||
0x02, /*Bulk endpoint type */
|
||||
0x40, /*Maximum packet size (64 bytes) */
|
||||
0x00,
|
||||
0x00 /*Polling interval in milliseconds*/
|
||||
/*32*/
|
||||
};
|
||||
const uint8_t MASS_StringLangID[MASS_SIZ_STRING_LANGID] =
|
||||
{
|
||||
MASS_SIZ_STRING_LANGID,
|
||||
0x03,
|
||||
0x09,
|
||||
0x04
|
||||
}
|
||||
; /* LangID = 0x0409: U.S. English */
|
||||
const uint8_t MASS_StringVendor[MASS_SIZ_STRING_VENDOR] =
|
||||
{
|
||||
MASS_SIZ_STRING_VENDOR, /* Size of manufaturer string */
|
||||
0x03, /* bDescriptorType = String descriptor */
|
||||
/* Manufacturer: "STMicroelectronics" */
|
||||
'S', 0, 'T', 0, 'M', 0, 'i', 0, 'c', 0, 'r', 0, 'o', 0, 'e', 0,
|
||||
'l', 0, 'e', 0, 'c', 0, 't', 0, 'r', 0, 'o', 0, 'n', 0, 'i', 0,
|
||||
'c', 0, 's', 0
|
||||
};
|
||||
const uint8_t MASS_StringProduct[MASS_SIZ_STRING_PRODUCT] =
|
||||
{
|
||||
MASS_SIZ_STRING_PRODUCT,
|
||||
0x03,
|
||||
/* Product name: "STM32F10x:USB Mass Storage" */
|
||||
'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0, ' ', 0, 'M', 0, 'a', 0, 's', 0,
|
||||
's', 0, ' ', 0, 'S', 0, 't', 0, 'o', 0, 'r', 0, 'a', 0, 'g', 0, 'e', 0
|
||||
|
||||
};
|
||||
|
||||
uint8_t MASS_StringSerial[MASS_SIZ_STRING_SERIAL] =
|
||||
{
|
||||
MASS_SIZ_STRING_SERIAL,
|
||||
0x03,
|
||||
/* STM3210 */
|
||||
'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0, '1', 0, '0', 0
|
||||
};
|
||||
const uint8_t MASS_StringInterface[MASS_SIZ_STRING_INTERFACE] =
|
||||
{
|
||||
MASS_SIZ_STRING_INTERFACE,
|
||||
0x03,
|
||||
/* Interface 0: "ST Mass" */
|
||||
'S', 0, 'T', 0, ' ', 0, 'M', 0, 'a', 0, 's', 0, 's', 0
|
||||
};
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,55 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_endp.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.0.1
|
||||
* Date : 04/27/2009
|
||||
* Description : Endpoint routines
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_lib.h"
|
||||
#include "usb_bot.h"
|
||||
#include "usb_istr.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EP1_IN_Callback
|
||||
* Description : EP1 IN Callback Routine
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void EP1_IN_Callback(void)
|
||||
{
|
||||
// IN
|
||||
Mass_Storage_In();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EP2_OUT_Callback.
|
||||
* Description : EP2 OUT Callback Routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void EP2_OUT_Callback(void)
|
||||
{
|
||||
// OUT 收到主机发来的数据或命令
|
||||
Mass_Storage_Out();
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_istr.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.0.1
|
||||
* Date : 04/27/2009
|
||||
* Description : ISTR events interrupt service routines
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x.h"
|
||||
#include "usb_type.h"
|
||||
#include "usb_regs.h"
|
||||
#include "usb_pwr.h"
|
||||
#include "usb_istr.h"
|
||||
#include "usb_init.h"
|
||||
#include "usb_int.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 */
|
||||
|
||||
/* 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)
|
||||
{
|
||||
|
||||
wIstr = _GetISTR();
|
||||
|
||||
#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_SOF)
|
||||
if (wIstr & ISTR_SOF & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_SOF);
|
||||
bIntPackSOF++;
|
||||
|
||||
#ifdef SOF_CALLBACK
|
||||
SOF_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
#if (IMR_MSK & ISTR_ESOF)
|
||||
if (wIstr & ISTR_ESOF & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_ESOF);
|
||||
/* resume handling timing is made with ESOFs */
|
||||
Resume(RESUME_ESOF); /* request without change of the machine state */
|
||||
|
||||
#ifdef ESOF_CALLBACK
|
||||
ESOF_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
|
||||
} /* USB_Istr */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "stm32f10x.h"
|
||||
#include "usb_lib.h"
|
||||
#include "usb_istr.h"
|
||||
#include "hw_config.h"
|
||||
#include "usb_pwr.h"
|
||||
|
||||
#include "rtthread.h"
|
||||
|
||||
extern uint32_t Mass_Memory_Size[2];
|
||||
extern uint32_t Mass_Block_Size[2];
|
||||
extern uint32_t Mass_Block_Count[2];
|
||||
extern rt_device_t dev_sdio;
|
||||
|
||||
#include <finsh.h>
|
||||
#include "sdcard.h"
|
||||
void USB_cable(void)
|
||||
{
|
||||
rt_device_t dev = RT_NULL;
|
||||
SD_CardInfo * sdio_info = RT_NULL;
|
||||
dev = rt_device_find("sd0");
|
||||
if(dev != RT_NULL)
|
||||
{
|
||||
dev_sdio = dev;
|
||||
sdio_info = (SD_CardInfo *)dev->private;
|
||||
Mass_Memory_Size[0] = sdio_info->CardCapacity;
|
||||
Mass_Block_Size[0] = sdio_info->CardBlockSize;
|
||||
Mass_Block_Count[0] = Mass_Memory_Size[0] / Mass_Block_Size[0];
|
||||
|
||||
Set_System();
|
||||
Set_USBClock();
|
||||
USB_Interrupts_Config();
|
||||
USB_Init();
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("\r\nNo find the device sd0 !!!!");
|
||||
}
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(USB_cable, cable_the_usb);
|
||||
@@ -0,0 +1,402 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_prop.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.0.1
|
||||
* Date : 04/27/2009
|
||||
* Description : All processing related to Mass Storage Demo
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_lib.h"
|
||||
#include "usb_desc.h"
|
||||
#include "usb_pwr.h"
|
||||
#include "usb_bot.h"
|
||||
#include "hw_config.h"
|
||||
#include "memory.h"
|
||||
#include "mass_mal.h"
|
||||
#include "usb_prop.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
#ifdef USE_STM3210B_EVAL
|
||||
uint32_t Max_Lun = 0;
|
||||
#else //USE_STM3210E_EVAL
|
||||
uint32_t Max_Lun = 1;
|
||||
#endif
|
||||
|
||||
DEVICE Device_Table =
|
||||
{
|
||||
EP_NUM,
|
||||
1
|
||||
};
|
||||
|
||||
DEVICE_PROP Device_Property =
|
||||
{
|
||||
MASS_init,
|
||||
MASS_Reset,
|
||||
MASS_Status_In,
|
||||
MASS_Status_Out,
|
||||
MASS_Data_Setup,
|
||||
MASS_NoData_Setup,
|
||||
MASS_Get_Interface_Setting,
|
||||
MASS_GetDeviceDescriptor,
|
||||
MASS_GetConfigDescriptor,
|
||||
MASS_GetStringDescriptor,
|
||||
0,
|
||||
0x40 /*MAX PACKET SIZE*/
|
||||
};
|
||||
|
||||
USER_STANDARD_REQUESTS User_Standard_Requests =
|
||||
{
|
||||
Mass_Storage_GetConfiguration,
|
||||
Mass_Storage_SetConfiguration,
|
||||
Mass_Storage_GetInterface,
|
||||
Mass_Storage_SetInterface,
|
||||
Mass_Storage_GetStatus,
|
||||
Mass_Storage_ClearFeature,
|
||||
Mass_Storage_SetEndPointFeature,
|
||||
Mass_Storage_SetDeviceFeature,
|
||||
Mass_Storage_SetDeviceAddress
|
||||
};
|
||||
|
||||
ONE_DESCRIPTOR Device_Descriptor =
|
||||
{
|
||||
(uint8_t*)MASS_DeviceDescriptor,
|
||||
MASS_SIZ_DEVICE_DESC
|
||||
};
|
||||
|
||||
ONE_DESCRIPTOR Config_Descriptor =
|
||||
{
|
||||
(uint8_t*)MASS_ConfigDescriptor,
|
||||
MASS_SIZ_CONFIG_DESC
|
||||
};
|
||||
|
||||
ONE_DESCRIPTOR String_Descriptor[5] =
|
||||
{
|
||||
{(uint8_t*)MASS_StringLangID, MASS_SIZ_STRING_LANGID},
|
||||
{(uint8_t*)MASS_StringVendor, MASS_SIZ_STRING_VENDOR},
|
||||
{(uint8_t*)MASS_StringProduct, MASS_SIZ_STRING_PRODUCT},
|
||||
{(uint8_t*)MASS_StringSerial, MASS_SIZ_STRING_SERIAL},
|
||||
{(uint8_t*)MASS_StringInterface, MASS_SIZ_STRING_INTERFACE},
|
||||
};
|
||||
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
extern unsigned char Bot_State;
|
||||
extern Bulk_Only_CBW CBW;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Extern function prototypes ------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/*******************************************************************************
|
||||
* Function Name : MASS_init
|
||||
* Description : Mass Storage init routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void MASS_init()
|
||||
{
|
||||
/* Update the serial number string descriptor with the data from the unique
|
||||
ID*/
|
||||
Get_SerialNum();
|
||||
|
||||
pInformation->Current_Configuration = 0;
|
||||
|
||||
/* Connect the device */
|
||||
PowerOn();
|
||||
|
||||
/* USB interrupts initialization */
|
||||
/* clear pending interrupts */
|
||||
_SetISTR(0);
|
||||
wInterrupt_Mask = IMR_MSK;
|
||||
/* set interrupts mask */
|
||||
_SetCNTR(wInterrupt_Mask);
|
||||
|
||||
bDeviceState = UNCONNECTED;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MASS_Reset
|
||||
* Description : Mass Storage reset routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void MASS_Reset()
|
||||
{
|
||||
/* Set the device as not configured */
|
||||
Device_Info.Current_Configuration = 0;
|
||||
|
||||
/* Current Feature initialization */
|
||||
pInformation->Current_Feature = MASS_ConfigDescriptor[7];
|
||||
|
||||
SetBTABLE(BTABLE_ADDRESS);
|
||||
|
||||
/* Initialize Endpoint 0 */
|
||||
SetEPType(ENDP0, EP_CONTROL);
|
||||
SetEPTxStatus(ENDP0, EP_TX_NAK);
|
||||
SetEPRxAddr(ENDP0, ENDP0_RXADDR);
|
||||
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
|
||||
SetEPTxAddr(ENDP0, ENDP0_TXADDR);
|
||||
Clear_Status_Out(ENDP0);
|
||||
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_BULK);
|
||||
SetEPRxAddr(ENDP2, ENDP2_RXADDR);
|
||||
SetEPRxCount(ENDP2, Device_Property.MaxPacketSize);
|
||||
SetEPRxStatus(ENDP2, EP_RX_VALID);
|
||||
SetEPTxStatus(ENDP2, EP_TX_DIS);
|
||||
|
||||
|
||||
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
|
||||
SetEPRxValid(ENDP0);
|
||||
|
||||
/* Set the device to response on default address */
|
||||
SetDeviceAddress(0);
|
||||
|
||||
bDeviceState = ATTACHED;
|
||||
|
||||
CBW.dSignature = BOT_CBW_SIGNATURE;
|
||||
Bot_State = BOT_IDLE;
|
||||
//USB_NotConfigured_LED();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Mass_Storage_SetConfiguration
|
||||
* Description : Handle the SetConfiguration request.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Mass_Storage_SetConfiguration(void)
|
||||
{
|
||||
if (pInformation->Current_Configuration != 0)
|
||||
{
|
||||
/* Device configured */
|
||||
bDeviceState = CONFIGURED;
|
||||
|
||||
ClearDTOG_TX(ENDP1);
|
||||
ClearDTOG_RX(ENDP2);
|
||||
Bot_State = BOT_IDLE; /* set the Bot state machine to the IDLE state */
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Mass_Storage_ClearFeature
|
||||
* Description : Handle the ClearFeature request.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Mass_Storage_ClearFeature(void)
|
||||
{
|
||||
/* when the host send a CBW with invalid signature or invalid length the two
|
||||
Endpoints (IN & OUT) shall stall until receiving a Mass Storage Reset */
|
||||
if (CBW.dSignature != BOT_CBW_SIGNATURE)
|
||||
Bot_Abort(BOTH_DIR);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Mass_Storage_SetConfiguration.
|
||||
* Description : Udpade the device state to addressed.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Mass_Storage_SetDeviceAddress (void)
|
||||
{
|
||||
bDeviceState = ADDRESSED;
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : MASS_Status_In
|
||||
* Description : Mass Storage Status IN routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void MASS_Status_In(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MASS_Status_Out
|
||||
* Description : Mass Storage Status OUT routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void MASS_Status_Out(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MASS_Data_Setup.
|
||||
* Description : Handle the data class specific requests..
|
||||
* Input : RequestNo.
|
||||
* Output : None.
|
||||
* Return : RESULT.
|
||||
*******************************************************************************/
|
||||
RESULT MASS_Data_Setup(uint8_t RequestNo)
|
||||
{
|
||||
uint8_t *(*CopyRoutine)(uint16_t);
|
||||
|
||||
//print("MASS_Data_Setup");
|
||||
CopyRoutine = NULL;
|
||||
if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||
&& (RequestNo == GET_MAX_LUN) && (pInformation->USBwValue == 0)
|
||||
&& (pInformation->USBwIndex == 0) && (pInformation->USBwLength == 0x01))
|
||||
{
|
||||
//print(" Get_Max_Lun\r\n");
|
||||
CopyRoutine = Get_Max_Lun;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
if (CopyRoutine == NULL)
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
pInformation->Ctrl_Info.CopyData = CopyRoutine;
|
||||
pInformation->Ctrl_Info.Usb_wOffset = 0;
|
||||
(*CopyRoutine)(0);
|
||||
|
||||
return USB_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MASS_NoData_Setup.
|
||||
* Description : Handle the no data class specific requests.
|
||||
* Input : RequestNo.
|
||||
* Output : None.
|
||||
* Return : RESULT.
|
||||
*******************************************************************************/
|
||||
RESULT MASS_NoData_Setup(uint8_t RequestNo)
|
||||
{
|
||||
if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||
&& (RequestNo == MASS_STORAGE_RESET) && (pInformation->USBwValue == 0)
|
||||
&& (pInformation->USBwIndex == 0) && (pInformation->USBwLength == 0x00))
|
||||
{
|
||||
/* Initialize Endpoint 1 */
|
||||
ClearDTOG_TX(ENDP1);
|
||||
|
||||
/* Initialize Endpoint 2 */
|
||||
ClearDTOG_RX(ENDP2);
|
||||
|
||||
/*intialise the CBW signature to enable the clear feature*/
|
||||
CBW.dSignature = BOT_CBW_SIGNATURE;
|
||||
Bot_State = BOT_IDLE;
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MASS_Get_Interface_Setting
|
||||
* Description : Test the interface and the alternate setting according to the
|
||||
* supported one.
|
||||
* Input : uint8_t Interface, uint8_t AlternateSetting.
|
||||
* Output : None.
|
||||
* Return : RESULT.
|
||||
*******************************************************************************/
|
||||
RESULT MASS_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting)
|
||||
{
|
||||
if (AlternateSetting > 0)
|
||||
{
|
||||
return USB_UNSUPPORT;/* in this application we don't have AlternateSetting*/
|
||||
}
|
||||
else if (Interface > 0)
|
||||
{
|
||||
return USB_UNSUPPORT;/*in this application we have only 1 interfaces*/
|
||||
}
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MASS_GetDeviceDescriptor
|
||||
* Description : Get the device descriptor.
|
||||
* Input : uint16_t Length.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
uint8_t *MASS_GetDeviceDescriptor(uint16_t Length)
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &Device_Descriptor );
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MASS_GetConfigDescriptor
|
||||
* Description : Get the configuration descriptor.
|
||||
* Input : uint16_t Length.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
uint8_t *MASS_GetConfigDescriptor(uint16_t Length)
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &Config_Descriptor );
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MASS_GetStringDescriptor
|
||||
* Description : Get the string descriptors according to the needed index.
|
||||
* Input : uint16_t Length.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
uint8_t *MASS_GetStringDescriptor(uint16_t Length)
|
||||
{
|
||||
uint8_t wValue0 = pInformation->USBwValue0;
|
||||
|
||||
if (wValue0 > 5)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Get_Max_Lun
|
||||
* Description : Handle the Get Max Lun request.
|
||||
* Input : uint16_t Length.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
uint8_t *Get_Max_Lun(uint16_t Length)
|
||||
{
|
||||
if (Length == 0)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wLength = LUN_DATA_LENGTH;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return((uint8_t*)(&Max_Lun));
|
||||
}
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,224 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_pwr.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.0.1
|
||||
* Date : 04/27/2009
|
||||
* Description : Connection/disconnection & power management
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x.h"
|
||||
#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 */
|
||||
|
||||
struct
|
||||
{
|
||||
__IO RESUME_STATE eState;
|
||||
__IO uint8_t bESOFcnt;
|
||||
}
|
||||
ResumeS;
|
||||
|
||||
/* 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 ? ***/
|
||||
/*while(!CablePluggedIn());*/
|
||||
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 ints 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)
|
||||
{
|
||||
uint16_t wCNTR;
|
||||
/* suspend preparation */
|
||||
/* ... */
|
||||
|
||||
/* macrocell enters suspend mode */
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR |= CNTR_FSUSP;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/* ------------------ ONLY WITH BUS-POWERED DEVICES ---------------------- */
|
||||
/* power reduction */
|
||||
/* ... on connected devices */
|
||||
|
||||
|
||||
/* force low-power mode in the macrocell */
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR |= CNTR_LPMODE;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
/* switch-off the clocks */
|
||||
/* ... */
|
||||
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:
|
||||
Resume_Init();
|
||||
ResumeS.eState = RESUME_OFF;
|
||||
break;
|
||||
case RESUME_INTERNAL:
|
||||
Resume_Init();
|
||||
ResumeS.eState = RESUME_START;
|
||||
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;
|
||||
}
|
||||
break;
|
||||
case RESUME_OFF:
|
||||
case RESUME_ESOF:
|
||||
default:
|
||||
ResumeS.eState = RESUME_OFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,433 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_scsi.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.0.1
|
||||
* Date : 04/27/2009
|
||||
* Description : All processing related to the SCSI commands
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "hw_config.h"
|
||||
#include "usb_scsi.h"
|
||||
#include "mass_mal.h"
|
||||
#include "usb_bot.h"
|
||||
#include "usb_regs.h"
|
||||
#include "memory.h"
|
||||
#include "nand_if.h"
|
||||
#include "platform_config.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern uint8_t Bulk_Data_Buff[BULK_MAX_PACKET_SIZE]; /* data buffer*/
|
||||
extern uint8_t Bot_State;
|
||||
extern Bulk_Only_CBW CBW;
|
||||
extern Bulk_Only_CSW CSW;
|
||||
extern uint32_t Mass_Memory_Size[2];
|
||||
extern uint32_t Mass_Block_Size[2];
|
||||
extern uint32_t Mass_Block_Count[2];
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_Inquiry_Cmd
|
||||
* Description : SCSI Inquiry Command routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_Inquiry_Cmd(uint8_t lun)
|
||||
{
|
||||
uint8_t* Inquiry_Data;
|
||||
uint16_t Inquiry_Data_Length;
|
||||
|
||||
if (CBW.CB[1] & 0x01)/*Evpd is set*/
|
||||
{
|
||||
Inquiry_Data = Page00_Inquiry_Data;
|
||||
Inquiry_Data_Length = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if ( lun == 0)
|
||||
{
|
||||
Inquiry_Data = Standard_Inquiry_Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
Inquiry_Data = Standard_Inquiry_Data2;
|
||||
}
|
||||
|
||||
if (CBW.CB[4] <= STANDARD_INQUIRY_DATA_LEN)
|
||||
Inquiry_Data_Length = CBW.CB[4];
|
||||
else
|
||||
Inquiry_Data_Length = STANDARD_INQUIRY_DATA_LEN;
|
||||
|
||||
}
|
||||
Transfer_Data_Request(Inquiry_Data, Inquiry_Data_Length);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_ReadFormatCapacity_Cmd
|
||||
* Description : SCSI ReadFormatCapacity Command routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_ReadFormatCapacity_Cmd(uint8_t lun)
|
||||
{
|
||||
|
||||
if (MAL_GetStatus(lun) != 0 )
|
||||
{
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
||||
Bot_Abort(DIR_IN);
|
||||
return;
|
||||
}
|
||||
ReadFormatCapacity_Data[4] = (uint8_t)(Mass_Block_Count[lun] >> 24);
|
||||
ReadFormatCapacity_Data[5] = (uint8_t)(Mass_Block_Count[lun] >> 16);
|
||||
ReadFormatCapacity_Data[6] = (uint8_t)(Mass_Block_Count[lun] >> 8);
|
||||
ReadFormatCapacity_Data[7] = (uint8_t)(Mass_Block_Count[lun]);
|
||||
|
||||
ReadFormatCapacity_Data[9] = (uint8_t)(Mass_Block_Size[lun] >> 16);
|
||||
ReadFormatCapacity_Data[10] = (uint8_t)(Mass_Block_Size[lun] >> 8);
|
||||
ReadFormatCapacity_Data[11] = (uint8_t)(Mass_Block_Size[lun]);
|
||||
Transfer_Data_Request(ReadFormatCapacity_Data, READ_FORMAT_CAPACITY_DATA_LEN);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_ReadCapacity10_Cmd
|
||||
* Description : SCSI ReadCapacity10 Command routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_ReadCapacity10_Cmd(uint8_t lun)
|
||||
{
|
||||
|
||||
if (MAL_GetStatus(lun))
|
||||
{
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
||||
Bot_Abort(DIR_IN);
|
||||
return;
|
||||
}
|
||||
|
||||
ReadCapacity10_Data[0] = (uint8_t)(Mass_Block_Count[lun] - 1 >> 24);
|
||||
ReadCapacity10_Data[1] = (uint8_t)(Mass_Block_Count[lun] - 1 >> 16);
|
||||
ReadCapacity10_Data[2] = (uint8_t)(Mass_Block_Count[lun] - 1 >> 8);
|
||||
ReadCapacity10_Data[3] = (uint8_t)(Mass_Block_Count[lun] - 1);
|
||||
|
||||
ReadCapacity10_Data[4] = (uint8_t)(Mass_Block_Size[lun] >> 24);
|
||||
ReadCapacity10_Data[5] = (uint8_t)(Mass_Block_Size[lun] >> 16);
|
||||
ReadCapacity10_Data[6] = (uint8_t)(Mass_Block_Size[lun] >> 8);
|
||||
ReadCapacity10_Data[7] = (uint8_t)(Mass_Block_Size[lun]);
|
||||
Transfer_Data_Request(ReadCapacity10_Data, READ_CAPACITY10_DATA_LEN);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_ModeSense6_Cmd
|
||||
* Description : SCSI ModeSense6 Command routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_ModeSense6_Cmd (uint8_t lun)
|
||||
{
|
||||
Transfer_Data_Request(Mode_Sense6_data, MODE_SENSE6_DATA_LEN);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_ModeSense10_Cmd
|
||||
* Description : SCSI ModeSense10 Command routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_ModeSense10_Cmd (uint8_t lun)
|
||||
{
|
||||
Transfer_Data_Request(Mode_Sense10_data, MODE_SENSE10_DATA_LEN);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_RequestSense_Cmd
|
||||
* Description : SCSI RequestSense Command routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_RequestSense_Cmd (uint8_t lun)
|
||||
{
|
||||
uint8_t Request_Sense_data_Length;
|
||||
|
||||
if (CBW.CB[4] <= REQUEST_SENSE_DATA_LEN)
|
||||
{
|
||||
Request_Sense_data_Length = CBW.CB[4];
|
||||
}
|
||||
else
|
||||
{
|
||||
Request_Sense_data_Length = REQUEST_SENSE_DATA_LEN;
|
||||
}
|
||||
Transfer_Data_Request(Scsi_Sense_Data, Request_Sense_data_Length);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Set_Scsi_Sense_Data
|
||||
* Description : Set Scsi Sense Data routine.
|
||||
* Input : uint8_t Sens_Key
|
||||
uint8_t Asc.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void Set_Scsi_Sense_Data(uint8_t lun, uint8_t Sens_Key, uint8_t Asc)
|
||||
{
|
||||
Scsi_Sense_Data[2] = Sens_Key;
|
||||
Scsi_Sense_Data[12] = Asc;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_Start_Stop_Unit_Cmd
|
||||
* Description : SCSI Start_Stop_Unit Command routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_Start_Stop_Unit_Cmd(uint8_t lun)
|
||||
{
|
||||
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_Read10_Cmd
|
||||
* Description : SCSI Read10 Command routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_Read10_Cmd(uint8_t lun , uint32_t LBA , uint32_t BlockNbr)
|
||||
{
|
||||
|
||||
if (Bot_State == BOT_IDLE)
|
||||
{
|
||||
/*address out of range*/
|
||||
if (!(SCSI_Address_Management(CBW.bLUN, SCSI_READ10, LBA, BlockNbr)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((CBW.bmFlags & 0x80) != 0)
|
||||
{
|
||||
Bot_State = BOT_DATA_IN;
|
||||
Read_Memory(lun, LBA , BlockNbr);
|
||||
}
|
||||
else
|
||||
{
|
||||
Bot_Abort(BOTH_DIR);
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (Bot_State == BOT_DATA_IN)
|
||||
{
|
||||
Read_Memory(lun , LBA , BlockNbr);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_Write10_Cmd
|
||||
* Description : SCSI Write10 Command routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_Write10_Cmd(uint8_t lun , uint32_t LBA , uint32_t BlockNbr)
|
||||
{
|
||||
|
||||
if (Bot_State == BOT_IDLE)
|
||||
{
|
||||
if (!(SCSI_Address_Management(CBW.bLUN, SCSI_WRITE10 , LBA, BlockNbr)))/*address out of range*/
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((CBW.bmFlags & 0x80) == 0)
|
||||
{
|
||||
Bot_State = BOT_DATA_OUT;
|
||||
SetEPRxStatus(ENDP2, EP_RX_VALID);
|
||||
}
|
||||
else
|
||||
{
|
||||
Bot_Abort(DIR_IN);
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (Bot_State == BOT_DATA_OUT)
|
||||
{
|
||||
Write_Memory(lun , LBA , BlockNbr);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_Verify10_Cmd
|
||||
* Description : SCSI Verify10 Command routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_Verify10_Cmd(uint8_t lun)
|
||||
{
|
||||
if ((CBW.dDataLength == 0) && !(CBW.CB[1] & BLKVFY))/* BLKVFY not set*/
|
||||
{
|
||||
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
Bot_Abort(BOTH_DIR);
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||
}
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_Valid_Cmd
|
||||
* Description : Valid Commands routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_Valid_Cmd(uint8_t lun)
|
||||
{
|
||||
if (CBW.dDataLength != 0)
|
||||
{
|
||||
Bot_Abort(BOTH_DIR);
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||
}
|
||||
else
|
||||
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_Valid_Cmd
|
||||
* Description : Valid Commands routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_TestUnitReady_Cmd(uint8_t lun)
|
||||
{
|
||||
if (MAL_GetStatus(lun))
|
||||
{
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
||||
Bot_Abort(DIR_IN);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
||||
}
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_Format_Cmd
|
||||
* Description : Format Commands routine.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_Format_Cmd(uint8_t lun)
|
||||
{
|
||||
if (MAL_GetStatus(lun))
|
||||
{
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_ENABLE);
|
||||
Bot_Abort(DIR_IN);
|
||||
return;
|
||||
}
|
||||
#ifdef USE_STM3210E_EVAL
|
||||
else
|
||||
{
|
||||
//NAND_Format();
|
||||
Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_Invalid_Cmd
|
||||
* Description : Invalid Commands routine
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void SCSI_Invalid_Cmd(uint8_t lun)
|
||||
{
|
||||
if (CBW.dDataLength == 0)
|
||||
{
|
||||
Bot_Abort(DIR_IN);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((CBW.bmFlags & 0x80) != 0)
|
||||
{
|
||||
Bot_Abort(DIR_IN);
|
||||
}
|
||||
else
|
||||
{
|
||||
Bot_Abort(BOTH_DIR);
|
||||
}
|
||||
}
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SCSI_Address_Management
|
||||
* Description : Test the received address.
|
||||
* Input : uint8_t Cmd : the command can be SCSI_READ10 or SCSI_WRITE10.
|
||||
* Output : None.
|
||||
* Return : Read\Write status (bool).
|
||||
*******************************************************************************/
|
||||
bool SCSI_Address_Management(uint8_t lun , uint8_t Cmd , uint32_t LBA , uint32_t BlockNbr)
|
||||
{
|
||||
|
||||
if ((LBA + BlockNbr) > Mass_Block_Count[lun] )
|
||||
{
|
||||
if (Cmd == SCSI_WRITE10)
|
||||
{
|
||||
Bot_Abort(BOTH_DIR);
|
||||
}
|
||||
Bot_Abort(DIR_IN);
|
||||
Set_Scsi_Sense_Data(lun, ILLEGAL_REQUEST, ADDRESS_OUT_OF_RANGE);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
|
||||
if (CBW.dDataLength != BlockNbr * Mass_Block_Size[lun])
|
||||
{
|
||||
if (Cmd == SCSI_WRITE10)
|
||||
{
|
||||
Bot_Abort(BOTH_DIR);
|
||||
}
|
||||
else
|
||||
{
|
||||
Bot_Abort(DIR_IN);
|
||||
}
|
||||
Set_Scsi_Sense_Data(CBW.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,259 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : otgd_fs_cal.h
|
||||
* Author : STMicroelectronics
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Header of OTG FS Device Core Access Layer interface.
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
#ifndef __OTG_CORE_H__
|
||||
#define __OTG_CORE_H__
|
||||
|
||||
#ifdef STM32F10X_CL
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "usb_type.h"
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#define __packed __packed /*!< packing keyword for ARM Compiler */
|
||||
|
||||
#elif defined ( __ICCARM__ )
|
||||
#define __packed __packed /*!< packing keyword for IAR Compiler */
|
||||
|
||||
#elif defined ( __GNUC__ )
|
||||
#define __packed __attribute__ ((__packed__)) /*!< packing keyword for GNU Compiler */
|
||||
|
||||
#endif /* __CC_ARM */
|
||||
|
||||
/*******************************************************************************
|
||||
define and types
|
||||
*******************************************************************************/
|
||||
|
||||
#define DEVICE_MODE_ENABLED
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
|
||||
#define DEV_EP_TX_DIS 0x0000
|
||||
#define DEV_EP_TX_STALL 0x0010
|
||||
#define DEV_EP_TX_NAK 0x0020
|
||||
#define DEV_EP_TX_VALID 0x0030
|
||||
|
||||
#define DEV_EP_RX_DIS 0x0000
|
||||
#define DEV_EP_RX_STALL 0x1000
|
||||
#define DEV_EP_RX_NAK 0x2000
|
||||
#define DEV_EP_RX_VALID 0x3000
|
||||
|
||||
/***************** GLOBAL DEFINES ***************************/
|
||||
|
||||
#define GAHBCFG_TXFEMPTYLVL_EMPTY 1
|
||||
#define GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
|
||||
|
||||
#define GAHBCFG_GLBINT_ENABLE 1
|
||||
#define GAHBCFG_INT_DMA_BURST_SINGLE 0
|
||||
#define GAHBCFG_INT_DMA_BURST_INCR 1
|
||||
#define GAHBCFG_INT_DMA_BURST_INCR4 3
|
||||
#define GAHBCFG_INT_DMA_BURST_INCR8 5
|
||||
#define GAHBCFG_INT_DMA_BURST_INCR16 7
|
||||
#define GAHBCFG_DMAENABLE 1
|
||||
#define GAHBCFG_TXFEMPTYLVL_EMPTY 1
|
||||
#define GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
|
||||
|
||||
#define GRXSTS_PKTSTS_IN 2
|
||||
#define GRXSTS_PKTSTS_IN_XFER_COMP 3
|
||||
#define GRXSTS_PKTSTS_DATA_TOGGLE_ERR 5
|
||||
#define GRXSTS_PKTSTS_CH_HALTED 7
|
||||
|
||||
#define DEVICE_MODE 0
|
||||
#define HOST_MODE 1
|
||||
|
||||
/***************** DEVICE DEFINES ***************************/
|
||||
|
||||
#define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
|
||||
#define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
|
||||
#define DSTS_ENUMSPD_LS_PHY_6MHZ 2
|
||||
#define DSTS_ENUMSPD_FS_PHY_48MHZ 3
|
||||
|
||||
#define DCFG_FRAME_INTERVAL_80 0
|
||||
#define DCFG_FRAME_INTERVAL_85 1
|
||||
#define DCFG_FRAME_INTERVAL_90 2
|
||||
#define DCFG_FRAME_INTERVAL_95 3
|
||||
|
||||
#define DEP0CTL_MPS_64 0
|
||||
#define DEP0CTL_MPS_32 1
|
||||
#define DEP0CTL_MPS_16 2
|
||||
#define DEP0CTL_MPS_8 3
|
||||
|
||||
#define EP_SPEED_LOW 0
|
||||
#define EP_SPEED_FULL 1
|
||||
#define EP_SPEED_HIGH 2
|
||||
|
||||
#define EP_TYPE_CTRL 0
|
||||
#define EP_TYPE_ISOC 1
|
||||
#define EP_TYPE_BULK 2
|
||||
#define EP_TYPE_INTR 3
|
||||
|
||||
#define STS_GOUT_NAK 1
|
||||
#define STS_DATA_UPDT 2
|
||||
#define STS_XFER_COMP 3
|
||||
#define STS_SETUP_COMP 4
|
||||
#define STS_SETUP_UPDT 6
|
||||
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
|
||||
USB_OTG_OK,
|
||||
USB_OTG_FAIL
|
||||
|
||||
}USB_OTG_Status;
|
||||
|
||||
typedef struct USB_OTG_hc
|
||||
{
|
||||
uint8_t hc_num;
|
||||
uint8_t dev_addr ;
|
||||
uint8_t ep_num;
|
||||
uint8_t ep_is_in;
|
||||
uint8_t speed;
|
||||
uint8_t ep_type;
|
||||
uint16_t max_packet;
|
||||
uint8_t data_pid;
|
||||
uint16_t multi_count;
|
||||
uint8_t *xfer_buff;
|
||||
uint32_t xfer_len;
|
||||
}
|
||||
USB_OTG_HC , *PUSB_OTG_HC;
|
||||
|
||||
typedef struct USB_OTG_ep
|
||||
{
|
||||
uint8_t num;
|
||||
uint8_t is_in;
|
||||
uint32_t tx_fifo_num;
|
||||
uint32_t type;
|
||||
uint8_t data_pid_start;
|
||||
uint8_t even_odd_frame;
|
||||
uint32_t maxpacket;
|
||||
uint8_t *xfer_buff;
|
||||
uint32_t xfer_len;
|
||||
uint32_t xfer_count;
|
||||
}
|
||||
|
||||
USB_OTG_EP , *PUSB_OTG_EP;
|
||||
|
||||
/********************************************************************************
|
||||
MACRO'S
|
||||
********************************************************************************/
|
||||
|
||||
#define CLEAR_IN_EP_INTR(epnum,intr) \
|
||||
diepint.d32=0; \
|
||||
diepint.b.intr = 1; \
|
||||
WRITE_REG32(&core_regs.inep_regs[epnum]->dev_in_ep_int,diepint.d32);
|
||||
|
||||
#define CLEAR_OUT_EP_INTR(epnum,intr) \
|
||||
doepint.d32=0; \
|
||||
doepint.b.intr = 1; \
|
||||
WRITE_REG32(&core_regs.outep_regs[epnum]->dev_out_ep_int,doepint.d32);
|
||||
|
||||
|
||||
#define READ_REG32(reg) (*(__IO uint32_t *)reg)
|
||||
|
||||
#define WRITE_REG32(reg,value) (*(__IO uint32_t *)reg = value)
|
||||
|
||||
#define MODIFY_REG32(reg,clear_mask,set_mask) \
|
||||
WRITE_REG32(reg, (((READ_REG32(reg)) & ~clear_mask) | set_mask ) )
|
||||
|
||||
|
||||
#define uDELAY(usec) udelay(usec)
|
||||
#define mDELAY(msec) uDELAY(msec * 1000)
|
||||
|
||||
#define _OTGD_FS_GATE_PHYCLK *(__IO uint32_t*)(0x50000E00) = 0x03
|
||||
#define _OTGD_FS_UNGATE_PHYCLK *(__IO uint32_t*)(0x50000E00) = 0x00
|
||||
|
||||
/*******************************************************************************
|
||||
this can be changed for real time base
|
||||
*******************************************************************************/
|
||||
static void udelay (const uint32_t usec)
|
||||
{
|
||||
uint32_t count = 0;
|
||||
const uint32_t utime = usec * 10;
|
||||
do
|
||||
{
|
||||
if ( ++count > utime )
|
||||
{
|
||||
return ;
|
||||
}
|
||||
}
|
||||
while (1);
|
||||
}
|
||||
/********************************************************************************
|
||||
EXPORTED FUNCTIONS FROM THE OTGD_FS_CAL LAYER
|
||||
********************************************************************************/
|
||||
USB_OTG_Status OTGD_FS_CoreInit(void);
|
||||
USB_OTG_Status OTGD_FS_SetAddress(uint32_t BaseAddress);
|
||||
USB_OTG_Status OTGD_FS_EnableGlobalInt(void);
|
||||
USB_OTG_Status OTGD_FS_DisableGlobalInt(void);
|
||||
|
||||
USB_OTG_Status USB_OTG_CoreInitHost(void);
|
||||
USB_OTG_Status USB_OTG_EnableHostInt(void);
|
||||
USB_OTG_Status USB_OTG_DisableHostInt(void);
|
||||
|
||||
void* OTGD_FS_ReadPacket(uint8_t *dest, uint16_t bytes);
|
||||
USB_OTG_Status OTGD_FS_WritePacket(uint8_t *src, uint8_t ch_ep_num, uint16_t bytes);
|
||||
|
||||
USB_OTG_Status USB_OTG_HcInit(USB_OTG_HC *hc);
|
||||
USB_OTG_Status USB_OTG_StartXfer(USB_OTG_HC *hc);
|
||||
|
||||
uint32_t USB_OTG_ResetPort( void);
|
||||
|
||||
uint32_t USB_OTG_ReadHPRT0(void);
|
||||
uint32_t OTGD_FS_ReadDevAllInEPItr(void);
|
||||
uint32_t OTGD_FS_ReadCoreItr(void);
|
||||
uint32_t OTGD_FS_ReadOtgItr (void);
|
||||
uint32_t USB_OTG_ReadHostAllChannels_intr (void);
|
||||
uint8_t IsHostMode(void);
|
||||
uint8_t IsDeviceMode(void);
|
||||
USB_OTG_Status USB_OTG_HcInit(USB_OTG_HC *hc);
|
||||
USB_OTG_Status USB_OTG_HcHalt(uint8_t hc_num);
|
||||
|
||||
USB_OTG_Status OTGD_FS_FlushTxFifo (uint32_t num);
|
||||
USB_OTG_Status OTGD_FS_FlushRxFifo (void);
|
||||
USB_OTG_Status OTGD_FS_SetHostMode (void);
|
||||
|
||||
USB_OTG_Status OTGD_FS_PhyInit(void);
|
||||
USB_OTG_Status USB_OTG_HcStartXfer(USB_OTG_HC *hc);
|
||||
|
||||
USB_OTG_Status OTGD_FS_CoreInitDev (void);
|
||||
USB_OTG_Status OTGD_FS_EnableDevInt(void);
|
||||
USB_OTG_Status OTGD_FS_EP0Activate(void);
|
||||
USB_OTG_Status OTGD_FS_EPActivate(USB_OTG_EP *ep);
|
||||
USB_OTG_Status OTGD_FS_EPDeactivate(USB_OTG_EP *ep);
|
||||
|
||||
USB_OTG_Status OTGD_FS_EPStartXfer(USB_OTG_EP *ep);
|
||||
USB_OTG_Status OTGD_FS_EP0StartXfer(USB_OTG_EP *ep);
|
||||
|
||||
USB_OTG_Status OTGD_FS_EPSetStall(USB_OTG_EP *ep);
|
||||
USB_OTG_Status OTGD_FS_EPClearStall(USB_OTG_EP *ep);
|
||||
uint32_t OTGD_FS_ReadDevAllOutEp_itr(void);
|
||||
uint32_t OTGD_FS_ReadDevOutEP_itr(USB_OTG_EP *ep);
|
||||
uint32_t OTGD_FS_ReadDevAllInEPItr(void);
|
||||
|
||||
|
||||
uint32_t OTGD_FS_Dev_GetEPStatus(USB_OTG_EP *ep);
|
||||
void OTGD_FS_Dev_SetEPStatus(USB_OTG_EP *ep, uint32_t Status);
|
||||
void OTGD_FS_Dev_SetRemoteWakeup(void);
|
||||
void OTGD_FS_Dev_ResetRemoteWakeup(void);
|
||||
|
||||
#endif /* STM32F10X_CL */
|
||||
|
||||
#endif
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : otg_dev.h
|
||||
* Author : STMicroelectronics
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : linking defines
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __OTG_DEV_H__
|
||||
#define __OTG_DEV_H__
|
||||
|
||||
#ifdef STM32F10X_CL
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x.h"
|
||||
#include "usb_type.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Endpoint types */
|
||||
#define OTG_DEV_EP_TYPE_CONTROL 0
|
||||
#define OTG_DEV_EP_TYPE_ISOC 1
|
||||
#define OTG_DEV_EP_TYPE_BULK 2
|
||||
#define OTG_DEV_EP_TYPE_INT 3
|
||||
|
||||
/* Endpoint Addresses (w/direction) */
|
||||
#define EP0_OUT 0x00
|
||||
#define EP0_IN 0x80
|
||||
#define EP1_OUT 0x01
|
||||
#define EP1_IN 0x81
|
||||
#define EP2_OUT 0x02
|
||||
#define EP2_IN 0x82
|
||||
#define EP3_OUT 0x03
|
||||
#define EP3_IN 0x83
|
||||
|
||||
|
||||
/*-*-*-*-*-*-*-*-*-* Replace the usb_regs.h defines -*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
/* 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)
|
||||
|
||||
/* EP Transmit status defines */
|
||||
#define EP_TX_DIS DEV_EP_TX_DIS) /* EndPoint TX DISabled */
|
||||
#define EP_TX_STALL DEV_EP_TX_STALL /* EndPoint TX STALLed */
|
||||
#define EP_TX_NAK DEV_EP_TX_NAK /* EndPoint TX NAKed */
|
||||
#define EP_TX_VALID DEV_EP_TX_VALID /* EndPoint TX VALID */
|
||||
|
||||
/* EP Transmit status defines */
|
||||
#define EP_RX_DIS DEV_EP_RX_DIS /* EndPoint RX DISabled */
|
||||
#define EP_RX_STALL DEV_EP_RX_STALL /* EndPoint RX STALLed */
|
||||
#define EP_RX_NAK DEV_EP_RX_NAK /* EndPoint RX NAKed */
|
||||
#define EP_RX_VALID DEV_EP_RX_VALID /* EndPoint RX VALID */
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#define _GetEPTxStatus(bEpNum) ((uint16_t)OTG_DEV_GetEPTxStatus(bEpNum))
|
||||
#define _GetEPRxStatus(bEpNum) ((uint16_t)OTG_DEV_GetEPRxStatus(bEpNum))
|
||||
|
||||
#define _SetEPTxStatus(bEpNum,wState) (OTG_DEV_SetEPTxStatus(bEpNum, wState))
|
||||
#define _SetEPRxStatus(bEpNum,wState) (OTG_DEV_SetEPRxStatus(bEpNum, wState))
|
||||
|
||||
#define _SetEPTxValid(bEpNum) (OTG_DEV_SetEPTxStatus(bEpNum, EP_TX_VALID))
|
||||
#define _SetEPRxValid(bEpNum) (OTG_DEV_SetEPRxStatus(bEpNum, EP_RX_VALID))
|
||||
|
||||
#define _GetTxStallStatus(bEpNum) (OTG_DEV_GetEPTxStatus(bEpNum) == EP_TX_STALL)
|
||||
#define _GetRxStallStatus(bEpNum) (OTG_DEV_GetEPRxStatus(bEpNum) == EP_RX_STALL)
|
||||
|
||||
/* Define the callbacks for updating the USB state machine */
|
||||
#define OTGD_FS_DEVICE_RESET Device_Property.Reset()
|
||||
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
void OTG_DEV_Init(void);
|
||||
void OTG_DEV_EP_Init(uint8_t bEpAdd, uint8_t bEpType, uint16_t wEpMaxPackSize);
|
||||
|
||||
void OTG_DEV_SetEPRxStatus(uint8_t bEpnum, uint32_t status);
|
||||
void OTG_DEV_SetEPTxStatus(uint8_t bEpnum, uint32_t status);
|
||||
uint32_t OTG_DEV_GetEPRxStatus(uint8_t bEpnum);
|
||||
uint32_t OTG_DEV_GetEPTxStatus(uint8_t bEpnum);
|
||||
|
||||
void USB_DevDisconnect(void);
|
||||
void USB_DevConnect(void);
|
||||
|
||||
|
||||
/*-*-*-*-*-*-*-*-*-* Replace the usb_regs.h prototypes *-*-*-*-*-*-*-*-*-*-*-*/
|
||||
void SetEPTxStatus(uint8_t bEpNum, uint16_t wState);
|
||||
void SetEPRxStatus(uint8_t bEpNum, uint16_t wState);
|
||||
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 SetEPTxCount(uint8_t bEpNum, uint16_t wCount);
|
||||
void SetEPRxCount(uint8_t bEpNum, uint16_t wCount);
|
||||
|
||||
uint16_t ToWord(uint8_t, uint8_t);
|
||||
uint16_t ByteSwap(uint16_t);
|
||||
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
|
||||
#endif /* STM32F10X_CL */
|
||||
|
||||
#endif /* __OTG_DEV_H__ */
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : otgd_fs_int.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Endpoint interrupt's service routines prototypes.
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_INT_H
|
||||
#define __USB_INT_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
#ifdef STM32F10X_CL
|
||||
|
||||
/* Interrupt Handlers functions */
|
||||
uint32_t OTGD_FS_Handle_ModeMismatch_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_Sof_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_RxStatusQueueLevel_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_NPTxFE_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_GInNakEff_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_GOutNakEff_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_EarlySuspend_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_USBSuspend_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_UsbReset_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_EnumDone_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_IsoOutDrop_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_EOPF_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_EPMismatch_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_InEP_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_OutEP_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_IncomplIsoIn_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_IncomplIsoOut_ISR(void);
|
||||
uint32_t OTGD_FS_Handle_Wakeup_ISR(void);
|
||||
|
||||
#endif /* STM32F10X_CL */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
|
||||
#endif /* __USB_INT_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,87 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : otgd_fs_pcd.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Header file of the High Layer device mode interface and
|
||||
* wrapping layer
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __USB_OTG_PCD_H__
|
||||
#define __USB_OTG_PCD_H__
|
||||
|
||||
#include "otgd_fs_regs.h"
|
||||
|
||||
#define MAX_EP0_SIZE 0x40
|
||||
#define MAX_PACKET_SIZE 0x400
|
||||
|
||||
|
||||
#define USB_ENDPOINT_XFER_CONTROL 0
|
||||
#define USB_ENDPOINT_XFER_ISOC 1
|
||||
#define USB_ENDPOINT_XFER_BULK 2
|
||||
#define USB_ENDPOINT_XFER_INT 3
|
||||
#define USB_ENDPOINT_XFERTYPE_MASK 3
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
ENUMERATION TYPE
|
||||
********************************************************************************/
|
||||
enum usb_device_speed {
|
||||
USB_SPEED_UNKNOWN = 0,
|
||||
USB_SPEED_LOW, USB_SPEED_FULL,
|
||||
USB_SPEED_HIGH
|
||||
};
|
||||
/********************************************************************************
|
||||
Data structure type
|
||||
********************************************************************************/
|
||||
typedef struct usb_ep_descriptor
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bEndpointAddress;
|
||||
uint8_t bmAttributes;
|
||||
uint16_t wMaxPacketSize;
|
||||
uint8_t bInterval;
|
||||
}
|
||||
EP_DESCRIPTOR , *PEP_DESCRIPTOR;
|
||||
/********************************************************************************
|
||||
USBF LAYER UNION AND STRUCTURES
|
||||
********************************************************************************/
|
||||
typedef struct USB_OTG_USBF
|
||||
{
|
||||
|
||||
USB_OTG_EP ep0;
|
||||
uint8_t ep0state;
|
||||
USB_OTG_EP in_ep[ MAX_TX_FIFOS - 1];
|
||||
USB_OTG_EP out_ep[ MAX_TX_FIFOS - 1];
|
||||
}
|
||||
USB_OTG_PCD_DEV , *USB_OTG_PCD_PDEV;
|
||||
/********************************************************************************
|
||||
EXPORTED FUNCTION FROM THE USB_OTG LAYER
|
||||
********************************************************************************/
|
||||
void OTGD_FS_PCD_Init(void);
|
||||
void OTGD_FS_PCD_DevConnect (void);
|
||||
void OTGD_FS_PCD_DevDisconnect (void);
|
||||
void OTGD_FS_PCD_EP_SetAddress (uint8_t address);
|
||||
uint32_t OTGD_FS_PCD_EP_Open(EP_DESCRIPTOR *epdesc);
|
||||
uint32_t OTGD_FS_PCD_EP_Close ( uint8_t ep_addr);
|
||||
uint32_t OTGD_FS_PCD_EP_Read ( uint8_t ep_addr, uint8_t *pbuf, uint32_t buf_len);
|
||||
uint32_t OTGD_FS_PCD_EP_Write ( uint8_t ep_addr, uint8_t *pbuf, uint32_t buf_len);
|
||||
uint32_t OTGD_FS_PCD_EP_Stall (uint8_t epnum);
|
||||
uint32_t OTGD_FS_PCD_EP_ClrStall (uint8_t epnum);
|
||||
uint32_t OTGD_FS_PCD_EP_Flush (uint8_t epnum);
|
||||
uint32_t OTGD_FS_PCD_Handle_ISR(void);
|
||||
|
||||
USB_OTG_EP* OTGD_FS_PCD_GetOutEP(uint32_t ep_num) ;
|
||||
USB_OTG_EP* OTGD_FS_PCD_GetInEP(uint32_t ep_num);
|
||||
void OTGD_FS_PCD_EP0_OutStart(void);
|
||||
|
||||
#endif
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,243 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_core.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Standard protocol processing functions prototypes
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* 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 sucessfully */
|
||||
USB_ERROR,
|
||||
USB_UNSUPPORT,
|
||||
USB_NOT_READY /* The process has not been finished, endpoint will be
|
||||
NAK to further rquest */
|
||||
} 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);
|
||||
|
||||
uint8_t* 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 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,80 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_def.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Definitions related to USB Core
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* 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 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,49 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_init.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Initialization routines & global variables
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* 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 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,33 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_int.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Endpoint CTR (Low and High) interrupt's service routines
|
||||
* prototypes
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* 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 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,50 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_lib.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : USB library include files
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_LIB_H
|
||||
#define __USB_LIB_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f10x.h"
|
||||
#include "usb_type.h"
|
||||
#include "usb_regs.h"
|
||||
#include "usb_def.h"
|
||||
#include "usb_core.h"
|
||||
#include "usb_init.h"
|
||||
#ifndef STM32F10X_CL
|
||||
#include "usb_mem.h"
|
||||
#include "usb_int.h"
|
||||
#endif /* STM32F10X_CL */
|
||||
|
||||
#include "usb_sil.h"
|
||||
|
||||
#ifdef STM32F10X_CL
|
||||
#include "otgd_fs_cal.h"
|
||||
#include "otgd_fs_pcd.h"
|
||||
#include "otgd_fs_dev.h"
|
||||
#include "otgd_fs_int.h"
|
||||
#endif /* STM32F10X_CL */
|
||||
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
/* External variables --------------------------------------------------------*/
|
||||
|
||||
#endif /* __USB_LIB_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,32 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_mem.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Utility prototypes functions for memory/PMA transfers
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* 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 2009 STMicroelectronics *****END OF FILE****/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,34 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_sil.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Simplified Interface Layer function prototypes.
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* 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 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,74 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_type.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Type definitions used by the USB Library
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* 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
|
||||
|
||||
#ifndef __STM32F10x_H
|
||||
|
||||
typedef signed long s32;
|
||||
typedef signed short s16;
|
||||
typedef signed char s8;
|
||||
|
||||
typedef volatile signed long vs32;
|
||||
typedef volatile signed short vs16;
|
||||
typedef volatile signed char vs8;
|
||||
|
||||
typedef unsigned long u32;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned char u8;
|
||||
|
||||
typedef unsigned long const uc32; /* Read Only */
|
||||
typedef unsigned short const uc16; /* Read Only */
|
||||
typedef unsigned char const uc8; /* Read Only */
|
||||
|
||||
typedef volatile unsigned long vu32;
|
||||
typedef volatile unsigned short vu16;
|
||||
typedef volatile unsigned char vu8;
|
||||
|
||||
typedef volatile unsigned long const vuc32; /* Read Only */
|
||||
typedef volatile unsigned short const vuc16; /* Read Only */
|
||||
typedef volatile unsigned char const vuc8; /* Read Only */
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FALSE = 0, TRUE = !FALSE
|
||||
}
|
||||
bool;
|
||||
|
||||
typedef enum { RESET = 0, SET = !RESET } FlagStatus, ITStatus;
|
||||
|
||||
typedef enum { DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
|
||||
|
||||
typedef enum { ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
|
||||
#endif
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
/* External variables --------------------------------------------------------*/
|
||||
|
||||
#endif /* __USB_TYPE_H */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,385 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : otgd_fs_dev.c
|
||||
* Author : STMicroelectronics
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : High Layer device mode interface and wrapping layer.
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifdef STM32F10X_CL
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "otgd_fs_dev.h"
|
||||
#include "usb_regs.h"
|
||||
#include "otgd_fs_cal.h"
|
||||
#include "otgd_fs_pcd.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTG_DEV_Init
|
||||
* Description : Initialize the OTG Device IP and EP0.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void OTG_DEV_Init(void)
|
||||
{
|
||||
EP_DESCRIPTOR ep_descriptor;
|
||||
USB_OTG_EP *ep;
|
||||
|
||||
/* Set the OTG_USB base registers address */
|
||||
OTGD_FS_SetAddress(USB_OTG_FS1_BASE_ADDR);
|
||||
|
||||
/* Disable all global interrupts */
|
||||
OTGD_FS_DisableGlobalInt();
|
||||
|
||||
/*Init the Core (common init.) */
|
||||
OTGD_FS_CoreInit();
|
||||
|
||||
/* Init Device */
|
||||
OTGD_FS_CoreInitDev();
|
||||
|
||||
/* Init internal driver structure */
|
||||
OTGD_FS_PCD_Init();
|
||||
|
||||
/* Configure and open the IN control EP0 */
|
||||
ep_descriptor.bEndpointAddress = 0x80;
|
||||
ep_descriptor.wMaxPacketSize = 64;
|
||||
ep_descriptor.bmAttributes = USB_ENDPOINT_XFER_CONTROL;
|
||||
OTGD_FS_PCD_EP_Open(&ep_descriptor);
|
||||
|
||||
/* Configure and open the OUT control EP0 */
|
||||
ep_descriptor.bEndpointAddress = 0x00;
|
||||
OTGD_FS_PCD_EP_Open(&ep_descriptor);
|
||||
|
||||
|
||||
ep = OTGD_FS_PCD_GetOutEP(0);
|
||||
OTGD_FS_EPStartXfer(ep);
|
||||
|
||||
/* Enable EP0 to start receiving setup packets */
|
||||
OTGD_FS_PCD_EP0_OutStart();
|
||||
|
||||
/* Enable USB Global interrupt */
|
||||
OTGD_FS_EnableGlobalInt();
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTG_DEV_EP_Init
|
||||
* Description : Initialize the selected endpoint parameters
|
||||
* Input : - bEpAdd: address of the endpoint (epnum|epdir)
|
||||
* expample: EP1 OUT -> 0x01 and EP1 IN 0x81.
|
||||
* - bEpType: OTG_DEV_EP_TYPE_CONTROL, OTG_DEV_EP_TYPE_ISOC,
|
||||
* OTG_DEV_EP_TYPE_BULK, OTG_DEV_EP_TYPE_INT
|
||||
* - wEpMaxPackSize: The EP max packet size.
|
||||
* Output : None.
|
||||
* Return : Status: New status to be set for the endpoint:
|
||||
*******************************************************************************/
|
||||
void OTG_DEV_EP_Init(uint8_t bEpAdd, uint8_t bEpType, uint16_t wEpMaxPackSize)
|
||||
{
|
||||
EP_DESCRIPTOR ep_descriptor;
|
||||
USB_OTG_EP *ep;
|
||||
|
||||
/* Set the EP parameters in a structure */
|
||||
ep_descriptor.bEndpointAddress = bEpAdd;
|
||||
ep_descriptor.bmAttributes = bEpType;
|
||||
ep_descriptor.wMaxPacketSize = wEpMaxPackSize;
|
||||
|
||||
OTGD_FS_PCD_EP_Flush(bEpAdd);
|
||||
|
||||
/* Open the EP with entered parameters */
|
||||
OTGD_FS_PCD_EP_Open(&ep_descriptor);
|
||||
|
||||
/* Activate the EP if it is an OUT EP */
|
||||
if ((bEpAdd & 0x80) == 0)
|
||||
{
|
||||
ep = OTGD_FS_PCD_GetOutEP(bEpAdd & 0x7F);
|
||||
OTGD_FS_EPStartXfer(ep);
|
||||
}
|
||||
else
|
||||
{
|
||||
ep = OTGD_FS_PCD_GetInEP(bEpAdd & 0x7F);
|
||||
ep->even_odd_frame = 0;
|
||||
OTG_DEV_SetEPTxStatus(bEpAdd, DEV_EP_TX_NAK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTG_DEV_GetEPTxStatus
|
||||
* Description : Set the related endpoint status.
|
||||
* Input : Number of the endpoint.
|
||||
* Output : None.
|
||||
* Return : Status: New status to be set for the endpoint:
|
||||
*******************************************************************************/
|
||||
uint32_t OTG_DEV_GetEPTxStatus(uint8_t bEpnum)
|
||||
{
|
||||
USB_OTG_EP *ep;
|
||||
uint32_t status = 0;
|
||||
|
||||
ep = OTGD_FS_PCD_GetInEP(bEpnum & 0x7F);
|
||||
|
||||
status = OTGD_FS_Dev_GetEPStatus(ep);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTG_DEV_GetEPRxStatus
|
||||
* Description : returns the related endpoint status.
|
||||
* Input : Number of the endpoint.
|
||||
* Output : None.
|
||||
* Return : Status: New status to be set for the endpoint:
|
||||
*******************************************************************************/
|
||||
uint32_t OTG_DEV_GetEPRxStatus(uint8_t bEpnum)
|
||||
{
|
||||
USB_OTG_EP *ep;
|
||||
uint32_t status = 0;
|
||||
|
||||
ep = OTGD_FS_PCD_GetOutEP(bEpnum & 0x7F);
|
||||
|
||||
status = OTGD_FS_Dev_GetEPStatus(ep);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTG_DEV_SetEPTxStatus
|
||||
* Description : Sets the related endpoint status.
|
||||
* Input : - bEpnum: Number of the endpoint.
|
||||
* - Status: New status to be set for the endpoint. It can be
|
||||
* DEV_EP_TX_VALID, DEV_EP_TX_STALL, DEV_EP_TX_NAK or
|
||||
* DEV_EP_TX_DISABLE.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void OTG_DEV_SetEPTxStatus(uint8_t bEpnum, uint32_t Status)
|
||||
{
|
||||
USB_OTG_EP *ep;
|
||||
|
||||
ep = OTGD_FS_PCD_GetInEP(bEpnum & 0x7F);
|
||||
|
||||
if ((bEpnum == 0x80) && (Status == DEV_EP_TX_STALL))
|
||||
{
|
||||
ep->is_in = 1;
|
||||
}
|
||||
|
||||
OTGD_FS_Dev_SetEPStatus(ep, Status);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTG_DEV_SetEPRxStatus
|
||||
* Description : Sets the related endpoint status.
|
||||
* Input : - bEpnum: Number of the endpoint.
|
||||
* - Status: New status to be set for the endpoint. It can be
|
||||
* DEV_EP_RX_VALID, DEV_EP_RX_STALL, DEV_EP_RX_NAK or
|
||||
* DEV_EP_RX_DISABLE.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void OTG_DEV_SetEPRxStatus(uint8_t bEpnum, uint32_t Status)
|
||||
{
|
||||
USB_OTG_EP *ep;
|
||||
|
||||
ep = OTGD_FS_PCD_GetOutEP(bEpnum & 0x7F);
|
||||
|
||||
OTGD_FS_Dev_SetEPStatus(ep, Status);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USB_DevDisconnect
|
||||
* Description : Disconnect the Pullup resist.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wState: new state.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void USB_DevDisconnect(void)
|
||||
{
|
||||
OTGD_FS_PCD_DevDisconnect();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USB_DevConnect
|
||||
* Description : Disconnect the .
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wState: new state.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
void USB_DevConnect(void)
|
||||
{
|
||||
OTGD_FS_PCD_DevConnect();
|
||||
}
|
||||
|
||||
/*-*-*-*-*-*-*-*-*-* Replace the usb_regs.h defines -*-*-*-*-*-*-*-*-*-*-*-*-*/
|
||||
|
||||
/*******************************************************************************
|
||||
* 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 : 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 : 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 : 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)
|
||||
{
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* 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)
|
||||
{
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* 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);
|
||||
}
|
||||
|
||||
#endif /* STM32F10X_CL */
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,445 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : otgd_fs_pcd.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Peripheral Device Interface low layer.
|
||||
********************************************************************************
|
||||
* THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifdef STM32F10X_CL
|
||||
|
||||
#include "usb_lib.h"
|
||||
#include "otgd_fs_cal.h"
|
||||
#include "otgd_fs_pcd.h"
|
||||
|
||||
USB_OTG_PCD_DEV USB_OTG_PCD_dev;
|
||||
|
||||
extern USB_OTG_CORE_REGS core_regs;
|
||||
/*******************************************************************************
|
||||
* Function Name : OTGD_FS_PCD_Init
|
||||
* Description : Initialize the USB Device portion of the driver.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void OTGD_FS_PCD_Init(void)
|
||||
{
|
||||
uint32_t i;
|
||||
USB_OTG_EP *ep;
|
||||
|
||||
ep = &USB_OTG_PCD_dev.ep0;
|
||||
USB_OTG_PCD_dev.ep0state = 0;
|
||||
|
||||
/* Init ep structure */
|
||||
ep->num = 0;
|
||||
ep->tx_fifo_num = 0;
|
||||
|
||||
/* Control until ep is actvated */
|
||||
ep->type = EP_TYPE_CTRL;
|
||||
ep->maxpacket = MAX_PACKET_SIZE;
|
||||
|
||||
ep->xfer_buff = 0;
|
||||
ep->xfer_len = 0;
|
||||
|
||||
for (i = 1; i < MAX_TX_FIFOS ; i++)
|
||||
{
|
||||
ep = &USB_OTG_PCD_dev.in_ep[i-1];
|
||||
|
||||
/* Init ep structure */
|
||||
ep->is_in = 1;
|
||||
ep->num = i;
|
||||
ep->tx_fifo_num = i;
|
||||
|
||||
/* Control until ep is actvated */
|
||||
ep->type = EP_TYPE_CTRL;
|
||||
ep->maxpacket = MAX_PACKET_SIZE;
|
||||
ep->xfer_buff = 0;
|
||||
ep->xfer_len = 0;
|
||||
}
|
||||
|
||||
for (i = 1; i < MAX_TX_FIFOS; i++)
|
||||
{
|
||||
ep = &USB_OTG_PCD_dev.out_ep[i-1];
|
||||
|
||||
/* Init ep structure */
|
||||
ep->is_in = 0;
|
||||
ep->num = i;
|
||||
ep->tx_fifo_num = i;
|
||||
|
||||
/* Control until ep is activated */
|
||||
ep->type = EP_TYPE_CTRL;
|
||||
ep->maxpacket = MAX_PACKET_SIZE;
|
||||
ep->xfer_buff = 0;
|
||||
ep->xfer_len = 0;
|
||||
}
|
||||
|
||||
USB_OTG_PCD_dev.ep0.maxpacket = MAX_EP0_SIZE;
|
||||
USB_OTG_PCD_dev.ep0.type = EP_TYPE_CTRL;
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTGD_FS_PCD_EP_Open
|
||||
* Description : Configure an Endpoint
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : status
|
||||
*******************************************************************************/
|
||||
uint32_t OTGD_FS_PCD_EP_Open(EP_DESCRIPTOR *epdesc)
|
||||
{
|
||||
USB_OTG_EP *ep;
|
||||
|
||||
|
||||
if ((0x80 & epdesc->bEndpointAddress) != 0)
|
||||
{
|
||||
ep = OTGD_FS_PCD_GetInEP(epdesc->bEndpointAddress & 0x7F);
|
||||
}
|
||||
else
|
||||
{
|
||||
ep = OTGD_FS_PCD_GetOutEP(epdesc->bEndpointAddress & 0x7F);
|
||||
}
|
||||
|
||||
ep->num = epdesc->bEndpointAddress & 0x7F;
|
||||
ep->is_in = (0x80 & epdesc->bEndpointAddress) != 0;
|
||||
ep->maxpacket = epdesc->wMaxPacketSize;
|
||||
ep->type = epdesc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
|
||||
|
||||
if (ep->is_in)
|
||||
{
|
||||
/* Assign a Tx FIFO */
|
||||
ep->tx_fifo_num = ep->num;
|
||||
}
|
||||
|
||||
/* Set initial data PID. */
|
||||
if ((epdesc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK )
|
||||
{
|
||||
ep->data_pid_start = 0;
|
||||
}
|
||||
|
||||
OTGD_FS_EPActivate(ep );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTGD_FS_PCD_EP_Close
|
||||
* Description : Called when an EP is disabled
|
||||
* Input : Endpoint address.
|
||||
* Output : None
|
||||
* Return : status
|
||||
*******************************************************************************/
|
||||
uint32_t OTGD_FS_PCD_EP_Close(uint8_t ep_addr)
|
||||
{
|
||||
|
||||
USB_OTG_EP *ep;
|
||||
|
||||
if ((0x80 & ep_addr) != 0)
|
||||
{
|
||||
ep = OTGD_FS_PCD_GetInEP(ep_addr & 0x7F);
|
||||
}
|
||||
else
|
||||
{
|
||||
ep = OTGD_FS_PCD_GetOutEP(ep_addr & 0x7F);
|
||||
}
|
||||
|
||||
ep->num = ep_addr & 0x7F;
|
||||
ep->is_in = (0x80 & ep_addr) != 0;
|
||||
|
||||
OTGD_FS_EPDeactivate(ep );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTGD_FS_PCD_EP_Read
|
||||
* Description : Read data from Fifo
|
||||
* Input : Endpoint address.
|
||||
* Output : None
|
||||
* Return : status
|
||||
*******************************************************************************/
|
||||
uint32_t OTGD_FS_PCD_EP_Read (uint8_t ep_addr, uint8_t *pbuf, uint32_t buf_len)
|
||||
{
|
||||
USB_OTG_EP *ep;
|
||||
uint32_t i;
|
||||
|
||||
ep = OTGD_FS_PCD_GetOutEP(ep_addr & 0x7F);
|
||||
|
||||
/* copy received data into application buffer */
|
||||
for (i = 0 ; i < buf_len ; i++)
|
||||
{
|
||||
pbuf[i] = ep->xfer_buff[i];
|
||||
}
|
||||
|
||||
/*setup and start the Xfer */
|
||||
ep->xfer_buff = pbuf;
|
||||
ep->xfer_len = buf_len;
|
||||
ep->xfer_count = 0;
|
||||
ep->is_in = 0;
|
||||
ep->num = ep_addr & 0x7F;
|
||||
|
||||
if ( ep->num == 0 )
|
||||
{
|
||||
OTGD_FS_EP0StartXfer(ep);
|
||||
}
|
||||
else if (USB_OTG_PCD_dev.ep0state == 0)
|
||||
{
|
||||
OTGD_FS_EPStartXfer( ep );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USBF_EP_Write
|
||||
* Description : Read data from Fifo
|
||||
* Input : ep
|
||||
* Output : None
|
||||
* Return : status
|
||||
*******************************************************************************/
|
||||
uint32_t OTGD_FS_PCD_EP_Write (uint8_t ep_addr, uint8_t *pbuf, uint32_t buf_len)
|
||||
{
|
||||
USB_OTG_EP *ep;
|
||||
|
||||
ep = OTGD_FS_PCD_GetInEP(ep_addr & 0x7f);
|
||||
|
||||
/* assign data to EP structure buffer */
|
||||
ep->xfer_buff = pbuf;
|
||||
|
||||
/* Setup and start the Transfer */
|
||||
ep->xfer_count = 0;
|
||||
ep->xfer_len = buf_len;
|
||||
ep->is_in = 1;
|
||||
ep->num = ep_addr & 0x7F;
|
||||
|
||||
if ( ep->num == 0 )
|
||||
{
|
||||
OTGD_FS_EP0StartXfer(ep);
|
||||
}
|
||||
else if (USB_OTG_PCD_dev.ep0state == 0)
|
||||
{
|
||||
OTGD_FS_EPStartXfer( ep );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTGD_FS_PCD_EP_Stall
|
||||
* Description : Stall an endpoint.
|
||||
* Input : Endpoint Address.
|
||||
* Output : None
|
||||
* Return : status
|
||||
*******************************************************************************/
|
||||
uint32_t OTGD_FS_PCD_EP_Stall (uint8_t ep_addr)
|
||||
{
|
||||
USB_OTG_EP *ep;
|
||||
|
||||
if ((0x80 & ep_addr) != 0)
|
||||
{
|
||||
ep = OTGD_FS_PCD_GetInEP(ep_addr & 0x7F);
|
||||
}
|
||||
else
|
||||
{
|
||||
ep = OTGD_FS_PCD_GetOutEP(ep_addr & 0x7F);
|
||||
}
|
||||
|
||||
ep->num = ep_addr & 0x7F;
|
||||
ep->is_in = ((ep_addr & 0x80) == 0x80) ? 1 : 0;
|
||||
|
||||
OTGD_FS_EPSetStall(ep);
|
||||
return (0);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : OTGD_FS_PCD_EP_ClrStall
|
||||
* Description : Clear stall condition on endpoints.
|
||||
* Input : Endpoint Address.
|
||||
* Output : None
|
||||
* Return : status
|
||||
*******************************************************************************/
|
||||
uint32_t OTGD_FS_PCD_EP_ClrStall (uint8_t ep_addr)
|
||||
{
|
||||
|
||||
USB_OTG_EP *ep;
|
||||
|
||||
if ((0x80 & ep_addr) != 0)
|
||||
{
|
||||
ep = OTGD_FS_PCD_GetInEP(ep_addr & 0x7F);
|
||||
}
|
||||
else
|
||||
{
|
||||
ep = OTGD_FS_PCD_GetOutEP(ep_addr & 0x7F);
|
||||
}
|
||||
|
||||
ep->num = ep_addr & 0x7F;
|
||||
ep->is_in = ((ep_addr & 0x80) == 0x80) ? 1 : 0;
|
||||
|
||||
OTGD_FS_EPClearStall(ep);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : USBF_FCD_EP_Flush()
|
||||
* Description : This Function flushes the buffer.
|
||||
* Input : Endpoint Address.
|
||||
* Output : None
|
||||
* Return : status
|
||||
*******************************************************************************/
|
||||
uint32_t OTGD_FS_PCD_EP_Flush (uint8_t ep_addr)
|
||||
{
|
||||
|
||||
uint8_t is_out;
|
||||
uint8_t ep_nbr;
|
||||
|
||||
ep_nbr = ep_addr & 0x7F;
|
||||
is_out = ((ep_addr & 0x80) == 0x80) ? 0 : 1;
|
||||
|
||||
if (is_out == 0)
|
||||
{
|
||||
OTGD_FS_FlushTxFifo(ep_nbr);
|
||||
}
|
||||
else
|
||||
{
|
||||
OTGD_FS_FlushRxFifo();
|
||||
}
|
||||
OTGD_FS_PCD_EP_ClrStall(ep_addr);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTGD_FS_PCD_EP_SetAddress
|
||||
* Description : This Function set USB device address
|
||||
* Input : The new device Address to be set.
|
||||
* Output : None
|
||||
* Return : status
|
||||
*******************************************************************************/
|
||||
void OTGD_FS_PCD_EP_SetAddress (uint8_t address)
|
||||
{
|
||||
|
||||
USB_OTG_dev_cfg_data dcfg;
|
||||
dcfg.d32 = 0;
|
||||
|
||||
dcfg.b.devaddr = address;
|
||||
MODIFY_REG32( &core_regs.dev_regs->dev_cfg, 0, dcfg.d32);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTGD_FS_PCD_GetInEP
|
||||
* Description : This function returns pointer to IN EP struct with number ep_num
|
||||
* Input : Endpoint Number.
|
||||
* Output : None
|
||||
* Return : status
|
||||
*******************************************************************************/
|
||||
USB_OTG_EP* OTGD_FS_PCD_GetInEP(uint32_t ep_num)
|
||||
{
|
||||
uint32_t i;
|
||||
if (ep_num == 0)
|
||||
{
|
||||
return &USB_OTG_PCD_dev.ep0;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < MAX_TX_FIFOS; ++i)
|
||||
{
|
||||
if (USB_OTG_PCD_dev.in_ep[i].num == ep_num)
|
||||
return &USB_OTG_PCD_dev.in_ep[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : USBF_GetOutEP
|
||||
* Description : returns pointer to OUT EP struct with number ep_num
|
||||
* Input : Endpoint Number.
|
||||
* Output : None
|
||||
* Return : USBF_EP
|
||||
*******************************************************************************/
|
||||
USB_OTG_EP* OTGD_FS_PCD_GetOutEP(uint32_t ep_num)
|
||||
{
|
||||
uint32_t i;
|
||||
if (ep_num == 0)
|
||||
{
|
||||
return &USB_OTG_PCD_dev.ep0;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < MAX_TX_FIFOS; ++i)
|
||||
{
|
||||
if (USB_OTG_PCD_dev.out_ep[i].num == ep_num)
|
||||
return &USB_OTG_PCD_dev.out_ep[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTGD_FS_PCD_DevConnect
|
||||
* Description : Connect device
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : status
|
||||
*******************************************************************************/
|
||||
void OTGD_FS_PCD_DevConnect(void)
|
||||
{
|
||||
|
||||
USB_OTG_dev_ctl_data dctl;
|
||||
|
||||
dctl.d32 = READ_REG32(&core_regs.dev_regs->dev_ctl);
|
||||
|
||||
/* Connect device */
|
||||
dctl.b.sftdiscon = 0;
|
||||
WRITE_REG32(&core_regs.dev_regs->dev_ctl, dctl.d32);
|
||||
mDELAY(25);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTGD_FS_PCD_DevDisconnect
|
||||
* Description : Disconnect device
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : status
|
||||
*******************************************************************************/
|
||||
void OTGD_FS_PCD_DevDisconnect (void)
|
||||
{
|
||||
|
||||
USB_OTG_dev_ctl_data dctl;
|
||||
|
||||
dctl.d32 = READ_REG32(&core_regs.dev_regs->dev_ctl);
|
||||
|
||||
/* Disconnect device for 20ms */
|
||||
dctl.b.sftdiscon = 1;
|
||||
WRITE_REG32(&core_regs.dev_regs->dev_ctl, dctl.d32);
|
||||
mDELAY(25);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : OTGD_FS_PCD_EP0_OutStart
|
||||
* Description : Configures EPO to receive SETUP packets.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void OTGD_FS_PCD_EP0_OutStart(void)
|
||||
{
|
||||
|
||||
USB_OTG_dev_ep_txfer_size0_data doeptsize0;
|
||||
|
||||
doeptsize0.d32 = 0;
|
||||
doeptsize0.b.supcnt = 3;
|
||||
doeptsize0.b.pktcnt = 1;
|
||||
doeptsize0.b.xfersize = 8 * 3;
|
||||
|
||||
WRITE_REG32( &core_regs.outep_regs[0]->dev_out_ep_txfer_siz, doeptsize0.d32 );
|
||||
|
||||
}
|
||||
|
||||
#endif /* STM32F10X_CL */
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,63 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_init.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Initialization routines & global variables
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
/* 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 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,188 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_int.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Endpoint CTR (Low and High) interrupt's service routines
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
#ifndef STM32F10X_CL
|
||||
|
||||
/* 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 ints */
|
||||
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(...) */
|
||||
}
|
||||
|
||||
#endif /* STM32F10X_CL */
|
||||
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,75 @@
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : usb_mem.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.0
|
||||
* Date : 10/30/2009
|
||||
* Description : Utility functions for memory transfers to/from PMA
|
||||
********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
#ifndef STM32F10X_CL
|
||||
|
||||
/* 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++;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* STM32F10X_CL */
|
||||
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user