You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

STM32L476RG CubeIDE项目中SystemCoreClockUpdate()函数未识别求助

问题解决:编译器无法识别SystemCoreClockUpdate()函数

关键解决动作

  • 包含正确的头文件:你需要在代码里添加#include "system_stm32l4xx.h",而不是你之前用的system_stm32xx.h。这个头文件里明确声明了SystemCoreClockUpdate()的函数原型,是编译器能识别该函数的前提。
  • 确认源文件已加入编译:光加头文件路径没用,得把定义函数的system_stm32l4xx.c文件也加到项目的编译列表里——不然编译器能找到声明,但链接阶段会找不到函数的实际实现。

修正后的代码示例

#include "stm32l476xx.h"
#include "uart.h"
#include <stdint.h>
#include <stdio.h>
// 补上正确的头文件
#include "system_stm32l4xx.h"

void SystemClockConfig(void);
void DelayS(uint32_t seconds);

volatile uint32_t tick;
volatile uint32_t _tick;

int main(void) {

    SystemClockConfig();
    while(1)
    {
        printf("hello");
        DelayS(1);
    }
}

void SystemClockConfig(void) {
    SystemCoreClockUpdate();
    SysTick_Config(SystemCoreClock / 100U);
    __enable_irq();
}

void SysTick_Handler(void) {
    ++tick;
}
uint32_t getTick(void) {
    __disable_irq();
    _tick = tick;
    __enable_irq();
    return _tick;
}

void DelayS(uint32_t seconds) {
    seconds *= 100;
    uint32_t temp = getTick();
    while ((getTick() - temp) < seconds) {
    }

}

额外检查项

  • 确认CMSIS/Device/ST/STM32L4xx/Include路径下确实存在system_stm32l4xx.h,且项目的包含路径配置无误。
  • 如果用的是STM32CubeIDE这类工具,检查项目的Core/Src目录里有没有system_stm32l4xx.c,没有的话手动添加进去。

内容的提问来源于stack exchange,提问作者Raed Banneni

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 20:12:18