Stm32f429i-disco FreeRTOS Keil Stm32cubemx

Source: Internet
Author: User

Goal:

On the stm32f429 disco Development Board, double-flashing LEDs are lit with freertos dual threads.

Get ready:

0. Stm32f429i-disco

1. Keil ARMMDK 5.13

2. STM32CUBEMX 4.8

Steps:

1. Establishment of the project

Keil-project-new Project

2. Save on the hard drive, give the project a name

3. Save the Project

At the same time, the device selection interface is ejected, select STM32F429ZITX

4. Above the interface point OK after the run environment Configuration interface

Expand Cmsis:rtos and Enable:keil RTX:

The Validation Output area shows the dependent components, point resolve, and OK

Now, the required components are added to the project (startup, RTX config, cmsis system files)

5. Gpio and Clock configuration.

Open Cube

Select the device.

Configuring the Clock

Then generate the Code

What I want is the initialization of the clock and the initialization of the GPIO

/** System Clock Configuration*/voidSystemclock_config (void) {rcc_oscinittypedef rcc_oscinitstruct;  Rcc_clkinittypedef rcc_clkinitstruct;  __pwr_clk_enable ();  __hal_pwr_voltagescaling_config (PWR_REGULATOR_VOLTAGE_SCALE1); Rcc_oscinitstruct.oscillatortype=Rcc_oscillatortype_hse; Rcc_oscinitstruct.hsestate=rcc_hse_on; RCC_OscInitStruct.PLL.PLLState=rcc_pll_on; RCC_OscInitStruct.PLL.PLLSource=Rcc_pllsource_hse; RCC_OscInitStruct.PLL.PLLM=8; RCC_OscInitStruct.PLL.PLLN=336; RCC_OscInitStruct.PLL.PLLP=Rcc_pllp_div2; RCC_OscInitStruct.PLL.PLLQ=4; Hal_rcc_oscconfig (&rcc_oscinitstruct); Rcc_clkinitstruct.clocktype= rcc_clocktype_sysclk|RCC_CLOCKTYPE_PCLK1|Rcc_clocktype_pclk2; Rcc_clkinitstruct.sysclksource=RCC_SYSCLKSOURCE_PLLCLK; Rcc_clkinitstruct.ahbclkdivider=Rcc_sysclk_div1; Rcc_clkinitstruct.apb1clkdivider=rcc_hclk_div4; Rcc_clkinitstruct.apb2clkdivider=Rcc_hclk_div2; Hal_rcc_clockconfig (&rcc_clkinitstruct, flash_latency_5); Hal_systick_config (Hal_rcc_gethclkfreq ()/ +); Hal_systick_clksourceconfig (SYSTICK_CLKSOURCE_HCLK);}
initializing the 168M system clock
/** Configure Pins as * Analog * Input * Output * event_out * Exti*/voidMx_gpio_init (void) {gpio_inittypedef gpio_initstruct; /*GPIO Ports Clock Enable*/__gpioh_clk_enable ();  __gpiog_clk_enable (); /*Configure GPIO pins:pg13 PG14*/Gpio_initstruct.pin= gpio_pin_13|gpio_pin_14; Gpio_initstruct.mode=gpio_mode_output_pp; Gpio_initstruct.pull=Gpio_nopull; Gpio_initstruct.speed=Gpio_speed_low; Hal_gpio_init (Gpiog,&gpio_initstruct);}
Initialize Gpio

Add these two pieces of code into the MAIN.C and call

6. Configuring the FreeRTOS Clock

Open the Rtx_conf_cm.c file with a configuration tag underneath the file, where the 168M clock is configured to match the above

8. Add the main function

Right-click Source Group 1, select Add New Item to Group

Select User Code Template and click on "Cmsis-rtos ' main ' function". Click Add.

9. Edit the main program code. First add the Cmsis-rtos RTX header. Right-click on a blank line in the beginning of the file main.c and from the popup menu select Insert ' #include files '. Include the header file cmsis_os.h.

Hal Drive

11. Write Application code

Add LED.h, LEDs. H

/* ------------------------------------------------------------------------  * File LED.h  *------------- ---------------------------------------------------------*/voidvoid// Initialize Thread
/*------------------------------------------------------------------------* File LED.C *---------------------- ------------------------------------------------*/#include"stm32f4xx.h" //Device Header#include"Cmsis_os.h" //Rtos:keil RTX Header#include"LED.h"#include"stm32f4xx_hal.h" //Prototype functionvoidLedg_blink (void Const*argument);voidLedr_blink (void Const*argument);//Define Blinky ThreadOsthreaddef (Ledg_blink, Osprioritynormal,1,0); Osthreaddef (Ledr_blink, Osprioritynormal,1,0); voidLedg_blink (void Const*argument) {     for (;;)        {Hal_gpio_writepin (Gpiog, gpio_pin_13, Gpio_pin_set); Osdelay ( -);//Delay-MsHal_gpio_writepin (Gpiog, gpio_pin_13, Gpio_pin_reset); Osdelay ( -);//Delay-Ms    }}voidLedr_blink (void Const*argument) {     for (;;)        {Hal_gpio_writepin (Gpiog, gpio_pin_14, Gpio_pin_set); Osdelay ( -);//Delay-MsHal_gpio_writepin (Gpiog, gpio_pin_14, Gpio_pin_reset); Osdelay ( -);//Delay-Ms    }} voidInit_blinkythread (void) {osthreadcreate (Osthread (Ledr_blink), NULL);//Create ThreadOsthreadcreate (Osthread (Ledg_blink), NULL);//Create Thread}
LED.C

12. Call Inside the MAIN.C

/** main:initialize and start the system*/intMain (void) {systemclock_config ();    Mx_gpio_init (); Oskernelinitialize (); //Initialize Cmsis-rtos//create ' thread ' functions that start executing,//example:tid_name = osthreadcreate (osthread (name), NULL);Init_blinkythread ();//Start Blinky Thread//osthreadcreate (Osthread (blink_led), NULL);//Create ThreadOskernelstart ();//Start Thread Execution         while(1); }

Stm32f429i-disco FreeRTOS Keil Stm32cubemx

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.