
本帖最后由 xnmc2013 于 2017-4-8 22:52 编辑 之前一直在用SysTick的定时功能,有时为了一些功能想改变它的中断优先等级,可是找不到有什么函数可以改变。论坛里一位前辈在他的QQ群里,发过一篇F1的改变SysTick的中断的方法,看了之后也是一头雾水。这几天静下心来,仔细看各个手册关于SysTick的说明,今天测试了一下,终于可以解决了,再反过来想那位前辈的方法,才觉得是一样的。 在RM0360( STM32F030x4/6/8/C and STM32F070x6/B参考手册)里,有这样的说明 ![]() 这里是说,SysTick的中断优先级是6,?????并且可以改变。通过追踪SysTick的设置函数 if (SysTick_Config(SystemCoreClock / 10000)) 里面的SysTick_Config,我们找到在030标准库的里的core_cm0.h文件里有这样一段代码: /* ################################## SysTick function ############################################ */ /** \ingroup CMSIS_Core_FunctionInterface \defgroup CMSIS_Core_SysTickFunctions SysTick Functions \brief Functions that configure the System. @{ */ #if (__Vendor_SysTickConfig == 0) /** \brief System Tick Configuration The function initializes the System Timer and its interrupt, and starts the System Tick Timer. Counter is in free running mode to generate periodic interrupts. \param [in] ticks Number of ticks between two interrupts. \return 0 Function succeeded. \return 1 Function failed. \note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b> must contain a vendor-specific implementation of this function. */ __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) { if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */ SysTick->LOAD = ticks - 1; /* set reload register */ NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt */ 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 */ } #endif /*@} end of CMSIS_Core_SysTickFunctions */ ****************************************************************************************************** 这里面关键是 NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt */----------------这行代码 我们通过改变(1<<__NVIC_PRIO_BITS) - 1的值,就可以改变SysTick的中断优先级了。追踪__NVIC_PRIO_BITS,他的值是2,将1左移2位后减1为3就是SysTick的中断优先级了。但是参考手册中标明了SysTick的中断优先级是6啊,和算出来的3是不一样的?并且F0的优先级只有0~3可以设置,那么参考手册的6级优先级是怎么回事呢?查了各种数据手册和参考手册都是写的6,仔细考虑后,我觉得即便对某种型号的MCU的参考手册也是描述的通用M0内核的情况,针对具体情况,F030的中断优先级只有0~3可以设置,那么标准库里就将SysTick的中断优先级设置为最低的了。当然这只是我的自己的理解,有机会再听ST工程师讲座时,我一定要问明白。 至于关于SysTick基础上的一些延时函数,比较简单,这里就不介绍了。 希望这里简单的说明,能够帮助一些像我一样的菜鸟~~~~~~~· |
(1<<__NVIC_PRIO_BITS) - 1;怎么是6呢? |
太感謝了,謝謝分享 |