最近因为可能要重启一个项目,会用到STM32作为主控,要使用ST官方的标准外设库来进行编程。以前接触过STM32,但是没有做过这么大的工程,所以学得很浅显,现在决定重新把标准外设库的结构弄明白一点,方便以后使用。
在stm32f10x.h中编程思路大概是这样子的:
头文件最前面是关于内存保护单元啊
00155 #ifdef STM32F10X_XL
00156 #define __MPU_PRESENT 1 /*!< STM32 XL-density devices provide an MPU */
00157 #else
00158 #define __MPU_PRESENT 0 /*!< Other STM32 devices does not provide an MPU */
00159 #endif /* STM32F10X_XL */
00133 * @brief STM32F10x Standard Peripheral Library version number
00134 */
00135 #define __STM32F10X_STDPERIPH_VERSION_MAIN (0x03) /*!< [31:24] main version */
00136 #define __STM32F10X_STDPERIPH_VERSION_SUB1 (0x05) /*!< [23:16] sub1 version */
00137 #define __STM32F10X_STDPERIPH_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
00138 #define __STM32F10X_STDPERIPH_VERSION_RC (0x00) /*!< [7:0] release candidate */
00139 #define __STM32F10X_STDPERIPH_VERSION ( (__STM32F10X_STDPERIPH_VERSION_MAIN << 24)\
00140 |(__STM32F10X_STDPERIPH_VERSION_SUB1 << 16)\
00141 |(__STM32F10X_STDPERIPH_VERSION_SUB2 << 8)\
00142 |(__STM32F10X_STDPERIPH_VERSION_RC))
晶振单元啊之类的地方(感觉这部分是弱定义,好像不会执行什么)
00115 #if !defined HSE_VALUE
00116 #ifdef STM32F10X_CL
00117 #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
00118 #else
00119 #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
00120 #endif /* STM32F10X_CL */
00121 #endif /* HSE_VALUE */
随后定义了cortex-CM3以及STM32必有得中断通道号码
00167 typedef enum IRQn
00168 {
00169 /****** Cortex-M3 Processor Exceptions Numbers ***************************************************/
00170 NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
00171 MemoryManagement_IRQn = -12, /*!< 4 Cortex-M3 Memory Management Interrupt */
00172 BusFault_IRQn = -11, /*!< 5 Cortex-M3 Bus Fault Interrupt */
00173 UsageFault_IRQn = -10, /*!< 6 Cortex-M3 Usage Fault Interrupt */
00174 SVCall_IRQn = -5, /*