daily pastebin goal
85%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void startup(void) __attribute__((naked)) __attribute__((section (".start_section")) );
  2.  
  3. void startup ( void )
  4. {
  5. __asm volatile(
  6.     " LDR R0,=0x2001C000\n"     /* set stack */
  7.     " MOV SP,R0\n"
  8.     " BL main\n"                /* call main */
  9.     "_exit: B .\n"              /* never return */
  10.     ) ;
  11. }
  12.  
  13. #define GPIO_E 0x40021000
  14. #define GPIO_E_MODER        ((volatile unsigned int   *)    (GPIO_E))
  15.  
  16. #define GPIO_D  0x40020C00
  17. #define GPIO_D_MODER        ((volatile unsigned int *)      (GPIO_D))
  18. #define GPIO_D_OTYPER       ((volatile unsigned short *)    (GPIO_D + 0x04))
  19. #define GPIO_D_PUPDR        ((volatile unsigned int   *)    (GPIO_D + 0xC ))
  20.  
  21. #define GPIO_D_IDR_HIGH     ((volatile unsigned char  *)    (GPIO_D + 0x11))           
  22. #define GPIO_D_ODR_HIGH     ((volatile unsigned char  *)    (GPIO_D + 0x15))
  23. #define GPIO_D_ODR_LOW      ((volatile unsigned char *)     (GPIO_D + 0x14))
  24.  
  25. #define SYSCFG_EXTICR1  0x40013808
  26. #define EXTI_RTSR       0x40013C0C
  27. #define EXTI_IMR        0x40013C00
  28. #define EXTI_PR             ((volatile unsigned int *)      (0x40013C14))
  29.  
  30. static volatile unsigned int count = 0;
  31.  
  32. void interrupt_handler(void) {
  33.     if((*((unsigned int *) 0x40013C14) & 0x8) != 0) {
  34.         count++;
  35.         *((unsigned int *) 0x40013C14) |= 0x8;
  36.     }
  37. }
  38.  
  39. void init_app(void) {
  40.     *GPIO_D_MODER &= 0xFFFF0000;
  41.     *GPIO_D_MODER |= 0x00005555;
  42.    
  43.     *((unsigned int *) 0x40013808) &= ~0xF000;
  44.     *((unsigned int *) 0x40013808) |=  0x4000;
  45.  
  46.    
  47.     *((unsigned int *) 0x40013C00)  |=  8;
  48.     *((unsigned int *) 0x40013C0C)  |=  8;
  49.     *((unsigned int *) 0x40013C08)  &= ~8;
  50.        
  51.     *((void (**) (void) ) 0x2001C064 ) = interrupt_handler;
  52.      
  53.     *((unsigned int *) 0xE000E100) |= (1<<9);
  54. }
  55.  
  56. void main(void) {
  57.     init_app();
  58.     while(1) {
  59.         *GPIO_D_ODR_LOW = count;
  60.     }
  61. }
RAW Paste Data
Top