GlobLib
HAL and API libraries for MCUs and hardware.

This module contains low level functions modifying clock parameters. More...

Files

file  stm32f103cb_clock.h
 Header file for stm32f103 CLOCK.
 

Enumerations

Functions

mcu_error CLOCK_setSpeed (clock_option option)
 Set the final clock speed of the device. More...
 
uint32_t CLOCK_getSpeed (void)
 Get the current clock speed of the device. More...
 
uint32_t CLOCK_getSpeedAlternate (void)
 Get the current clock speed of the alternate bus. More...
 

Detailed Description

This module contains low level functions modifying clock parameters.

The STM32f1 has a maximum clock speed of 72MHz for external oscillator and 64MHz for intenal.

By default, on startup, the clock is set to internal oscillator with 8MHz frequency.

Note
Clock switching needs to be done before any extra peripheral clocks are used!
Author
Stuart Ianna
Version
0.1
Date
June 2018
Warning
None
Bug:
Switching between all clock options doesn't work well.
  • Switch from internal ocsillator 64Mhz to a lower speed doesn't work
Todo:
Add option for setting clock back to default option.
Compilers
  • arm-none-eabi-gcc (15:4.9.3+svn231177-1) 4.9.3 20150529 (prerelease)
Example Usage
#include <coms128.h>
#include <mpu6050.h>
//Create a data structure for the device
MPU6050 mpu;
int main(void)
{
//This should be done before other peripherals are set up
//Serial communications
COMS(USART_1);
//Print out clock freuqency
prints("Clock speed =");
printl(CLOCK_getSpeed());
//Done
while (1);
return 0;
}

Enumeration Type Documentation

Clock configuration available for MCU.

This doesn't represent all clock options available, further options can be utalised with libopencm3 firmware

Enumerator
CLOCK_IN_OUT_64 

Internal oscillator, multiplied to 64MHz final.

CLOCK_IN_OUT_48 

Internal oscillator, multiplied to 48MHz final.

CLOCK_IN_OUT_24 

Internal oscillator, multiplied to 24MHz final.

CLOCK_EX_8_OUT_24 

External 8MHz oscillator, multiplied to 24MHz final.

CLOCK_EX_8_OUT_72 

External 8MHz oscillator, multiplied to 72MHz final.

Definition at line 54 of file stm32f103cb_clock.h.

Function Documentation

uint32_t CLOCK_getSpeed ( void  )

Get the current clock speed of the device.

Returns
The current speed of the ahp1 bus. (Clock frequency)

Definition at line 57 of file stm32f103cb_clock.c.

uint32_t CLOCK_getSpeedAlternate ( void  )

Get the current clock speed of the alternate bus.

Returns
The current speed of the ahp2 bus. (Usuall Clock frequency/2)

Definition at line 63 of file stm32f103cb_clock.c.

mcu_error CLOCK_setSpeed ( clock_option  option)

Set the final clock speed of the device.

If this function isn't used, the default internal oscillator, 8Mhz

Parameters
optionThe clock speed option to use defined by clock_option
Returns
Error number as defined in mcu_error, E_CLOCK_NOSPEED if clock option doesn't exist.

Definition at line 19 of file stm32f103cb_clock.c.