http://stm32f4-discovery.com/2014/11/overclock-stm32f4-device-up-to-250mhz/

Let’s test what STM32F4xx devices can do.

I have all “4 speed families” at home so why not to try it how fast we can go.

By default, for those who don’t know max frequencies for STM32F4xx devices, they are in list below:

  • 84MHz: STM32F401 MCUs, including Nucleo-F401 board
  • 100MHz: STM32F411 MCUs, including Nucleo F411 board
  • 168MHz: STM32F405/7 and STM32F415/17 MCUs, including STM32F4-Discovery board
  • 180MHz: STM32F427/29 and STM32F437/39 MCUs, including STM32F429-Discovery board

Ok, we have everything provided, let’s test how far we can go with PLL settings.

First we have to go through, how to set PLL parameters to even get any clock.

Step by step on how PLL works.

About PLL settings

  1. You gave him some input frequency, let’s say HSE_VALUE = 8MHz.
    Then, he divide this by PLL_M factor, that we get 1MHz in the first stage output. This means

    PLL_M = HSE_VALUE (in Hz) / 1MHz =  /  = 
  2. Then, PLL multiplies output (1MHz) with a large number, factor is called PLL_N.
    This number depends on STM32F4xx family.
    By default, for normal clocks (specified in datasheet) values are:
    1. 84MHz: PLL_N = 336
    2. 100MHz: PLL_N = 400
    3. 168MHz: PLL_N = 336
    4. 180MHz: PLL_N = 360

    Probably your question is why so strange values.
    Simple answer, STM32F4xx have different peripherals (SDIO, USB, etc)
    and some specific peripherals needs exact clock.
    If you want to have 168MHz core clock and then for USB 48MHz, this is not possible,
    because you cannot set a prescaler of 168/48 = 3.5.
    This is “no go”. For that purpose, least common value for (in this case) 168MHz and 48MHz is used, 336.

    PLL_VCO = PLL_N * (HSE_VALUE / PLL_M)
    Note:
    PLL_N parameter can be set between 192 and 432.
    At least datasheet says that but we will see that we can go more that this.
  3. Ok, we have 336MHz somewhere inside PLL now.
    Now become 2 new PLL parameters.
    1. PLL_P: This parameter is used to set system core clock for MCU.
      If you want 168MHz clock, and you have 336MHz on the input of this divider,
      you set parameter PLL_P = 2. Equation is

      SYSCLK = PLL_VCO / PLL_P = 336MHz /  = 168MHz
      1. 84MHz: PLL_P = 4
      2. 100MHz: PLL_P = 4
      3. 168MHz: PLL_P = 2
      4. 180MHz: PLL_P = 2
    2. PLL_Q: This parameter is used to set clock for special peripheral (SDIO, USB, RNG)
      to be at least about 48MHz. But this is not always possible.
      It divides the input frequency for special peripherals like PLL_P does for system core clock.
      CLOCK_48MHz = PLL_VCO / PLL_Q = 336MHz /  = 48MHz

      By default this parameter is set to 7.
      If we take a look at what happens if we have 180MHz clock and PLL_N set to 360,
      the our PLL_VCO is 360MHz and our “48MHz” clock becomes:

      CLOCK_48MHz = 360MHz /  = .7MHz
      It’s not a big problem but yeah, if we want perfect, then if we use USB/SDIO/RNG
      we can not have 180MHz for our MCU.
      We have to slow it down to 168MHz by setting PLL_N to 336.
      Someone will probably say that we can increase PLL_N to 384 and then PLL_Q to 8 and we will get

      CLOCK_48MHz = 384MHz /  = 48MHz
      This is true, but if we set PLL_N to 384, then on divide by 2 for PLL_P we have higher frequency
      than 180MHz for Core clock (384MHz / 2 = 192MHz) and this is not good now.
      Terrible  If you have 100MHz core clock, then you have PLL_N set to 400 and PLL_Q to 7,
      wow, that more than 55MHz for peripheral, not good at all.
      Even PLL_Q = 8 is too small. You need then about 8.3 prescaler but floating points in prescalers = no go.
       
  4. If we now make a full equatons for system core clock, we will get something like this:
    PLL_VCO = ((HSE_VALUE / PLL_M) * PLL_N)
    SYSTEM_CORE_CLOCK = PLL_VCO / PLL_P
    CLOCK_48MHZ = PLL_VCO / PLL_Q
  5. All these settings are set in system_stm32f4xx.c file if you use Standard Peripheral Drivers like I do.

