Hello everyone! Current post is based on clock control on stm32f4discovery post. Now, after some of new material has been read on the topic, I’m going to switch to the recommended maximum frequency of stm32f407 system clock - 168 MHz.
That’s easy enough. I’m going just to modify the init_clock routine from previous example by adding some configuration:
- Flash: the higher the frequency the more clock cycles CPU needs to wait for flash reaction. There is a table in user manual, page 80 from which the value of this parameter can be taken. In our case it is 6 cycles or 5 so called “wait states”. The FLASH_ACR registry holds this parameter.
- Power controller: to operate on 168 MHz the MC need voltage controller enabled and the voltage mode scale 1 to be selected. This is done on PWR_CR register.
- The peripherals have clock frequency limits for normal operation. For high speed devices on APB2 it is 84 MHz and for low speed on APB1 - 42 MHz. So we need to set apropriate prescaling factors on RCC_CFGR register. They are 168 / 84 = 2 and 168 / 42 = 4 respectively.
- Finally we configure, enable and select the main PLL as the source of a system clock. The output signal frequency of main PLL is calculated in such a way:
fout = (fin * N / M) / P
Where fin - is 8 MHz from HSE with external crystal, it is convenient to take M value the same as the fin and equal 8 in our case, P - takes minimum of 2
So, N = 168 * 2 = 336. All these factors are set in RCC_PLLCFGR register.
Please, checkout the code for details:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
The executable is available to download.
Feel free to post your questions.