Gpio Operation for stm32f407

Source: Internet
Author: User

/*
#include "Stm32f4_discovery.h"
#include "stm32f4xx_conf.h"


uint32_t Gb_timingdelay;
void Delay (uint32_t ntime);

void Main ()
{
Systick_config (systemcoreclock/1000); Set Systemtick one millisecond interrupt
Rcc->ahb1enr |= 0x00000008; Enable Gpiod clock
Rcc->apb2enr |= (1<<14); Enable Syscfg clock
Gpiod->moder &= 0x00ffffff; Setting the pd12,13,14,15 output
Gpiod->moder |= 0x55000000;
Gpiod->otyper &= 0xffff0fff; Setting pd12,13,14,15 push-Pull output
Gpiod->ospeedr &= 0x00ffffff; pd12,13,14,15 Speed 100m
Gpiod->ospeedr |= 0xff000000;
SYSCFG-&GT;CMPCR = 0x00000001; Using the IO compensation Unit,
Consider using this setting when the Gpio speed exceeds 50M
GPIOD-&GT;PUPDR &= 0x00ffffff; pd12,13,14,15 no pull-up no pull-down
Gpiod->bsrrh = 0xf000; Reset register Gpiox_bsrrh, write only
Set register GPIOX_BSRRL, write only

while (1)
{
Gpiod->bsrrh = 0xf000;
GPIOD-&GT;BSRRL = 0x1000;
Delay (100);
Gpiod->bsrrh = 0xf000;
GPIOD-&GT;BSRRL = 0x1000<<1;
Delay (100);
Gpiod->bsrrh = 0xf000;
GPIOD-&GT;BSRRL = 0x1000<<2;
Delay (100);
Gpiod->bsrrh = 0xf000;
GPIOD-&GT;BSRRL = 0x1000<<3;
Delay (100);
}
}

void Delay (uint32_t ntime)
{
Gb_timingdelay = Ntime;
while (Gb_timingdelay! = 0);
}
void Systick_handler (void)
{
if (gb_timingdelay! = 0x00)
{
gb_timingdelay--;
}
}
*/

#include "Stm32f4_discovery.h"
#include "stm32f4xx_conf.h"

uint32_t Gb_timingdelay;
void Delay (uint32_t ntime);

Void Main ()
{
    systick_config (systemcoreclock/1000);//Set Systemtick one millisecond interrupt
 & nbsp; 
   /*
   //initialize LEDs mounted on stm32f4-discovery Board
&N bsp;   Stm_eval_ledinit (LED4);
    Stm_eval_ledinit (LED3);
    Stm_eval_ledinit (LED5);
    Stm_eval_ledinit (LED6);
     
   //turn on LED4 and LED5
    Stm_eval_ledo N (LED4);
    Stm_eval_ledon (LED5);
   
    while (1)
    {
     & nbsp; //toggle LED3 and LED6
        stm_eval_ledtoggle (LED3);
        Stm_eval_ledtoggle (LED6);

Insert a delay
Delay (100);

Toggle LED4 and LED5
Stm_eval_ledtoggle (LED4);
Stm_eval_ledtoggle (LED5);

Insert a delay
Delay (100);
}
*/

//-------------------------------------
Gpio_inittypedef gpio_initstructure;

Enable the gpio_led Clock
Rcc_ahb1periphclockcmd (Rcc_ahb1periph_gpiod, ENABLE);

   //configure the gpio_led pin
    gpio_initstructure.gpio_pin = Gpio_pin_12;
    Gpio_initstructure.gpio_mode = gpio_mode_out;
    gpio_initstructure.gpio_otype = gpio_otype_pp;
    gpio_initstructure.gpio_pupd = gpio_pupd_up;
    gpio_initstructure.gpio_speed = Gpio_speed_50mhz;
    gpio_init (Gpiod, &gpio_initstructure);
   //light This lamp
    gpiod->bsrrl = Gpio_pin_12;
   
    while (1)
    {
       // 
        Gpiod->odr ^= Gpio_pin_12;
       //insert a delay
        Delay (+);    
   }
   
}

Void Delay (uint32_t ntime)
{
    gb_timingdelay = ntime;
    while (gb_ Timingdelay! = 0);
}
void Systick_handler (void)
{
    if (gb_timingdelay! = 0x00)
    {         gb_timingdelay--;
   }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.