STM32F407 CubeIDE

问题描述 投票:0回答:1

systick 无法工作。

我尝试简单地从其内存寄存器启用系统控制杆:

    uint32_t *pSCSR = (uint32_t*)0xE000E010;

    //do some settings
    *pSCSR |= ( 1 << 2);  //Indicates the clock source, processor clock source
    *pSCSR |= ( 1 << 1); //Enables SysTick exception request:
    
    //enable the systick
    *pSCSR |= ( 1 << 0); //enables the counter

我已经尝试了上面的代码,但它没有调用 systick 处理程序,如下所示:

void SysTick_Handler(void){
    printf("--------------systick handler----------\n");
}
c arm stm32 cortex-m
1个回答
0
投票
    uint32_t *pSCSR = (uint32_t*)0xE000E010;

    //do some settings
    *pSCSR |= ( 1 << 2);  //Indicates the clock source, processor         clock source
    *pSCSR |= ( 1 << 1); //Enables SysTick exception request:

    //enable the systick
    *pSCSR |= ( 1 << 0); //enables the counter

在当前配置中从其内存寄存器启用 SysTick 不会设置 SysTick 重载值寄存器/SysTick 当前值寄存器/SysTick 校准值寄存器。

您可以简单地设置 SysTick 配置:

 #define _IOM volatile // Read/write structure member permission
 #define _OM  volatile  // Write only structure member permission
 #define _IM  volatile   // Read only structure member permission

 #define SCR_BASE        (0xE000E000UL) // system control base address
 #define SysTick_offset  (0x010UL)
 #define SysTick_BASE    (SCR_BASE + SysTick_offset)

 typedef struct {
    _IOM uint32_t SCSR;
    _IOM uint32_t SRVR;
    _IOM uint32_t SCVR;
    _IM  uint32_t SCALIB;
 } SysTick_Type;

 #define SysTick ( (SysTick_Type*) SysTick_BASE) 

// 1ms interrupt at 16MHz clock
#define SYSTICK_LOAD_VAL ((16000000 / 1000) - 1)  

// configure SysTick 
SysTick->SRVR = SYSTICK_LOAD_VAL;
SysTick->SCVR = 0;

//do some settings
SysTick->SCSR |= ( 1 << 2);  //Indicates the clock source, processor         clock source
SysTick->SCSR |= ( 1 << 1); //Enables SysTick exception request:

//enable the systick
SysTick->SCSR |= ( 1 << 0); //enables the counter

如果您的 SysTick 计时器仍未触发处理程序,请仔细检查数据表并确保没有其他配置无意中全局禁用 SysTick 或中断。

© www.soinside.com 2019 - 2024. All rights reserved.