Overclocking STM32F4xx device

To test how far I can go, I used my PWM library hich automatically sets timer period and prescaler

according to the timer’s frequency and pwm frequency you choose.

This values are stored in my working struct for PWM library.

I used this PWM output to measure actual frequency with oscilloscope.

First, I tried overclock STM32F429-Discovery board.

For first test, it was just good if I set PLL_N to higher value.

I set it to PLL_N = 400, and if we calculate this, we will get SYSCLK = 200MHz.

This is more than 180MHz so we can expect any problems. I’ve also set variable

SystemCoreClock = 200000000

to be sure my settings are OK in file.

Then I’ve started my program in debug mode and set timer settings and PWM output.

I’ve measured real 10kHz PWM output like I set.

I was still not sure if this is ok. In debug window, you can look at variables.

Like I previously said, my PWM struct stores information about timer prescaler and period.

I read from debug windows values below:

  • Period: 10000

    • Absolute value how much ticks timer has to make. Value stored in TIM’s register is Period – 1
  • Prescaler: 1
    • Absolute value to use with calculations. Value stored in TIM’s register is Prescaler – 1

It was strange for me first time, because this was not so nice result.

Then I realized, that TIM2 for PWM is connected to APB1 bus,

which clock frequency is on F429 APB1 = SYSCLK / 4

but TIM has internal PLL which increases frequency by 2,

so you get TIM2_TICK_DEFAULT = SYSCLK / 4 * 2 = SYSCLK / 2 = 100MHz.

This result is better now. because you get:

PWM_FREQ = TIMER_TICK_DEFAULT_FREQ / (Absolute_Period * Absolute_Prescaler) = 10kHz
PWM_FREQ = TIMER_TICK_DEFAULT_FREQ / ((Period_in_Register + ) * (Prescaler_in_Register + ))

So I was doing this a lot of times, trying different frequencies.

To 250MHz on STM32F429-Discovery I got frequency on my oscilloscope 10kHz and parameters for timer were valid.

So clock was really 250MHz.

For other boards, I got maximum clocks of:

  • STM32F429-Discovery; 250MHz

    • APB1 = SYSCLK / 4; TIM2 default frequency = SYSCLK / 4 * 2 = 125MHz
  • STM32F4-Discovery: 250MHz
    • APB1 = SYSCLK / 4; TIM2 default frequency = SYSCLK / 4 * 2 = 125MHz
  • Nucleo F401: 125MHz
    • APB1 = SYSCLK / 2; TIM2 default frequency = SYSCLK / 2 * 2 = 125MHz
  • Nucleo F411: 125MHz
    • APB1 = SYSCLK / 2; TIM2 default frequency = SYSCLK / 2 * 2 = 125MHz

Important notes:

  • There is no guarantee that every MCU in the series will go to the value like my did, because they are not designed for so high speed,

    • I do not suggest you that you use this in production
  • When frequency is higher than expected, MCU can become unstable and can crash or some hardfault error can happen,
    • Also, temperature rises with frequency.
  • You can blow your MCU
    • I’m not responsible for that. You are doing this on your own risk.

PLL Settings

These settings are set in system_stm32f4xx.c file

