├── 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.
*
*
© COPYRIGHT 2011 STMicroelectronics
******************************************************************************
*/
/* 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\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
上一篇:STM32 延时函数高级用法分析
下一篇:stm32f4使用Systick实现延时
推荐阅读最新更新时间:2024-03-16 16:00