#ifndef __STM32F10x_H//如果没有定义__STM32F10x_H ,则定义__STM32F10x_H
#define __STM32F10x_H
#ifdef __cplusplus//
extern "C" {
#endif
这里是一种条件编译。extern "C"指令非常有用,因为C和C++的近亲关系。注意:extern "C"指令中的C,表示的一种编译和连接规约,而不是一种语言。C表示符合C语言的编译和连接规约的任何语言,如Fortran、assembler等。
还有要说明的是,extern "C"指令仅指定编译和连接规约,但不影响语义。例如在函数声明中,指定了extern "C",仍然要遵守C++的类型检测、参数转换规则。
#if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD) && !defined (STM32F10X_HD_VL) && !defined (STM32F10X_XL) && !defined (STM32F10X_CL)
#endif
STM32启动文件选择:
- startup_stm32f10x_ld_vl.s: for STM32 Low density Value line devices - startup_stm32f10x_ld.s: for STM32 Low density devices - startup_stm32f10x_md_vl.s: for STM32 Medium density Value line devices - startup_stm32f10x_md.s: for STM32 Medium density devices - startup_stm32f10x_hd.s: for STM32 High density devices - startup_stm32f10x_xl.s: for STM32 XL density devices - startup_stm32f10x_cl.s: for STM32 Connectivity line devices
cl:互联型产品,stm32f105/107系列
vl:超值型产品,stm32f100系列
xl:超高密度产品,stm32f101/103系列
ld:低密度产品,FLASH小于64K
md:中等密度产品,FLASH=64 or 128
hd:高密度产品,FLASH大于128
#if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD) && !defined (STM32F10X_HD_VL) && !defined (STM32F10X_XL) && !defined (STM32F10X_CL)
#error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)"
#endif 如果设备类型选择不正确,这里会报错的。
#if !defined USE_STDPERIPH_DRIVER
#endif
#if !defined HSE_VALUE
#ifdef STM32F10X_CL
#define HSE_VALUE ((uint32_t)25000000)
#else
#define HSE_VALUE ((uint32_t)8000000)
#endif
#endif
①、HSI是高速内部时钟,RC振荡器,频率为8MHz。 ②、HSE是高速外部时钟,可接石英/陶瓷谐振器,或者接外部时钟源,频率范围为4MHz~16MHz。
③、LSI是低速内部时钟,RC振荡器,频率为40kHz。
④、LSE是低速外部时钟,接频率为32.768kHz的石英晶体。
⑤、PLL为锁相环倍频输出,其时钟输入源可选择为HSI/2、HSE或者HSE/2。倍频可选择为2~16倍,但是其输出频率最大不得超过72MHz。
#define HSE_STARTUP_TIMEOUT ((uint16_t)0x0500)
高速外部时钟启动时间
#define HSI_VALUE ((uint32_t)8000000)
外部时钟设置的值
#define __STM32F10X_STDPERIPH_VERSION_MAIN (0x03)
#define __STM32F10X_STDPERIPH_VERSION_SUB1 (0x05)
#define __STM32F10X_STDPERIPH_VERSION_SUB2 (0x00)
#define __STM32F10X_STDPERIPH_VERSION_RC (0x00)
#define __STM32F10X_STDPERIPH_VERSION ( (__STM32F10X_STDPERIPH_VERSION_MAIN << 24)\
|(__STM32F10X_STDPERIPH_VERSION_SUB1 << 16)\
|(__STM32F10X_STDPERIPH_VERSION_SUB2 << 8)\
|(__STM32F10X_STDPERIPH_VERSION_RC))
#ifdef STM32F10X_XL
#define __MPU_PRESENT 1
#else
#define __MPU_PRESENT 0
#endif
#define __NVIC_PRIO_BITS 4
#define __Vendor_SysTickConfig 0
typedef enum IRQn
{
NonMaskableInt_IRQn = -14,
MemoryManagement_IRQn = -12,
BusFault_IRQn = -11,
UsageFault_IRQn = -10,
SVCall_IRQn = -5,
DebugMonitor_IRQn = -4,
PendSV_IRQn = -2,
SysTick_IRQn = -1,
typedef enum IRQn typedef enum表示定义了一个枚举型的数据结构,你可以用题目中的 IRQn 去定义变量
{系统异常ID:
标号
中断ID
描述
NonMaskableInt_IRQn
-14
不可屏蔽中断
MemoryManagement_IRQn
-12
Cortex-M3内存管理中断
BusFault_IRQn
-11
Cortex-M3 总线Fault中断
UsageFault_IRQn
-10
Cortex-M3 用法Fault 中断
SVCall_IRQn
-5
Cortex-M3 SV Call中断
DebugMonitor_IRQn
-4
Cortex-M3 调试监视中断
PendSV_IRQn
-2
Cortex-M3 Pend SV中断
SysTick_IRQn
-1
Cortex-M3 系统Tick中断
外设中断ID:
标号中断ID描述标号中断ID描述
WDT_IRQn0看门狗EINT3_IRQn21外中断3
TIMER0_IRQn1定时器0ADC_IRQn22AD转换
TIMER1_IRQn2定时器1BOD_IRQn23欠压检测
TIMER2_IRQn3定时器2USB_IRQn24USB
TIMER3_IRQn4定时器3CAN_IRQn25CAN
UART0_IRQn5UART0DMA_IRQn26通用DMA
UART1_IRQn6UART1I2S_IRQn27I2S
UART2_IRQn7UART2ENET_IRQn28以太网
UART3_IRQn8UART3MCI_IRQn29SD/MMC卡I/F
PWM1_IRQn9PWM1MCPWM_IRQn30电机控制PWM
I2C0_IRQn10I2C0QEI_IRQn31正交编码接口
I2C1_IRQn11I2C1PLL1_IRQn32PLL1锁存
I2C2_IRQn12I2C2USBActivity_IRQn33USB活动
Reserved0_IRQn13保留CANActivity_IRQn34CAN活动
SSP0_IRQn14SSP0UART4_IRQn35UART4
SSP1_IRQn15SSP1SSP2_IRQn36SSP2
PLL0_IRQn16PLL0锁存LCD_IRQn37LCD
RTC_IRQn17RTCGPIO_IRQn38GPIO
EINT0_IRQn18外中断0PWM0_IRQn39PWM0
EINT1_IRQn19外中断1EEPROM_IRQn40EEPROM
EINT2_IRQn20外中断2
CMSIS中的中断定义
NonMaskableInt_IRQn = -14,
MemoryManagement_IRQn = -12,
BusFault_IRQn = -11,
UsageFault_IRQn = -10,
SVCall_IRQn = -5,
DebugMonitor_IRQn = -4,
PendSV_IRQn = -2,
SysTick_IRQn = -1,
WWDG_IRQn = 0,
PVD_IRQn = 1,
TAMPER_IRQn = 2,
RTC_IRQn = 3,
FLASH_IRQn = 4,
RCC_IRQn = 5,
EXTI0_IRQn = 6,
EXTI1_IRQn = 7,
EXTI2_IRQn = 8,
EXTI3_IRQn = 9,
EXTI4_IRQn = 10,
DMA1_Channel1_IRQn = 11,
DMA1_Channel2_IRQn = 12,
DMA1_Channel3_IRQn = 13,
DMA1_Channel4_IRQn = 14,
DMA1_Channel5_IRQn = 15,
DMA1_Channel6_IRQn = 16,
DMA1_Channel7_IRQn = 17,
#ifdef STM32F10X_LD
ADC1_2_IRQn = 18,
USB_HP_CAN1_TX_IRQn = 19,
USB_LP_CAN1_RX0_IRQn = 20,
CAN1_RX1_IRQn = 21,
CAN1_SCE_IRQn = 22,
EXTI9_5_IRQn = 23,
TIM1_BRK_IRQn = 24,
TIM1_UP_IRQn = 25,
TIM1_TRG_COM_IRQn = 26,
TIM1_CC_IRQn = 27,
TIM2_IRQn = 28,
TIM3_IRQn = 29,
I2C1_EV_IRQn = 31,
I2C1_ER_IRQn = 32,
SPI1_IRQn = 35,
USART1_IRQn = 37,
USART2_IRQn = 38,
EXTI15_10_IRQn = 40,
RTCAlarm_IRQn = 41,
USBWakeUp_IRQn = 42
#endif
#ifdef STM32F10X_LD_VL
ADC1_IRQn = 18,
EXTI9_5_IRQn = 23,
TIM1_BRK_TIM15_IRQn = 24,
TIM1_UP_TIM16_IRQn = 25,
TIM1_TRG_COM_TIM17_IRQn = 26,
TIM1_CC_IRQn = 27,
TIM2_IRQn = 28,
TIM3_IRQn = 29,
I2C1_EV_IRQn = 31,
I2C1_ER_IRQn = 32,
SPI1_IRQn = 35,
USART1_IRQn = 37,
USART2_IRQn = 38,
EXTI15_10_IRQn = 40,
RTCAlarm_IRQn = 41,
CEC_IRQn = 42,
TIM6_DAC_IRQn = 54,
TIM7_IRQn = 55
#endif