After STM32F407 25M external crystal instead undetectable chip solution

Problem Description

Share STM32F4 crystal frequency before encountered a problem, resulting in single-chip solutions crash. After using a new development board F4, punctual atoms STM32F407 project template code directly used, pin configuration correctly downloaded to the external crystal to the development board 25MHz, LED does not flash, serial no output, the microcontroller directly crash, debugger detection less than chips.

problem analysis

Prior wrote an article: the STM32 serial print garbled output solutions , the F103 is garbled because the external crystal frequency 12M, 8M and programs do not correspond, resulting in garbled serial port and the timer is not accurate, but the microcontroller does not crash , the program can also be downloaded properly, the solution is very simple, just change the external high-speed clock frequency (HSE_VALUE) program and the multiplication factor (RCC_CFGR_PLLMULL6) can be, and this situation looks like now F407 and F103 are the same as before the problem also the problem of the crystal frequency allocation, but this is a direct crash, microcontroller did not work. Now development board crystal frequency is 25M, and the punctual atoms boards crystal frequency is 8M, the problem should be the result. In the Templates section "Punctuality atomic F407 Developer's Guide" in the new construction, the official firmware library default crystal frequency is 25MHz, to adapt the board 8M crystal, modify the following two parameters:

stm32f4xx.h file

if !defined (HSE_VALUE)

define HSE_VALUE ((uint32_t)8000000) /!< Value of the External oscillator in Hz /

system_stm32f4xx.c file

if defined (STM32F40_41xxx) || defined (STM32F427_437xx) || defined (STM32F429_439xx) || defined (STM32F401xx)

/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */

define PLL_M 8

So the solution is simple, only need to modify the program in the crystal frequency and the multiplication factor can be.

Solution

Know the source of the problem, the solution is very simple, just need to modify the values ​​of two or more macros can be.

This involves the calculation STM32F4 master clock, the master clock source of the first PLL clock via a time division factor of the divider M, and N through multiplication factor of frequency multiplier out after the need to go through a divider factor P (a first output PLLP) or Q (a second output PLLQ) after division of the frequency divider, and finally generate the final master clock PLL. The formula is:

PLL = HSE_VALUE * N / (M*P)

8M CRYSTAL:

PLL = HSE_VALUE * N / (MP) = 8M 336 /(8*2) = 168MHz

25M CRYSTAL:

PLL = HSE_VALUE * N / (MP) = 25M 336 /(25*2) = 168MHz

Therefore 25M crystal corresponding HSE_VALUE = 25000000 or, PLL_M = 25 , modify the program in

stm32f4xx.h file 122 lines:

if !defined (HSE_VALUE)

define HSE_VALUE ((uint32_t)25000000) /!< Value of the External oscillator in Hz

system_stm32f4xx.c file 316 lines:

if defined (STM32F40_41xxx) || defined (STM32F427_437xx) || defined (STM32F429_439xx) || defined (STM32F401xx)

/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */

define PLL_M 25

After editing, re-compile the project, normal, or should not detect the chip debugger, the program can not be downloaded, so in order to save the crash of chip re-download the program. We need a program before downloading, press and hold the reset button does not release, then click on the download button, such as one second, then release the reset button, so you can go download the program running, Amazing!

Recommended reading:


My blog: www.wangchaochao.top

Or micro-channel scan code of the public concerned about my number

Guess you like

Origin www.cnblogs.com/whik/p/11407678.html