Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Main code of firmware
- */
- #include "stm32f10x.h"
- #include "core_cm3.h"
- #include "main.h"
- void main();
- /* Main function */
- void main(void) {
- /* setup i/o port c */
- RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
- LED_PORT->CRH &= ~(GPIO_CRH_CNF8 | GPIO_CRH_CNF9);
- LED_PORT->CRH |= GPIO_CRH_CNF8_1 | GPIO_CRH_CNF9_1;
- LED_PORT->CRH |= GPIO_CRH_MODE8_0 | GPIO_CRH_MODE9_0;
- /* setup i/o port a */
- RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_AFIOEN;
- /* setup AFIO andEXTI */
- AFIO->EXTICR[0] |= AFIO_EXTICR1_EXTI0_PA;
- EXTI->IMR |= (1 << 0);
- EXTI->FTSR |= (1 << 0);
- /* remap TIM3 to pc6..9 pins port C */
- AFIO->MAPR |= AFIO_MAPR_TIM3_REMAP_FULLREMAP;
- /* setup TIM3 counter */
- RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
- TIM3->PSC = 8000 - 1;
- TIM3->ARR = 1000;
- /* setup TIM3 compare block */
- /** setup CC3..4 as output */
- TIM3->CCMR2 &= ~(TIM_CCMR2_CC3S | TIM_CCMR2_CC4S);
- /** setup CC3..4 to togle if compare */
- TIM3->CCMR2 |= TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2;
- /** setup value to compare registers 3..4 */
- if (RCC->CSR & RCC_CSR_PINRSTF) {
- TIM3->CCR3 = 1000;
- RCC->CSR &= ~RCC_CSR_PINRSTF;
- }
- else
- TIM3->CCR3 = 500;
- if (RCC->CSR & RCC_CSR_SFTRSTF) {
- TIM3->CCR4 = 1000;
- TIM3->CCR3 = 500;
- RCC->CSR &= ~RCC_CSR_SFTRSTF;
- }
- else
- TIM3->CCR4 = 500;
- RCC->CSR |= RCC_CSR_RMVF;
- /** setup channels 3..4 to corresponding output pin */
- TIM3->CCER |= TIM_CCER_CC3E | TIM_CCER_CC4E;
- /* enable TIM3 */
- TIM3->CR1 |= TIM_CR1_CEN;
- /* enable EXTI0 interrupt */
- NVIC_EnableIRQ(EXTI0_IRQn);
- /* infinity loop */
- while (1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement