Cortex_m3_stm32 Embedded Learning Note (i): Set up project template + Marquee experiment

Source: Internet
Author: User

It's been a whole night. + one morning at last it was just the LED lit up. It's a struggle.


The MDK of the slot is the encapsulation of the library function. It's so ridiculous. All firmware library functions should be added to the project by hand. Fortunately, after building good one template will not move (after the direct copy on the line)

First of all, for the project template, we need to figure out what we need to write ourselves, and which is not moving, in fact, beginners should only need to write two folders inside the program: 1 The main function of the USER folder

2. Hardware setup function in HARDWARE (hardware)

As for the construction of the project template I will not repeat, according to the video or textbook to build a backup after use on it.


And then it's how to light the LED and let it blink alternately.

Still need to look at the schematic.

Can see from the development Board two LED lights were written ds0,ds1 that corresponds to the LED0 LED1, LED0 corresponding stm32 on the PA8 on the LED1 on the chip stm32

Next write the function of configuring IO


#include "led.h" void Led_init (void) {gpio_inittypedef gpio_ist;//configuration LED0  rcc_apb2periphclockcmd (rcc_apb2periph_ gpioa| rcc_apb2periph_gpiod,enable); Enable the PA,PD port clock to gpio_ist. gpio_pin=gpio_pin_8;//led0-->pa.8 Port configuration Gpio_ist. GPIO_MODE=GPIO_MODE_OUT_PP; Select push-Pull output mode gpio_ist. The speed of the Gpio_speed=gpio_speed_50mhz;//io is set to 50mhzgpio_init (Gpioa,&gpio_ist),//¸ is initialized according to the parameters Gpioa.8gpio_setbits (GPIOA, GPIO_PIN_8);//set pa.8 to output high//configuration led1gpio_ist. gpio_pin=gpio_pin_2; Led1-->pd.2 Port configuration Gpio_init (gpiod,&gpio_ist);//¸ initialize Gpiod.2gpio_setbits (gpiod,gpio_pin_2) according to parameters; Set Pd.2 to output high}

Adjust the GPIO_INITTYPEDEF structure of the 3 members, the parameters to set a good initialization function, see this statement gpio_setbits (gpioa,gpio_pin_8);//set pa.8 to output high

To find the DS0 DS1, the function of this statement is to initialize the two-port level to 1, (that is, the light is not lit at first)

and see #include "led.h"

This header file needs to be written by yourself.

#ifndef _led_h#define _led_h#include "sys.h" #define LED0 paout (8)//pa 8#define LED1 pdout (2)//pd 2void led_init (void); #e Ndif
The above code is used for conditional compilation, not difficult. Just look at it. The function is to make it possible to identify LED0 LED1 led_init () in the main function: is actually declaring a bunch of things

Add the above two files to the HARDWARE file in the project, and note the path to add "Led.h"

The final writing of the main function is simple.

#include "led.h" #include "sys.h" #include "delay.h" int main (void) {delay_init (); Led_init (); while (1) {led0=0; Led1=1;delay_ms (600); Led0=1; Led1=0;delay_ms (600);}}


"Delay.h" is mainly a delay function.


Cortex_m3_stm32 Embedded Learning Note (i): Set up project template + Marquee experiment

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.