/************************* PLL Parameters *************************************/
#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
#else /* STM32F411xE */
#if defined (USE_HSE_BYPASS)
#define PLL_M 8
#else /* STM32F411xE */
#define PLL_M 16
#endif /* USE_HSE_BYPASS */
#endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx */ /* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
#define PLL_Q 7 #if defined (STM32F40_41xxx)
#define PLL_N 500
/* SYSCLK = PLL_VCO / PLL_P */
#define PLL_P 2
#endif /* STM32F40_41xxx */ #if defined (STM32F427_437xx) || defined (STM32F429_439xx)
#define PLL_N 500 /* 250MHz clock for STM32F429-Discovery board */
/* SYSCLK = PLL_VCO / PLL_P */
#define PLL_P 2
#endif /* STM32F427_437x || STM32F429_439xx */ #if defined (STM32F401xx)
#define PLL_N 500
/* SYSCLK = PLL_VCO / PLL_P */
#define PLL_P 4
#endif /* STM32F401xx */ #if defined (STM32F411xE)
#define PLL_N 500
/* SYSCLK = PLL_VCO / PLL_P */
#define PLL_P 4
#endif /* STM32F411xx */ /******************************************************************************/ /**
* @}
*/ /** @addtogroup STM32F4xx_System_Private_Macros
* @{
*/ /**
* @}
*/ /** @addtogroup STM32F4xx_System_Private_Variables
* @{
*/ #if defined (STM32F40_41xxx)
uint32_t SystemCoreClock = ;
#endif /* STM32F40_41xxx */ #if defined (STM32F427_437xx) || defined (STM32F429_439xx)
uint32_t SystemCoreClock = ; /* 250MHz clock */
#endif /* STM32F427_437x || STM32F429_439xx */ #if defined (STM32F401xx)
uint32_t SystemCoreClock = ;
#endif /* STM32F401xx */ #if defined (STM32F411xE)
uint32_t SystemCoreClock = ;
#endif /* STM32F401xx */

Main

Main program

/**
* Keil project for overclocking STM32F4xx devices
*
* Before you start, select your target, on the right of the "Load" button
*
* @author Tilen Majerle
* @email tilen@majerle.eu
* @website http://stm32f4-discovery.com
* @ide Keil uVision 5
* @packs STM32F4xx Keil packs version 2.2.0 or greater required
* @stdperiph STM32F4xx Standard peripheral drivers version 1.4.0 or greater required
*
* When you use debug, you need to print "PWM_Data" variable to see results
*/
/* Include core modules */
#include "stm32f4xx.h"
/* Include my libraries here */
#include "defines.h"
#include "tm_stm32f4_delay.h"
#include "tm_stm32f4_disco.h"
#include "tm_stm32f4_pwm.h" int main(void) {
/* Timer settings struct */
TM_PWM_TIM_t PWM_Data; /* Initialize system */
SystemInit(); /* Initialize delay */
TM_DELAY_Init(); /* Initialize leds on board */
TM_DISCO_LedInit(); /* Turn on all leds */
TM_DISCO_LedOn(LED_GREEN); /* Init Timer for PWM, TIM frequency 10kHz */
TM_PWM_InitTimer(TIM2, &PWM_Data, ); /* Initialize PWM Channel 1 on TIM2, PinsPack 2 = PA5 */
TM_PWM_InitChannel(TIM2, TM_PWM_Channel_1, TM_PWM_PinsPack_2); /* Set 70% duty cycle */
TM_PWM_SetChannelPercent(TIM2, &PWM_Data, TM_PWM_Channel_1, ); while () { }
}

Project below has settings in system_stm32f4xx.c

set to maximum frequency like I said above, so 250 and 125MHz.

Before you debug in Keil uVision, you have to rebuild. All libs are included in project.

