stm32f4xx 单片机,采用外部晶振,晶振频率 8M,需要将晶振频率参数设置在软件中。
看到:stm32f4xx.h 文件中,涉及此处的内容为:
/**
* @brief In the following line adjust the value of External High Speed oscillator (HSE)
used in your application
Tip: To avoid modifying this file each time you need to use different HSE, you
can define the HSE value in your toolchain compiler preprocessor.
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
那么我们需要定义一个预编译宏 HSD_VALUE 来设置我们使用的 8M 频率参数,否则,将使用 stm32f4xx.h 中这里设置的 25M 频率,这样会使得程序下载下去后由于时钟同步问题根本无法运行。
最简单的做法,就是在工程的编译参数页面设置这个宏:
在 C/C++ Preprocessor Symbols 中,Define框里面,添加: HSE_VALUE=8000000