新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > stm32 學習筆記 systick定時器

        stm32 學習筆記 systick定時器

        作者: 時間:2016-11-13 來源:網絡 收藏
        開發STM32,遇到一些簡單的需要計時的任務,比如延時等,最方便的是其提供的systick。

        systick其實本為移植操作系統提供滴答時鐘的方便。

        本文引用地址:http://www.104case.com/article/201611/316276.htm

        前兩天再次接觸STM32,使用了V3.5的庫,突然發現繁瑣的Systick用法被簡化成一句話。

        即:

        void SysTick_Configuration(void)
        {
        if (SysTick_Config(SystemCoreClock / 1000000))//72, 1us per tick
        {
        /* Capture error */
        while (1);
        }
        }

        而Systick_Config函數已經取代了之前所有的設置過程。

        systick.c文件也被簡除,該函數直接歸在了內核文件core_cm3.h里面。

        /* ################################## SysTick function ############################################ */

        #if (!defined (__Vendor_SysTickConfig)) || (__Vendor_SysTickConfig == 0)

        /**
        * @brief Initialize and start the SysTick counter and its interrupt.
        *
        * @param ticks number of ticks between two interrupts
        * @return 1 = failed, 0 = successful
        *
        * Initialise the system tick timer and its interrupt and start the
        * system tick timer / counter in free running mode to generate
        * periodical interrupts.
        */
        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 */
        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

        優點是設置相當簡化,

        缺點是控制不如以前靈活了,一旦開啟,確實沒有庫函數方便地重載或禁用。



        關鍵詞: stm32systick定時

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 襄樊市| 泰安市| 巫溪县| 忻城县| 陆良县| 苏尼特右旗| 调兵山市| 禹城市| 策勒县| 昆山市| 思南县| 黔南| 赤峰市| 晋州市| 化德县| 泰州市| 临江市| 顺义区| 嘉义市| 卢龙县| 故城县| 克拉玛依市| 庆元县| 延寿县| 邢台市| 同心县| 宜都市| 桦南县| 甘肃省| 台州市| 武功县| 兰溪市| 雅安市| 原平市| 平舆县| 得荣县| 湾仔区| 苏尼特左旗| 桂林市| 桃园市| 鞍山市|