forked from ScaryTea/STM32F103
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwm.c
27 lines (24 loc) · 772 Bytes
/
pwm.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
#include "stm32f1xx.h"
#include "led.h"
int main() {
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
MODIFY_REG(GPIOA->CRL,
GPIO_CRL_CNF0 | GPIO_CRL_MODE0 | GPIO_CRL_CNF1 | GPIO_CRL_MODE1
| GPIO_CRL_CNF2 | GPIO_CRL_MODE2,
GPIO_CRL_CNF0_1 | GPIO_CRL_MODE0_1 | GPIO_CRL_CNF1_1 | GPIO_CRL_MODE1_1
| GPIO_CRL_CNF2_1 | GPIO_CRL_MODE2_1);
SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);
TIM2->PSC = 0;
TIM2->ARR = 99;
TIM2->CCR1 = 50;
CLEAR_BIT(TIM2->CCMR1, TIM_CCMR1_CC1S);
SET_BIT(TIM2->CCMR1, 0x6 << TIM_CCMR1_OC1M_Pos);
SET_BIT(TIM2->CCMR1, TIM_CCMR1_OC1PE);
TIM2->CR1 |= TIM_CR1_ARPE;
TIM2->EGR |= TIM_EGR_UG;
TIM2->CR1 |= TIM_CR1_CEN;
SET_BIT(TIM2->CCER, TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E);
led_init();
while(1);
}