cancel
Showing results for 
Search instead for 
Did you mean: 

Question about Clock speed, PWM frequency, and UART buffers for STM32F4xx

spyguy99
Associate II
Posted on May 09, 2012 at 06:17

Like the title says I have a few questions about, all for the STM32F4xx series micro.

1. How can I set the micro to use an 8 MHz external crystal to achieve the maximum clock rate of 168 MHz. I have tried using the clock configuration excel spread sheet but I haven't gotten it to work correctly. 

2. How can I set the PWM output frequency? Right now I've only been able to get a maximum of 16KHz output. I need to get this up to 20KHz+ and out of the audible range. 

3. I have a lot of control data coming in over the UART in the form of a big array of unsigned chars. I can read in one character at a time fine, but is there any way I can read the array, encapsulated with start and end chars, into one big serial buffer then parse out the parts I need? 
2 REPLIES 2
Posted on May 09, 2012 at 13:53

1. How can I set the micro to use an 8 MHz external crystal to achieve the maximum clock rate of 168 MHz. I have tried using the clock configuration excel spread sheet but I haven't gotten it to work correctly.

I'm not sure why you'd need excel, this is just some basic math, hitting certain frequencies depends on your choice of inputs, and dividers. The STM32F4 Discovery uses and 8MHz external crystal.

*-----------------------------------------------------------------------------
* System Clock source | PLL (HSE)
*-----------------------------------------------------------------------------
* SYSCLK(Hz) | 168000000
*-----------------------------------------------------------------------------
* HCLK(Hz) | 168000000
*-----------------------------------------------------------------------------
* AHB Prescaler | 1
*-----------------------------------------------------------------------------
* APB1 Prescaler | 4
*-----------------------------------------------------------------------------
* APB2 Prescaler | 2
*-----------------------------------------------------------------------------
* HSE Frequency(Hz) | 8000000
*-----------------------------------------------------------------------------
* PLL_M | 8
*-----------------------------------------------------------------------------
* PLL_N | 336
*-----------------------------------------------------------------------------
* PLL_P | 2
*-----------------------------------------------------------------------------
* PLL_Q | 7
*-----------------------------------------------------------------------------

#define HSE_VALUE 8000000
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
#define PLL_M 8
#define PLL_N 336
/* SYSCLK = PLL_VCO / PLL_P */
#define PLL_P 2
/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
#define PLL_Q 7

2. How can I set the PWM output frequency? Right now I've only been able to get a maximum of 16KHz output. I need to get this up to 20KHz+ and out of the audible range. Look at your Prescale and Period values against TIMCLK, want high frequencies then drop the Prescale. Just do some factoring. PWMOUTFREQ = TIMCLK / (Prescale * Period) TIM_Prescaler = Prescale - 1; TIM_Period = Period - 1; 3. I have a lot of control data coming in over the UART in the form of a big array of unsigned chars. I can read in one character at a time fine, but is there any way I can read the array, encapsulated with start and end chars, into one big serial buffer then parse out the parts I need? Use DMA on the USART Rx, and monitor the DMA pointers.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jlchoobs
Associate II
Posted on June 15, 2012 at 14:45

Important Note / Correction :

* If you are using a 8MHz Crystal - like on the Stm32F4Discovery Board,

- then make sure that PLL_M is changed from 25 to 8 ;

#define    PLL_M    8

- Otherwise, the Timing will be wrong - like 56MHz instead of your desired 168MHz !