Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #include "stm32f3xx.h"
  2.  
  3. int main(void)
  4. {
  5. // Initialize the HSI:
  6. RCC->CR |= RCC_CR_HSION;
  7. while(!(RCC->CR&RCC_CR_HSIRDY));
  8.  
  9. // Initialize the LSI:
  10. // RCC->CSR |= RCC_CSR_LSION;
  11. // while(!(RCC->CSR & RCC_CSR_LSIRDY));
  12.  
  13. // PLL configuration:
  14. RCC->CFGR &= ~RCC_CFGR_PLLSRC; // HSI / 2 selected as the PLL input clock.
  15. RCC->CFGR |= RCC_CFGR_PLLMUL16; // HSI / 2 * 16 = 64 MHz
  16. RCC->CR |= RCC_CR_PLLON; // Enable PLL
  17. while(!(RCC->CR&RCC_CR_PLLRDY)); // Wait until PLL is ready
  18.  
  19. // Flash configuration:
  20. FLASH->ACR |= FLASH_ACR_PRFTBE;
  21. FLASH->ACR |= FLASH_ACR_LATENCY_1;
  22.  
  23. // Main clock output (MCO):
  24. RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
  25. GPIOA->MODER |= GPIO_MODER_MODER8_1;
  26. GPIOA->OTYPER &= ~GPIO_OTYPER_OT_8;
  27. GPIOA->PUPDR &= ~GPIO_PUPDR_PUPDR8;
  28. GPIOA->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR8;
  29. GPIOA->AFR[0] &= ~GPIO_AFRL_AFRL0;
  30.  
  31. // Output on the MCO pin:
  32. //RCC->CFGR |= RCC_CFGR_MCO_HSI;
  33. //RCC->CFGR |= RCC_CFGR_MCO_LSI;
  34. //RCC->CFGR |= RCC_CFGR_MCO_PLL;
  35. RCC->CFGR |= RCC_CFGR_MCO_SYSCLK;
  36.  
  37. // PLL as the system clock
  38. RCC->CFGR &= ~RCC_CFGR_SW; // Clear the SW bits
  39. RCC->CFGR |= RCC_CFGR_SW_PLL; //Select PLL as the system clock
  40. while ((RCC->CFGR & RCC_CFGR_SWS_PLL) != RCC_CFGR_SWS_PLL); //Wait until PLL is used
  41.  
  42. // Bit-bang monitoring:
  43. RCC->AHBENR |= RCC_AHBENR_GPIOEEN;
  44. GPIOE->MODER |= GPIO_MODER_MODER10_0;
  45. GPIOE->OTYPER &= ~GPIO_OTYPER_OT_10;
  46. GPIOE->PUPDR &= ~GPIO_PUPDR_PUPDR10;
  47. GPIOE->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR10;
  48.  
  49. while(1)
  50. {
  51. GPIOE->BSRRL |= GPIO_BSRR_BS_10;
  52. GPIOE->BRR |= GPIO_BRR_BR_10;
  53.  
  54. }
  55. }
  56.  
  57. arm-none-eabi-objdump -S yourprog.elf
  58.  
  59. arm-none-eabi-gcc
  60. -O1 ## your optimization level
  61. -S ## stop after generating assembly, i.e. don't run `as`
  62. -I/path/to/CMSIS/ST/STM32F3xx/ -I/path/to/CMSIS/include
  63. test.c
  64.  
  65. .L5:
  66. ldr r2, [r3, #24]
  67. orr r2, r2, #1024
  68. str r2, [r3, #24]
  69. ldr r2, [r3, #40]
  70. orr r2, r2, #1024
  71. str r2, [r3, #40]
  72. b .L5
  73.  
  74. GPIOE->BSRRL |= GPIO_BSRR_BS_10;
  75. GPIOE->BRR |= GPIO_BRR_BR_10;
  76.  
  77. GPIOE->BSRRL = GPIO_BSRR_BS_10;
  78. GPIOE->BRR = GPIO_BRR_BR_10;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement