STM32 系统定时器与外部中断响应级别实验测试

实验思路:

通过对比系统定时器产生中断点亮灯1后while(1)模拟忙碌,以及按键点亮灯2后while(1)模拟忙碌来对比优先级。


先通过开启自动装载寄存器触发系统定时器

SysTick_Config(SystemCoreClock / 10);

core_cm3.h
static __INLINE uint32_t SysTick_Config(uint32_t ticks)
{ 
  if (ticks > SysTick_LOAD_RELOAD_Msk)  return (1);            /* Reload value impossible */
                                                               
  SysTick->LOAD  = (ticks & SysTick_LOAD_RELOAD_Msk) - 1;      /* set reload register */
  //NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);  /* set Priority for Cortex-M0 System Interrupts */
  /*通过NVIC_SetPriority设置优先级*/
	NVIC_SetPriority (SysTick_IRQn, 1);  /* set Priority for Cortex-M0 System Interrupts */
  SysTick->VAL   = 0;                                          /* Load the SysTick Counter Value */
  SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk | 
                   SysTick_CTRL_TICKINT_Msk   | 
                   SysTick_CTRL_ENABLE_Msk;                    /* Enable SysTick IRQ and SysTick Timer */
  return (0);                                                  /* Function successful */
}

接下来查看系统定时器回调函数,那么系统回调函数在哪里呢
SMT32中文参考手册
STM32 系统定时器与外部中断响应级别实验测试_第1张图片
在启动文件startup_stm32f10x_hd.s中我们可以找到

__Vectors       DCD     __initial_sp               ; Top of Stack
                DCD     Reset_Handler              ; Reset Handler
                DCD     NMI_Handler                ; NMI Handler
                DCD     HardFault_Handler          ; Hard Fault Handler
                DCD     MemManage_Handler          ; MPU Fault Handler
                DCD     BusFault_Handler           ; Bus Fault Handler
                DCD     UsageFault_Handler         ; Usage Fault Handler
                DCD     0                          ; Reserved
                DCD     0                          ; Reserved
                DCD     0                          ; Reserved
                DCD     0                          ; Reserved
                DCD     SVC_Handler                ; SVCall Handler
                DCD     DebugMon_Handler           ; Debug Monitor Handler
                DCD     0                          ; Reserved
                DCD     PendSV_Handler             ; PendSV Handler
                DCD     SysTick_Handler            ; SysTick Handler 对应文档中这个就是系统定时器的回调

在stm32f10x_it.c系统定时回调函数中翻转LED
void SysTick_Handler(void)
{
	/*翻转LED查看效果,定时时间尽量长一些*/
	//LED0_TROGGLE;
}

剩下的代码可参考:STM32外部中断响应级别实验测试

你可能感兴趣的:(STM32)