SHARE
TWEET

Untitled

a guest Sep 20th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  *  startup.c
  3.  *
  4.  */
  5. void startup(void) __attribute__((naked)) __attribute__((section (".start_section")) );
  6.  
  7. void startup ( void )
  8. {
  9. __asm volatile(
  10.     " LDR R0,=0x2001C000\n"     /* set stack */
  11.     " MOV SP,R0\n"
  12.     " BL main\n"                /* call main */
  13.     "_exit: B .\n"              /* never return */
  14.     ) ;
  15. }
  16.  
  17. #include "stm32f4xx.h"
  18. #include "stm32f4xx_rcc.h"
  19. #include "stm32f4xx_gpio.h"
  20.  
  21. int main(void) {
  22.    
  23.    
  24.    
  25.    
  26.     GPIO_InitTypeDef GPIO_InitDef;
  27.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  28.  
  29.     GPIO_InitDef.GPIO_Pin = 0xFF;
  30.     GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT;
  31.     GPIO_InitDef.GPIO_OType = GPIO_OType_PP;
  32.     GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_NOPULL;
  33.     GPIO_InitDef.GPIO_Speed = GPIO_Speed_100MHz;
  34.     //Initialize pins
  35.     GPIO_Init(GPIOD, &GPIO_InitDef);
  36.  
  37.  
  38.     //volatile int i;
  39.     while (1) {
  40.             delay_ms(1000);
  41.             GPIO_SetBits(GPIOD, GPIO_Pin_1);
  42.     }
  43. }
  44.  
  45. void delay_1us(void)
  46. {
  47.     SysTick->CTRL = 0;
  48.     SysTick->LOAD = (168-1);
  49.     SysTick->VAL = 0;
  50.     SysTick->CTRL = 5;
  51.  
  52.     // COUNTFLAG is a bit that is set to 1 when counter reaches 0.
  53.     // It's automatically cleared when read.
  54.     while ((SysTick->CTRL & 0x10000) == 0);
  55.     SysTick->CTRL = 0;
  56. }
  57.  
  58. void delay_ms(unsigned int ms){
  59.     for(int i = 0; i < ms*1000; i++){
  60.         delay_1us();
  61.     }
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top