Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * startup.c
- *
- */
- 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 */
- ) ;
- }
- #include "stm32f4xx.h"
- #include "stm32f4xx_rcc.h"
- #include "stm32f4xx_gpio.h"
- int main(void) {
- GPIO_InitTypeDef GPIO_InitDef;
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
- GPIO_InitDef.GPIO_Pin = 0xFF;
- GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitDef.GPIO_OType = GPIO_OType_PP;
- GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_InitDef.GPIO_Speed = GPIO_Speed_100MHz;
- //Initialize pins
- GPIO_Init(GPIOD, &GPIO_InitDef);
- //volatile int i;
- while (1) {
- delay_ms(1000);
- GPIO_SetBits(GPIOD, GPIO_Pin_1);
- }
- }
- void delay_1us(void)
- {
- SysTick->CTRL = 0;
- SysTick->LOAD = (168-1);
- SysTick->VAL = 0;
- SysTick->CTRL = 5;
- // COUNTFLAG is a bit that is set to 1 when counter reaches 0.
- // It's automatically cleared when read.
- while ((SysTick->CTRL & 0x10000) == 0);
- SysTick->CTRL = 0;
- }
- void delay_ms(unsigned int ms){
- for(int i = 0; i < ms*1000; i++){
- delay_1us();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement