Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void startup(void) __attribute__((naked)) __attribute__((section (".start_section")) );
- void startup ( void )
- {
- __asm volatile(
- " LDR R0,=0x2001C000\n" /* set stack */
- " MOV SP,R0\n"
- " BL main\n" /* call main */
- "_exit: B .\n" /* never return */
- ) ;
- }
- #define GPIO_E 0x40021000
- #define GPIO_E_MODER ((volatile unsigned int *) (GPIO_E))
- #define GPIO_D 0x40020C00
- #define GPIO_D_MODER ((volatile unsigned int *) (GPIO_D))
- #define GPIO_D_OTYPER ((volatile unsigned short *) (GPIO_D + 0x04))
- #define GPIO_D_PUPDR ((volatile unsigned int *) (GPIO_D + 0xC ))
- #define GPIO_D_IDR_HIGH ((volatile unsigned char *) (GPIO_D + 0x11))
- #define GPIO_D_ODR_HIGH ((volatile unsigned char *) (GPIO_D + 0x15))
- #define GPIO_D_ODR_LOW ((volatile unsigned char *) (GPIO_D + 0x14))
- #define SYSCFG_EXTICR1 0x40013808
- #define EXTI_RTSR 0x40013C0C
- #define EXTI_IMR 0x40013C00
- #define EXTI_PR ((volatile unsigned int *) (0x40013C14))
- static volatile unsigned int count = 0;
- void interrupt_handler(void) {
- if((*((unsigned int *) 0x40013C14) & 0x8) != 0) {
- count++;
- *((unsigned int *) 0x40013C14) |= 0x8;
- }
- }
- void init_app(void) {
- *GPIO_D_MODER &= 0xFFFF0000;
- *GPIO_D_MODER |= 0x00005555;
- *((unsigned int *) 0x40013808) &= ~0xF000;
- *((unsigned int *) 0x40013808) |= 0x4000;
- *((unsigned int *) 0x40013C00) |= 8;
- *((unsigned int *) 0x40013C0C) |= 8;
- *((unsigned int *) 0x40013C08) &= ~8;
- *((void (**) (void) ) 0x2001C064 ) = interrupt_handler;
- *((unsigned int *) 0xE000E100) |= (1<<9);
- }
- void main(void) {
- init_app();
- while(1) {
- *GPIO_D_ODR_LOW = count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement