[STM32] Use RTE to create a (keil) ARM MDK project from 0 (pure keil, standard library, take STM32F103C8T6 as an example)

To learn related basic knowledge, please read other articles in this column, there must be what you want.

https://blog.csdn.net/weixin_43764974/category_11021363.html

The software and hardware of this article:

  • STM32F103C8T6
  • ARM MDK 5.38
  • ARM complier 6
  • ST-Link v2
  • StdPeriph Drivers (Standard Library)

Before the article starts, I want to say it again: keil, μvision, ARM MDKthese nouns (although it has been said several times in the previous article)

  • Keil is a German company that provides a range of software tools for embedded system development. Among them, Keil MDK (Microcontroller Development Kit) is a set of integrated development environment (IDE) launched by Keil, which is used to develop embedded applications based on ARM processors.

  • μVision (MicroVision) is the core component of Keil MDK. It is a powerful integrated development environment that provides functions such as code editing, compiling, debugging, simulation and programming. As the front-end tool of Keil MDK, μVision provides users with a friendly graphical interface and convenient development experience.

  • ARM MDK (ARM Microcontroller Development Kit) is a complete software development kit developed by Keil authorized by ARM. It combines Keil's software development tools and software libraries such as CMSIS (Cortex Microcontroller Software Interface Standard) provided by ARM to develop embedded systems based on ARM Cortex-M series processors.

Usually, use keil to refer to the above three.

1. Engineering structure

When creating an STM32 project in the Keil environment, the following structure is usually followed:

  1. Project Files (Project Files) :

    • Project file ( .uvprojx): The main file of the Keil project, which saves the settings and configuration information of the project.
    • Project options file ( .uvoptx): Saves configuration options for the compiler, linker, and debugger.
    • Project configuration file ( .uvproj.user): Save the user configuration options of the project, such as source file list, compilation options, etc. (here user is the Windows user name when you create the project).
  2. Source Files :

    • C/C++ source files (.c, .cpp): Contains the main source code of the application.
    • Assembly Source File (.s): An optional assembly language file for specific processor instructions or startup code.
    • Header file (.h): Contains various configurations and macro definitions.
  3. Library files (Library Files) :

    • STM32 standard peripheral library (.a): contains the standard peripheral library file of the STM32 chip, providing functions and constants for accessing STM32 peripherals.
    • Third-party library files: If you use third-party libraries (such as FreeRTOS, CMSIS, etc.), the files of these libraries can also be placed here.
  4. Intermediate Files :

    • Object file (.o): The object file generated by compiling the source file is used for subsequent link operations.
    • List file (.lst): Contains compiled assembly code, which can be used for debugging and analysis.
  5. Output Files :

    • Executable files (.axf, .elf): The linker links the object files into executable files for burning and running on the STM32 chip.
    • HEX file (.hex): The hexadecimal format of the executable file, which is often used for burning by the burner.
    • BIN file (.bin): The binary format of the executable file, which is also commonly used for burning by the burner.
  6. Debug files (Debug Files) :

    • Debug information file (.axf, .elf): contains symbol information and debugging information required by the debugger.
    • Debug output file (.txt): contains output information and logs during debugging.

In addition to the above files, the Keil project may also contain other auxiliary files, such as:

  • Startup file (startup_xxx.s): Contains the startup code of the processor, initializes the processor and peripherals.
  • Configuration file (xxx.h): Contains various configuration options and macro definitions.
  • Driver Files (xxx.c, xxx.h): Driver code and header files for specific peripherals.
  • Interrupt handler function (xxx.c): The function that handles interrupt requests.

This is to make it easier for you to read the explanations made by other people's codes. You can do whatever you want, but they are all similar. The core is the user program + system files (startup files, driver files, etc.).

Two, practical operation

For a detailed introduction to keil, you can read the previous articles in this column.

(1) Click project—>new μVision project, select a project save location

(2) Select the device: STM32F103C8 (the pack here must be installed first, which has been introduced in detail in the previous article)

insert image description here

(3) Click OK to pop up a runtime configuration interface

insert image description here


Manage Run-Time EnvironmentIt is a function used in Keil software to manage software components. In this window, you can select or cancel the required components, such as CMSIS, Device, Middleware, etc. These components can provide some precompiled library files, header files, source code, etc., to facilitate the development of STM32 projects.

  • In the pop-up Manage Run-Time Environment window, you can see different categories of components in the tree list on the left, such as CMSIS, Device, Middleware, etc. The corresponding description, version, document and other information are displayed on the right.

  • Select or deselect the required components in the check boxes on the right. In general, at least the select CMSIS->COREand Device->Startupthese two components are required, which provide some basic definition and startup code. Other components are determined according to engineering requirements. For example, if I light a lamp, I will choose another one GPIO(the standard library is used here, and GPIO under stdPeriph Drivers is selected).
    insert image description here

  • After selecting the components, click Resolvethe button to resolve some dependencies or conflicts, and help you check other dependency options.

In subsequent development, you can still click the green diamond on the toolbar to select the required components.


(4) After solving all the problems, click the OK button to close the Manage Run-Time Environment window and generate the corresponding project files.
insert image description here
In the previous operation, keil has generated the necessary files for the project for us:

  • System initialization file: system_stm32f10x.c, contains the definition of some system initialization functions.
  • Startup file: startup_stm32f10x_md.s, contains the definition of reset vector table and reset processing function.
  • GPIO driver: stm32f10x_gpio.c, you can view the functions and parameters of the GPIO driver in this file.
  • etc.

Among them, files with yellow keys cannot be modified and will not be displayed in the project folder. Of course, these generated files usually do not require modification. In addition, some files also have a + sign, which can be expanded, which reflects the inclusion relationship of the file and is convenient for viewing file dependencies.

This may be a little different from the "project template" you use, because some projects are created by an old version of keil, may not use software packages or RTE (ie Run-Time Environment) functions, or are created based on CubeMX, such as this :
insert image description here

The content of the current project directory:
insert image description here
the last three are project files, which have been introduced before, and the folders are:

  • RTE : This folder contains configuration files, header files, and source files for your selected software components. Here you can review or modify your component settings and code.
  • DebugConfig : This folder contains your debug configuration files, such as target settings, debugger settings, trace settings, etc. Debug parameters can be viewed or modified here.
  • Listings : This folder contains the assembly code, symbol table, mapping file, etc. generated after the project is compiled. You can view or analyze your compilation results here.
  • Objects : This folder contains the object files, library files, executable files, etc. generated after the project is compiled.

( 5) Write user program

  • You can create a new user program folder in the project folder, for example User;

  • Then create a new file, save it as a .c file, and save it to the file just now;

  • Write code;

  • Add them to keil:

    • Click Manage project itemsto create a new Group and add the source file just now, as shown in the figure:
      insert image description here
    • In option for target, check Make hexFiles

( 6) Download

I downloaded it using ST-Link, if not, you can read my previous article:

[STM32] Bootstrap mode and program download (ST-Link and serial port example)

3. Matters needing attention

3.1 I seem to be missing some settings?

In this article, I use STM32F103C8T6. In the project, I simply realized the on-off control of the LED light. There is only one mian.c file above.
insert image description here

My full workflow overview is:

  1. New construction, select model;
  2. Configure RTE;
  3. Programming;
  4. add the program to keil;
  5. Choose to generate a hex file;
  6. compile;
  7. Set ST-Link download;
  8. Download。

Since I created the project using RTE, RTE automatically handles the necessary include paths and library files to ensure a correct compilation and linking process. Based on the device and peripheral drivers you selected in the RTE configuration wizard, it will automatically generate the corresponding configuration files, including the correct include paths. RTE will also automatically generate corresponding processor symbols and macro definitions according to the device and peripheral drivers you choose.

That said, these settings are usually left alone:
insert image description here

3.2 RTE selection

If you want to use the standard library , choose Device--StdPeriph Driversthe following peripherals
insert image description here
If you want to use the HAL library, choose: CMSIS Driversthe following peripheral API, GPIO choose Device

insert image description here


CMSIS DriverIt is ARMa common driver interface standard defined by the company for peripheral control of various Cortex-M microcontrollers. It provides a consistent programming interface and portability, enabling driver code to be shared and reused among microcontrollers from different vendors. STMicroelectronics provides a CMSIS Driver compliant driver implementation for compatibility with its STM32 series microcontrollers.

HAL (Hardware Abstraction Layer)is STMicroelectronicsa high-level library provided for peripheral programming of STM32 microcontrollers. HAL provides functional functions and configuration options for specific peripherals of the STM32 series, making it relatively simple for developers to write and control peripherals. HAL is located on top of CMSIS Driver , and uses the underlying interface provided by CMSIS Driver to control peripherals.

stdPeriph Driversis STMicroelectronicsa legacy peripheral driver library provided by . stdPeriph Drivers provide a high-level API to make programming relatively simple, but for different series of STM32 microcontrollers, their peripheral functions and register definitions may be different.

appendix, code

Simple LED blinking, standard library:

If the Chinese characters are garbled after copying, just modify the encoding to UTF-8.

#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"

void LED_Init(void); //LED初始化函数声明
void Delay(uint32_t nCount); //延时函数声明

int main(void)
{
    
    
  LED_Init(); //调用LED初始化函数
  while (1)
  {
    
    
    GPIO_ResetBits(GPIOC, GPIO_Pin_13); //将PC13置低,点亮LED
    Delay(0x0FFFFF); //延时一段时间
    GPIO_SetBits(GPIOC, GPIO_Pin_13); //将PC13置高,熄灭LED
    Delay(0x0FFFFF); //延时一段时间
  }
}


void LED_Init(void) //LED初始化函数定义
{
    
    
  GPIO_InitTypeDef GPIO_InitStructure; //定义GPIO初始化结构体变量
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //使能GPIOC端口时钟
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //选择PC13引脚
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置为推挽输出模式
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置IO口速度为50MHz
  GPIO_Init(GPIOC, &GPIO_InitStructure); //根据参数初始化GPIOC
  GPIO_SetBits(GPIOC, GPIO_Pin_13); //将PC13置高,熄灭LED
}

void Delay(uint32_t nCount) //延时函数定义
{
    
    
  for(; nCount != 0; nCount--); //循环减计数
}

Effect:

insert image description here



Write love you forever into the end of the poem ~

Guess you like

Origin blog.csdn.net/weixin_43764974/article/details/131754334