Tutorial 4 - Clock Frequency

STM32F4Discovery Tutorial 4 - Clock Frequency

This is the fourth video tutorial on the tutorial series on stm32f4discovery board. In this tutorial we will understand about clock frequency. We will learn what is meant by clock frequency. How clock frequency is related to speed of microcontroller. What are crystal oscillators. How program execution speed depends on clock frequency. We will then see what is the current speed of our stm32f4discovery board. How we can change that speed. Then finally we will modify the code written in previous tutorial and learn how to write code for selecting a particular clock frequency.

#include "stm32f4xx.h"

GPIO_InitTypeDef GPIO_LED;

void Delay(__IO uint32_t nCount)
{       while(nCount--)
        {
        }
}

int main(void)
{
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  GPIO_LED.GPIO_Pin = GPIO_Pin_12;
  GPIO_LED.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_LED.GPIO_OType = GPIO_OType_PP;
  GPIO_LED.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOD, &GPIO_LED);

  while (1)
  {
          GPIO_WriteBit(GPIOD, GPIO_Pin_12, Bit_SET);
          Delay(16800000);
          GPIO_WriteBit(GPIOD, GPIO_Pin_12, Bit_RESET);
          Delay(16800000);
  }
}
//system_stm32f4xx.c
//In this file change the PLL_M parameter value to 8 like this :

#define PLL_M      8
//stm32f4xx.h
//In this file change the HSE_VALUE to 8000000 like this :

#if !defined  (HSE_VALUE)
  #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */