May 20, 2015

STM ARM Cortex-M3 Clock


The microcontroller clock is the key to do anything, because everything is based and works due the clock signal. So understand the clock is vital to work with any microcontroller. Here you can take a look in the STM ARM Cortex-M3 clock and how to analyze the instructions time using the Keil uVision IDE simulator.

From the SMT32F103C8T6 datasheet we know:

And below:

System clock selection is performed on startup, however the internal RC 8 MHz oscillator is
selected as default CPU clock on reset.

But how can it reaches 72 Mhz if has just a 8 Mhz internal oscillator? this is done using a technique called PLL (Phase-locked Loop), which can multiply this 8 Mhz input clock and output a higher clock, achieving the 72 Mhz as maximum frequency.

Now we know that the default clock is 72 Mhz, which is the same of 13,88 nanoseconds, because frequency (hertz) = 1 / time (seconds). So let's check this in the simulator, go to project options:


 Tab "Target" and set the clock as 8 Mhz:


Now we can use the nop assembly instruction, that do nothing, but uses 1 clock cycle, allowing us to see if it really spend 13,88 nanoseconds per clock cycle. The code is simple, just go to the package manager:


And select "Startup":


Now create the "main.c" file with this content:

#include <stm32f10x.h>

volatile uint32_t msTicks;

int main()
{ 
 SystemInit();
 
 __asm{NOP} //1 cycle ~= 13,88 nanoseconds
 __asm{NOP}
 __asm{NOP}
 __asm{NOP}
 __asm{NOP}
 
}

Set a breakpoint (F9) at the first nop and debug the code! The video below show how to see the instruction time using the "performance analyzer":



Due the "performance analyzer" precision of 1 us, we see 13,88 nanoseconds (0,01388 us) as 0,014 us !

That's all, now try with a delay function!

About the versions
  • Keil uVision 5.11.1.0
  • ARM Cortex-M3 STM32F103C8T6
Download

0 comentários :

Post a Comment