最近一直在研读正点原子的stm32开发板,在学习SysTick寄存器的过程中查不到该寄存器的地址是在哪里定义的,很是不解。上网搜后发现 http://www.eepw.com.cn/article/246289.htm
部分代码粘贴如下:
typedef struct
{
__IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
__IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
__IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
__I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
} SysTick_Type; //声明一个SysTick_Type型的结构体。
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base
Address */
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
CTRL_TICKINT_Set是一个宏定义,定义如下
/* CTRL TICKINT Mask */
#define CTRL_TICKINT_Set ((u32)0x00000002)
#define CTRL_TICKINT_Reset ((u32)0xFFFFFFFD)
上面代码中定义一个SysTick_Type类型的结构体实例SysTick,而从根本上来说这是一个地址,
就是STM32芯片内部分配给滴答时钟的实际地址0xE000E000UL+0x0010UL。SysTick->CTRL |= CTRL_TICKINT_Set;
就是给地址0xE000E000+0x0010 +0x000赋一个0x00000002的值,对应滴答时钟的CTRL寄存器的第2位置1
。即为开启中断的意思。 在该文中有详细的说明,个人觉得事实也本应是这样的,可是在我的core_cm3.h头文件中却找不到对SysTick寄存器定义相应的地址
========================================================================
/** rief Structure type to access the System Timer (SysTick).
*/
typedef struct
{
__IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
__IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
__IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
__I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
} SysTick_Type;
/* SysTick Control / Status Register Definitions */
#define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
#define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
#define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
#define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
#define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */
/* SysTick Reload Register Definitions */
#define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */
/* SysTick Current Register Definitions */
#define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */
/* SysTick Calibration Register Definitions */
#define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
#define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
#define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */
/*@} end of group CMSIS_SysTick */
上面代码中却怎么也找不到SysTick 寄存器地址的定义,黄天不负有心人,最终还是找到了,
原来在正点原子提供的代码中,把所有的寄存器的结构体定义完之后,统一给各个寄存器定义了地址,
该定义在所有结构体定义的后面。代码如下:
------------------------------------------------------------------------
/* Memory mapping of Cortex-M3 Hardware */
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */
#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */
#define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */
#define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */
#define SysTick_BASE (SCS_BASE+0x0010UL) /*!< SysTick Base Address */
#define NVIC_BASE (SCS_BASE +0x0100UL) /*!< NVIC Base Address */
#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control
Block Base Address #define SCnSCB ((SCnSCB_Type*) SCS_BASE ) /!< System control Register not in SCB /
#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
#define ITM ((ITM_Type *)ITM_BASE) /*!< ITM configuration struct */
#define DWT ((DWT_Type *) DWT_BASE) /*!< DWT configuration struct */
#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct
#define CoreDebug ((CoreDebug_Type ) eDebug_BASE)/!< Core Debug configuration struct
#if (__MPU_PRESENT == 1)***define MPU_BASE (SCS_BASE + 0x0D90UL) /!< Memory Protection Unit */
#define MPU ((MPU_Type ) MPU_BASE )/!< Memory Protection Unit */
#endif
/@} /
“`
这里定义了详细代码,但个人觉得这种定义可读性不是很强,没有前面的定义直观。对初学者是一种考验。Ok
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』