cancel
Showing results for 
Search instead for 
Did you mean: 

Keil, initial clock configuration.

guitardenver
Associate II
Posted on November 10, 2012 at 21:01

I'm writing my own USART code to work with USART1. I need to know what the start-up code that keil gives you sets the clock initially at. I can change it manually but id like to know where the code is. Also USART1 is running off of APB2 clock, how do I figure out what the clock speed is so I can figure out what I should write in the USART_BRR register? 

As I understand it, APBx clock comes from the system clock (HSI,HSE,PLL), then through AHB prescaler (if is has one) then through the APBx prescaler. Is this correct? 

I would like to edit the keil start up code to enable the HSI with PLL to make system clock 168Mhz, then have APB2 clock run at 12Mhz (There is a table for BRR register at this speed). 

I'm using the system_stm32f4xx.c and startup_stm32f4xx.c.

Thanks for the advise.

#initial-clock #usart1-clock
4 REPLIES 4
guitardenver
Associate II
Posted on November 10, 2012 at 23:37

I figured it out. Just needed a little more time. Moderators feel free to delete this post.

Posted on November 11, 2012 at 01:58

We don't tend to get things deleted around here, and it might show up in a forum or external search.

In case anyone happens upon the thread, the CMSIS implementation typically calls the SystemInit() function prior to main(), or CRT startup code, from startup_stm32f4xx.s.

SystemInit() resides in system_stm32fxx.c, along with all the PLL and clock settings and configuration code.

For clocks you can either manually decode RCC register content, and extrapolate via HSE_VALUE, or knowing HSI is 16 MHz.

Or you can us library functions like

  RCC_ClocksTypeDef RCC_ClocksStatus;

  RCC_GetClocksFreq(&RCC_ClocksStatus);

Where

typedef struct

{

  uint32_t SYSCLK_Frequency; /*!<  SYSCLK clock frequency expressed in Hz */

  uint32_t HCLK_Frequency;   /*!<  HCLK clock frequency expressed in Hz */

  uint32_t PCLK1_Frequency;  /*!<  PCLK1 clock frequency expressed in Hz */

  uint32_t PCLK2_Frequency;  /*!<  PCLK2 clock frequency expressed in Hz */

}RCC_ClocksTypeDef;

Subject: Keil, initial clock configuration.

I'm writing my own USART code to work with USART1. I need to know what the start-up code that keil gives you sets the clock initially at. I can change it manually but id like to know where the code is. Also USART1 is running off of APB2 clock, how do I figure out what the clock speed is so I can figure out what I should write in the USART_BRR register? 

As I understand it, APBx clock comes from the system clock (HSI,HSE,PLL), then through AHB prescaler (if is has one) then through the APBx prescaler. Is this correct? 

I would like to edit the keil start up code to enable the HSI with PLL to make system clock 168Mhz, then have APB2 clock run at 12Mhz (There is a table for BRR register at this speed). 

I'm using the system_stm32f4xx.c and startup_stm32f4xx.c.

Thanks for the advise.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
guitardenver
Associate II
Posted on November 11, 2012 at 10:05

I have a question about those libraries though.

I downloaded STM32F4xx_DSP_StdPeriph_Lib_V1.0.1. How do I use these? I've tried and it seems that I have to include the .c file and the .h file has to be in my project directory. Also if I include stm32f4xx_usart.h I have to include the .c file for everything that it uses also. Where do I put these files so that I can just type #include ''stm32f4xx_usart.h'' and be able to use the library? 

Posted on November 11, 2012 at 13:40

The much older libraries allowed you to build them separately and bring in via .h, .a or .lib. With the CMSIS releases you drop everything in the project (not the directory, you add by browsing to the library source directories). Within the project you need add metadata down in the options to point to include file directories you need the compiler to find later. You also need to add in define setting for the compiler.

You would probably want to dig into the example/template projects in the MDK-ARM directories. Creating a project in Keil from scratch can be a challenge to get all the details straight, sometimes it makes more sense to clone an existing project and trim/add as appropriate.

STM32F4xx_DSP_StdPeriph_Lib_V1.0.0\Project\STM32F4xx_StdPeriph_Templates\MDK-ARM

All the peripheral include files are generally pulled in via the configuration file within the project

STM32F4xx_StdPeriph_Templates\stm32f4xx_conf.h

You could trim it down to what you need, and only add the files you need, but often it is easier to bring it all in and let the linker do dead code elimination.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..