/*
以STM32F407为例子,为什么参数是这个
0. (SystemCoreClock / (1000U / uwTickFreq)): (表示systick的reload value)
1. SystemCoreClock 系统时钟 168000000: (1s可以计数这么多)
2. (1000U / uwTickFreq): (将1s分成1000份即1ms, 所以uwTickFreq毫秒后,触发systick中断)
3. (1000U / uwTickFreq): (1S将中断这么多次)
*/
HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq))
扩展
/*stm32f4xx_hal_cortex.c*/
/**
* @brief Initializes the System Timer and its interrupt, and starts the System Tick Timer.
* Counter is in free running mode to generate periodic interrupts.
* @param TicksNumb Specifies the ticks Number of ticks between two interrupts.
* @retval status: - 0 Function succeeded.
* - 1 Function failed.
*/
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
{
return SysTick_Config(TicksNumb);
}
/*core_cm4.h.c*/
/**
\brief System Tick Configuration
\details 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 - 1UL) > SysTick_LOAD_RELOAD_Msk)
{
return (1UL); /* Reload value impossible */
}
SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
SysTick->VAL = 0UL; /* 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 (0UL); /* Function successful */
}
/**
\brief Set Interrupt Priority
\details Sets the priority of a device specific interrupt or a processor exception.
The interrupt number can be positive to specify a device specific interrupt,
or negative to specify a processor exception.
\param [in] IRQn Interrupt number.
\param [in] priority Priority to set.
\note The priority cannot be set for every processor exception.
*/
__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
{
if ((int32_t)(IRQn) >= 0)
{
NVIC->IP[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
}
else
{
SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
}
}
对比ucosii
/*os_cpu_c.c*/
/*
*********************************************************************************************************
* INITIALIZE SYS TICK
*
* Description: Initialize the SysTick using the number of counts between two ticks.
*
* Arguments : cnts Number of SysTick counts between two OS tick interrupts.
*
* Note(s) : 1) This function MUST be called after OSStart() & after processor initialization.
*
* 2) Either OS_CPU_SysTickInitFreq or OS_CPU_SysTickInit() can be called.
*********************************************************************************************************
*/
void OS_CPU_SysTickInit (INT32U cnts)
{
INT32U prio;
INT32U basepri;
/* Set BASEPRI boundary from the configuration. */
basepri = (INT32U)(CPU_CFG_KA_IPL_BOUNDARY << (8u - CPU_CFG_NVIC_PRIO_BITS));
OS_CPU_CM_SYST_RVR = cnts - 1u; /* Set Reload register. */
/* Set SysTick handler prio. */
prio = OS_CPU_CM_SCB_SHPRI3;
prio &= 0x00FFFFFFu;
prio |= (basepri << 24u);
OS_CPU_CM_SCB_SHPRI3 = prio;
/* Enable timer. */
OS_CPU_CM_SYST_CSR |= OS_CPU_CM_SYST_CSR_CLKSOURCE |
OS_CPU_CM_SYST_CSR_ENABLE;
/* Enable timer interrupt. */
OS_CPU_CM_SYST_CSR |= OS_CPU_CM_SYST_CSR_TICKINT;
}
版权声明:本文为lzw508170827原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。