-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclocks.c
33 lines (27 loc) · 912 Bytes
/
clocks.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "stm32f10x.h" // Device header
#include "clocks.h"
void Clocks_Init(void)
{
/*
Description:
Initializes all required peripheral clocks.
Parameters:
None
Return:
None
*/
while( (RCC->CR & RCC_CR_HSIRDY) != RCC_CR_HSIRDY ); //wait for internal oscillator to be stable
RCC->CFGR &= ~RCC_CFGR_SW; //use internal oscillator as system clock
RCC->CFGR &= ~RCC_CFGR_PPRE1; //No APB1 prescaler, run it at 8MHz
RCC->CR &= ~RCC_CR_PLLON; //disable PLL
RCC->CR &= ~RCC_CR_HSEON; //disable external oscillator
//enable clock for DMA1
RCC->AHBENR |= RCC_AHBENR_DMA1EN;
//enable clock access for GPIOA, GPIOB, USART1, ADC1, ADC2, AFIO
RCC->APB2ENR |= (RCC_APB2ENR_IOPAEN |
RCC_APB2ENR_IOPBEN |
RCC_APB2ENR_USART1EN |
RCC_APB2ENR_ADC1EN |
RCC_APB2ENR_ADC2EN |
RCC_APB2ENR_AFIOEN);
}