You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
50 lines
1.5 KiB
/*
|
|
* system_timer.c
|
|
*
|
|
* Created on: Dec 6, 2017
|
|
* Author: maximilian
|
|
*/
|
|
|
|
//--------------Includes-----------------
|
|
|
|
#include <stm32f10x.h>
|
|
#include <stm32f10x_flash.h>
|
|
#include <stm32f10x_rcc.h>
|
|
#include "porting.h"
|
|
|
|
void initClock(void)
|
|
{
|
|
/* Configure all clocks to max for best performance.
|
|
If there are EMI, power, or noise problems, try slowing the clocks.*/
|
|
|
|
/* First set the flash latency to work with our clock.
|
|
000 Zero wait state, if 0 MHz < SYSCLK <= 24 MHz
|
|
001 One wait state, if 24 MHz < SYSCLK <= 48 MHz
|
|
010 Two wait states, if 48 MHz < SYSCLK <= 72 MHz */
|
|
FLASH_SetLatency(FLASH_Latency_1);
|
|
|
|
/* Start with HSI (High-Speed Internal) clock with 16 MHz (internal RC circuit),
|
|
* divide by 2 and multiply by 9 to get maximum allowed frequency: 72 MHz.
|
|
* Enable PLL, wait till it's stable, then select it as system clock.*/
|
|
RCC_DeInit();
|
|
RCC_HSICmd(ENABLE);
|
|
RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_9);
|
|
RCC_PLLCmd(ENABLE);
|
|
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) != SET) {}
|
|
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
|
|
|
|
/* Set HCLK, PCLK1, and PCLK2 to SCLK. */
|
|
RCC_HCLKConfig(RCC_SYSCLK_Div1);
|
|
RCC_PCLK1Config(RCC_HCLK_Div8);
|
|
RCC_PCLK2Config(RCC_HCLK_Div8);
|
|
|
|
/* Configure Cortex-M System Tick Timer to tick as the os user defined.*/
|
|
SystemCoreClockUpdate(); // Update SystemCoreClock, which holds the freq. in Hz
|
|
SysTick_Config( (SystemCoreClock/1000) * SYS_TICK_PERIOD_MS);
|
|
}
|
|
|
|
void SysTick_Handler(void)
|
|
{
|
|
// TODO: For porting use another timer here to call the scheduler.
|
|
osRunScheduler();
|
|
}
|
|
|