Overclock STM32F4 device up to 250MHz的更多相关文章

  1. STM32F4 External interrupts

    STM32F4 External interrupts Each STM32F4 device has 23 external interrupt or event sources. They are ...

  2. STM32F4 HAL Composite USB Device Example : CDC + MSC

    STM32F4 USB Composite CDC + MSC I'm in the process of building a USB composite CDC + MSC device on t ...

  3. STM32F4读写内部FLASH【使用库函数】

    STM32F4Discovery开发帮使用的STM32F407VGT6芯片,内部FLASH有1M之多.平时写的代码,烧写完之后还有大量的剩余.有效利用这剩余的FLASH能存储不少数据.因此研究了一下S ...

  4. One-wire Demo on the STM32F4 Discovery Board

    One-wire Demo on the STM32F4 Discovery Board Some of the devs at work were struggling to get their s ...

  5. VGA Output from STM32F4 Discovery board

    VGA Output from STM32F4 Discovery board I love the web! There are so many cool projects out there, a ...

  6. STM32F4编程手册学习2_内存模型

    STM32F4编程手册学习2_内存模型 1. 内存映射 MCU将资源映射到一段固定的4GB可寻址内存上,如下图所示. 内存映射将内存分为几块区域,每一块区域都有一个定义的内存类型,一些区域还有一些附加 ...

  7. stm32F4中断分析-HAL库

    详细可以参考: STM32使用HAL库操作外部中断——实战操作 https://www.cnblogs.com/wt88/p/9624103.html /** ******************** ...

  8. Linux系统中的Device Mapper学习

    在linux系统中你使用一些命令时(例如nmon.iostat 如下截图所示),有可能会看到一些名字为dm-xx的设备,那么这些设备到底是什么设备呢,跟磁盘有什么关系呢?以前不了解的时候,我也很纳闷. ...

  9. 使用STM32F4的CCM内存

    使用STM32F4的CCM内存http://www.stmcu.org/module/forum/forum.php?mod=viewthread&tid=604814&fromuid ...

随机推荐

  1. Javascript - Vue - vue对象的生命周期

    vue对象的生命周期 从vue的创建到销毁会经过一系列的事件,这是vue对象的生命周期. 创建期间的生命周期函数 <div id="box">    <h3 id ...

  2. L0,L1,L2范数,正则化,过拟合

    L0范数是指向量中非0元素的个数 L1范数是向量中各个元素的绝对值求和 L2范数是指向量的各个元素平方求和然后取和的平方根 机器学习的目的是使学习到的模型不仅对已知的数据而且对未知的数据有很好的预测能 ...

  3. Eclipse 中 不能创建 Dynamic web project

    工作要涉及web开发,之前下载的java SE (我的是luna) 版本默认无法新建web项目,也就是找不到Dynamic Web ,在网上看了些解决办法,最终却是解决了问题,说到底就是安装一些用于E ...

  4. csu 1982:小M的移动硬盘(双向链表)

    Description 最近小M买了一个移动硬盘来储存自己电脑里不常用的文件.但是他把这些文件一股脑丢进移动硬盘后,觉得这些文件似乎没有被很好地归类,这样以后找起来岂不是会非常麻烦? 小M最终决定要把 ...

  5. python包管理之Pip安装及使用

    Python有两个著名的包管理工具easy_install.py和pip.在Python2.7的安装包中,easy_install.py是默认安装的,而pip需要我们手动安装. pip可以运行在Uni ...

  6. 说一下PHP中die()和exit()区别

    PHP手册:die()Equivalent to exit(). 说明:die()和exit()都是中止脚本执行函数:其实exit和die这两个名字指向的是同一个函数,die()是exit()函数的别 ...

  7. GetNumber的实现(Python & Java & Golang)

    TCO2014的编程赢取门票的题目,大致是从一个数组(大小为K),可以选取1-K个数,必须保证这n个数是从1-n,返回所有的选取方法个数. 思路:首先是得到从1开始连续的数,保存每个数的个数.然后通过 ...

  8. 搭建项目vue + vue-router + vuex + vue-i18n + element-ui + egg + sequelize

    vue + vue-router + vuex + vue-i18n + element-ui + egg + sequelize https://www.cnblogs.com/wuguanglin ...

  9. 【LOJ】#2513. 「BJOI2018」治疗之雨

    题解 具体就是列一个未知数方程\(dp[i]\)表示有\(i\)滴血的时候期望多少轮 \(dp[i] = 1 + \sum_{j = 1}^{i + 1} a_{i,j}dp[j]\) \(dp[n] ...

  10. js跨越请求的2中实现 JSONP /后端接口设置运行跨越header

    由于浏览器同源策略,a域名的js向b域名ajax请求会被禁止.JS实现跨越访问接口有2中办法. 1.后端接口设置允许跨越的header头. //header('Access-Control-Allow ...