document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  * Startup code of firmware
  3.  */
  4. #include "stm32f10x.h"
  5. #include "core_cm3.h"
  6. #include "main.h"
  7. void SystemInit(void);
  8. void main(void);
  9. /* provided by linker script */
  10. extern unsigned long _estack;
  11. /* reset handler */
  12. void Reset_Handler(void) {
  13.     SystemInit();
  14.     main();
  15. }
  16. /* NMI interrupt */
  17. void NMI_Handler(void) {
  18.     if (RCC->CIR & RCC_CIR_CSSF) {
  19.         /* fail led blink enabled */
  20.         TIM3->CCR3 = 100;
  21.         /* reset CSSC flag */
  22.         RCC->CIR |= RCC_CIR_CSSC;
  23.     }
  24. }
  25. /* EXTI line0 interrupt */
  26. void EXTI_L0_Handler(void) {
  27.     if (EXTI->PR & (1 << 0)) {
  28.         volatile static int pll_mul = 0;
  29.         /* change multiply for PLL */
  30.         if (pll_mul > (4 << 18))
  31.             pll_mul = 0;
  32.         else
  33.             pll_mul += (1 << 18);
  34.         /* if enable HSI CSS enabled, return */
  35.         if ((RCC->CFGR & RCC_CFGR_SWS) == RCC_CFGR_SWS_HSI)
  36.             return;
  37.         /* switch to HSI and wait for stable*/
  38.         RCC->CFGR &= ~RCC_CFGR_SW;
  39.         while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI);
  40.         /* disable PLL and wait for off */
  41.         RCC->CR &= ~RCC_CR_PLLON;
  42.         while ((RCC->CR & RCC_CR_PLLRDY) == 1);
  43.         /* setup PLL, enable and wait to ready */
  44.         RCC->CFGR &= ~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL);
  45.         RCC->CFGR |= (RCC_CFGR_PLLSRC_PREDIV1 | pll_mul);
  46.         RCC->CR |= RCC_CR_PLLON;
  47.         while ((RCC->CR & RCC_CR_PLLRDY) == 0);
  48.         /* select PLL for system clock and wait to select */
  49.         RCC->CFGR &= ~RCC_CFGR_SW;
  50.         RCC->CFGR |= RCC_CFGR_SW_PLL;
  51.         while ((RCC->CFGR & RCC_CFGR_SWS_PLL) == 0);
  52.         /* reset EXTI flag */
  53.         EXTI->PR |= (1 << 0);
  54.     }
  55.    
  56. }
  57. /* table of Cortex vectors */
  58. void *vector_table[] __attribute__ ((section(".vectors"))) = {
  59.     &_estack,
  60.     Reset_Handler,      /*!#0 cortex-m3 reset interrupt begin code of this */
  61.     NMI_Handler,        /*!#1 cortex-m3 non maskable interrupt */
  62.     0,                  /*!#2 cortex-m3 hardware fault interrupt */
  63.     0,                  /*!#3 cortex-m3 memory management interrupt */
  64.     0,                  /*!#4 cortex-m3 bus fault interrupt */
  65.     0,                  /*!#5 cortex-m3 usage fault interrupt */
  66.     0,                  /*!#6 reserved */
  67.     0,                  /*!#7 reserved */
  68.     0,                  /*!#8 reserved */
  69.     0,                  /*!#9 reserved */
  70.     0,                  /*!#10 cortex-m3 system service interrupt */
  71.     0,                  /*!#11 cortex-m3 debug monitor interrupt */
  72.     0,                  /*!#12 reserved */
  73.     0,                  /*!#13 cortex-m3 penable request for system service interrupt */
  74.     0,                  /*!#14 cortex-m3 system tick timer interrupt */
  75.     0,                  /*!%0 window watchdog interrupt */
  76.     0,                  /*!%1 PVD through EXTI line detection interrupt */
  77.     0,                  /*!%2 tamper adn timestamp through EXTI interrupt */
  78.     0,                  /*!%3 RTC wakeup through EXTI interrupt */
  79.     0,                  /*!%4 flash global interrupt */
  80.     0,                  /*!%5 RCC global interrupt */
  81.     EXTI_L0_Handler,    /*!%6 EXTI line0 interrupt */
  82.     0,                  /*!%7 EXTI line1 interrupt */
  83.     0,                  /*!%8 EXTI line2 interrupt */
  84.     0,                  /*!%9 EXTI line3 interrupt */
  85.     0,                  /*!%10 EXTI line4 interrupt */
  86.     0,                  /*!%11 DMA1 channel 1 global interrupt */
  87.     0,                  /*!%12 DMA1 channel 2 global interrupt */
  88.     0,                  /*!%13 DMA1 channel 3 global interrupt */
  89.     0,                  /*!%14 DMA1 channel 4 global interrupt */
  90.     0,                  /*!%15 DMA1 channel 5 global interrupt */
  91.     0,                  /*!%16 DMA1 channel 6 global interrupt */
  92.     0,                  /*!%17 DMA1 channel 7 global interrupt */
  93.     0,                  /*!%18 ADC1 global interrupt */
  94.     0,                  /*!%19 reserved */
  95.     0,                  /*!%20 reserved */
  96.     0,                  /*!%21 reserved */
  97.     0,                  /*!%22 reserved */
  98.     0,                  /*!%23 EXTI line[9:5] interrupts */
  99.     0,                  /*!%24 TIM1 break and TIM15 global interrupt */
  100.     0,                  /*!%25 TIM1 update and TIM16 global interrupt */
  101.     0,                  /*!%26 TIM1 trigger and commutation and TIM17 global interrupt */
  102.     0,                  /*!%27 TIM1 capture compare interrupt */
  103.     0,                  /*!%28 TIM2 global interrupt */
  104.     0,                  /*!%29 TIM3 global interrupt */
  105.     0,                  /*!%30 TIM4 global interrupt */
  106.     0,                  /*!%31 I2C1 event interrupt */
  107.     0,                  /*!%32 I2C1 error interrupt */
  108.     0,                  /*!%33 I2C2 event interrupt */
  109.     0,                  /*!%34 I2C2 error interrupt */
  110.     0,                  /*!%35 SPI1 global interrupt */
  111.     0,                  /*!%36 SPI2 global interrupt */
  112.     0,                  /*!%37 USART1 global interrupt */
  113.     0,                  /*!%38 USART2 global interrupt */
  114.     0,                  /*!%39 USART3 global interrupt */
  115.     0,                  /*!%40 EXTI line[15:10] interrupts */
  116.     0,                  /*!%41 RTC alarm through EXTI line interrupt */
  117.     0,                  /*!%42 HDMI-CEC interrupt */
  118.     0,                  /*!%43 reserved */
  119.     0,                  /*!%44 reserved */
  120.     0,                  /*!%45 reserved */
  121.     0,                  /*!%46 reserved */
  122.     0,                  /*!%47 reserved */
  123.     0,                  /*!%48 reserved */
  124.     0,                  /*!%49 reserved */
  125.     0,                  /*!%50 reserved */
  126.     0,                  /*!%51 reserved */
  127.     0,                  /*!%52 reserved */
  128.     0,                  /*!%53 reserved */
  129.     0,                  /*!%54 TIM6 and DAC underrun interrupt */
  130.     0,                  /*!%55 TIM7 interrupt */
  131. };
');