STM 32 F 4 Discovery USB HID用のファイル図解

6209 ワード

├── STM32_USB_Device_Library USBデバイスライブラリから
│   │   ├── Class
│   │   │   └── hid
│   │   │       ├── inc
│   │   │       │   └── usbd_hid_core.h
│   │   │       └── src
│   │   │           └── usbd_hid_core.c
│   │   └── Core
│   │       ├── inc
│   │       │   ├── usbd_core.h
│   │       │   ├── usbd_def.h
│   │       │   ├── usbd_ioreq.h
│   │       │   ├── usbd_req.h
│   │       │   └── usbd_usr.h
│   │       └── src
│   │           ├── usbd_core.c
│   │           ├── usbd_ioreq.c
│   │           └── usbd_req.c
│   ├── STM32_USB_OTG_Driver USB OTGライブラリ
│   │   ├── inc │   │   │   ├── usb_bsp.h │   │   │   ├── usb_core.h │   │   │   ├── usb_dcd.h │   │   │   ├── usb_dcd_int.h │   │   │   ├── usb_defines.h │   │   │   └── usb_regs.h │   │   └── src │   │       ├── usb_core.c │   │       ├── usb_dcd.c
│   │       └── usb_dcd_int.c
階層的に分析すると、OTGはさらに下位層で、USBDのファイルはUSBのファイルに依存しており、ライブラリの使用から言えば、これらのファイルは変更する必要はありません.
変更が必要なのは次のファイルかもしれません
    ├── usb_bsp.c     ├── usb_conf.h     ├── usbd_conf.h     ├── usbd_desc.c     ├── usbd_desc.h     └── usbd_usr.c
いくつかの論理はmainです.cで操作し、ホスト側にデータを送信する方法を考慮する
一つの工事にとって
    ├── stm32f4xx_conf.h     ├── stm32f4xx_it.c     ├── stm32f4xx_it.h     ├── system_stm32f4xx.c
このいくつかのファイルもライブラリから抽出されたもので、変更される可能性があります.
STM32F4xx_StdPeriph_Driverという部分の内容はほとんど動いたことがなく、かなり下位のドライブファイルです
│   ├── CMSIS │   │   ├── Include │   │   │   ├── core_cm4.h │   │   │   ├── core_cm4_simd.h │   │   │   ├── core_cmFunc.h │   │   │   └── core_cmInstr.h │   │   └── ST │   │       └── STM32F4xx │   │           ├── Include │   │           │   ├── stm32f4xx.h │   │           │   └── system_stm32f4xx.h │   │           └── Source │   │               └── Templates │   │                   └── arm │   │                       └── startup_stm32f4xx.s
これらの書類も普通は動かない.sファイルの名前には違いがあるかもしれません
修正したmainを以下に示す.c内容は簡潔になった
/**
  ******************************************************************************
  * @file    main.c 
  * @author  MCD Application Team
  * @version V1.0.0
  * @date    19-September-2011
  * @brief   Main program body
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
  ******************************************************************************
  */ 

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usbd_hid_core.h"
#include "usbd_usr.h"
#include "usbd_desc.h"

/** @addtogroup STM32F4-Discovery_Demo
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
  #if defined ( __ICCARM__ ) /*!< IAR Compiler */
    #pragma data_alignment = 4   
  #endif
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
__ALIGN_BEGIN USB_OTG_CORE_HANDLE  USB_OTG_dev __ALIGN_END;
__IO uint32_t TimingDelay;
/* Private function prototypes -----------------------------------------------*/
static uint32_t Demo_USBConfig(void);
static void Demo_Exec(void);
/* Private functions ---------------------------------------------------------*/

/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  RCC_ClocksTypeDef RCC_Clocks;
  /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
  Demo_Exec();
}

/**
  * @brief  Execute the demo application.
  * @param  None
  * @retval None
  */
static void Demo_Exec(void)
{
	  uint8_t buf[4];
		buf[0]=0;
		buf[1]=7;
		buf[2]=7;
		buf[3]=0;
    /* USB configuration */
    Demo_USBConfig();
	while(1) {
		Delay(5);
		USBD_HID_SendReport (&USB_OTG_dev, 
												 buf,
												 4);
	}
}

/**
  * @brief  Initializes the USB for the demonstration application.
  * @param  None
  * @retval None
  */
static uint32_t Demo_USBConfig(void)
{
  USBD_Init(&USB_OTG_dev,
            USB_OTG_FS_CORE_ID,
            &USR_desc, 
            &USBD_HID_cb, 
            &USR_cb);
  
  return 0;
}

/**
  * @brief  Inserts a delay time.
  * @param  nTime: specifies the delay time length, in 10 ms.
  * @retval None
  */
void Delay(__IO uint32_t nTime)
{
  TimingDelay = nTime;

  while(TimingDelay != 0);
}

/**
  * @brief  Decrements the TimingDelay variable.
  * @param  None
  * @retval None
  */
void TimingDelay_Decrement(void)
{
  if (TimingDelay != 0x00)
  { 
    TimingDelay--;
  }
}

/**
  * @brief  This function handles the test program fail.
  * @param  None
  * @retval None
  */
void Fail_Handler(void)
{
  while(1)
  {
    Delay(5);
  }
}

#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{ 
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r
", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/