F407_06_标准库开发

1

2



1> 概述

2> 下载链接

➕------------------------------------➕
🔗 StM32F407ZGT6 固件库
➕------------------------------------➕

1

帮助文档:
"stm32f4xx_dsp_stdperiph_lib_um.chm"
编程时,可对库函数概览;

3> 文件简介

3.1> CPU文件

ARM公司为CPU编写的描述和操作代码:

 /* CMSIS Cortex-M4 Core Peripheral Access Layer Header File */
"core_cm4.h"            

 /* CMSIS Cortex-M Core Instruction Access Header File  */                
"core_cmInstr.h"   

/* CMSIS Cortex-M Core Function Access Header File */         
"core_cmFunc.h"      
   
/* Compiler specific SIMD Intrinsics  */    
"core_cmSimd.h"

/* standard types definitions  */
"stdint.h" //在安装目录下            

3.2> MCU文件

/* MCU启动文件 */
"startup_stm32f40xx.s"

/* 时钟初始化 */
"system_stm32f4xx.h"
"system_stm32f4xx.c"

/* CMSIS Cortex-M4 Device Peripheral Access Layer Header File. 
This file contains:
> all the peripheral register's definitions, 
> bits definitions,
> memory mapping */
"stm32f4xx.h"

/* 外设驱动文件 */
"stm32f4xx_gpio.h"
"stm32f4xx_gpio.c"
"stm32f4xx_rcc.h"
"stm32f4xx_rcc.C"
...
"stm32f4xx_ppp.h"
"stm32f4xx_ppp.C"

/* 配置外设驱动文件 */
"stm32f4xx_conf.h"

3.3> 头文件包含关系

112

4> 标准库修改

4.1> 修改外部晶振

Step 1> stm32f4xx.h

/*修改HSE_VALUE 指定频率  */
#if defined(STM32F40_41xxx)  || defined(STM32F427_437xx)  || \
	defined(STM32F429_439xx) || defined(STM32F401xx)      || \
    defined(STM32F410xx)     || defined(STM32F411xE)      || \
    defined(STM32F469_479xx)
    
 	#if !defined  (HSE_VALUE) 
 		 #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
 	#endif /* HSE_VALUE */
 	
#elif defined (STM32F412xG) || defined(STM32F413_423xx) || defined(STM32F446xx)

	#if !defined  (HSE_VALUE) 
 		 #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
	#endif /* HSE_VALUE */
 	
#endif

Step 2> system_stm32f4xx.c

/*修改PLL_M 为:指定频率/100000 */

#if defined(STM32F40_41xxx)  || defined(STM32F427_437xx) || \
	defined(STM32F429_439xx) || defined(STM32F401xx)     || \
	defined(STM32F469_479xx)
	
 	/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
 	#define PLL_M      8
 
#elif defined(STM32F412xG) || defined(STM32F413_423xx) || defined (STM32F446xx)
 	#define PLL_M      8
 
#elif defined (STM32F410xx) || defined (STM32F411xE)
	#if defined(USE_HSE_BYPASS)
  		#define PLL_M      8    
 	#else /* !USE_HSE_BYPASS */
 	
 		#define PLL_M      16
	#endif /* USE_HSE_BYPASS */
#else
	
#endif 

Step 3> 调试仿真的时钟频率
1

4.2> 修改stm32f4xx_conf.h

"stm32f4xx_conf.h"
/* 注释掉不需要的 */

//#include "stm32f4xx_adc.h"
//#include "stm32f4xx_crc.h"
//#include "stm32f4xx_dbgmcu.h"
//#include "stm32f4xx_dma.h"
//#include "stm32f4xx_exti.h"
//#include "stm32f4xx_flash.h"
#include "stm32f4xx_gpio.h"

5> 标准库代码规范

5.1> 头文件

/**
  ******************************************************************************
  * @file    
  * @author  
  * @version 
  * @date    
  * @brief  
  *          
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */


/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TEMPLATE_H
#define __TEMPLATE_H

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"

/* Exported types ------------------------------------------------------------*/
"数据类型声明"
例如
typedef struct
{
  uint32_t GPIO_Pin;              
  GPIOMode_TypeDef GPIO_Mode;     
  GPIOSpeed_TypeDef GPIO_Speed;   
  GPIOOType_TypeDef GPIO_OType;   
  GPIOPuPd_TypeDef GPIO_PuPd;    
}GPIO_InitTypeDef;



/* Exported constants --------------------------------------------------------*/
"常量定义"

/* Exported macro ------------------------------------------------------------*/

"宏函数"
例如:#define MAX(a, b) ((a) > (b) ? (a) : (b))

/* Exported functions --------------------------------------------------------*/ 

#endif /* __TEMPLATE_H */


/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/


5.2> C文件

/**
  ******************************************************************************
  * @file    
  * @author  
  * @version 
  * @date    
  * @brief  
  *          
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */


/* Includes ------------------------------------------------------------------*/
#include "template.h"

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/

/* Private functions ---------------------------------------------------------*/


/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM32F407标准库中的USB CDC (Communication Device Class)用于在STM32微控制器和计算机之间建立虚拟的串行通信连接。USB CDC支持基于文本和二进制的数据传输,可以在计算机上使用终端模拟器或其他串口通信工具来与STM32F407进行通信。 使用USB CDC,可以实现STM32F407与计算机之间的实时双向通信。在STM32中,需要通过配置USB外设为CDC设备,并实现相应的回调函数来处理来自计算机的命令和数据。STM32F407的USB CDC库提供了相关的函数和数据结构,以简化配置和操作的过程。 首先,需要在工程中添加USB CDC库文件,并在代码中包含对应的头文件。接着,需要配置相应的GPIO和时钟以启用USB的功能。然后,通过调用库函数配置USB外设为CDC设备并进行初始化。 在USB CDC设备初始化完成后,可以通过调用相关函数来处理USB连接和传输的事件。例如,可以通过设置回调函数来处理接收到的数据或将数据发送到计算机。可以使用库函数来读取并处理计算机发送的数据并作出响应。 当STM32F407与计算机建立了USB CDC连接后,可以使用终端模拟器或其他串口通信工具来与STM32进行通信。可以通过发送和接收文本或二进制数据来实现双向通信。 在开发过程中,需要仔细配置和处理USB CDC相关的设置和事件,以确保正常的通信和数据传输。同时,也需要了解USB CDC的协议规范以便正确地配置和操作USB外设。 总之,STM32F407标准库中的USB CDC功能提供了一种方便的方式,在STM32微控制器和计算机之间建立虚拟的串行通信连接。通过适当的配置和操作,可以实现实时的双向通信。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值