Current location - Quotes Website - Personality signature - How to use stm32cubemx
How to use stm32cubemx
STM32Cube is a comprehensive software platform, including various series products of ST. The platform includes the hardware abstraction layer of STM32Cube (embedded software of STM32 abstraction layer to ensure maximum portability in STM32 series) and a set of middleware components (RTOS, USB, FatFs, TCP/IP, graphics, etc.). ).

Intuitive selection and clock tree configuration of STM32 microcontroller

The microcontroller graphically configures the functional modes and initialization parameters of peripheral devices and middleware.

C code generation project covers the initialization of STM32 microcontroller in accordance with IAR? Kyle's? And GCC compiler.

For new product design, it is highly recommended to use STM32Cube to speed up your development process and lay a good foundation for future product platform transplantation.

1. New project

Open STM32cubeMX software and click New Project. Select the corresponding open MCU(STM32F 103ZET6).

Select a project and enter the project interface, as shown in the figure below.

2. Configure peripherals.

RCC setting, choose HSE (external high-speed clock) as crystal/ceramic resonator.

GPIO port function selection, pf6, pf7, pf8 and pf9 are LED 1-LED4. Find the corresponding pin and set it to GPIO_Output mode. (The GPIO with yellow pin for this function has been used for other functions and can be ignored. Green indicates that the pin has been used)

3. Clock configuration

The clock configuration adopts graphic configuration, which is intuitive and simple. Each peripheral clock can be seen at a glance. The highest clock of STM32 is 72M. Here, just enter 72 in HCLK, and the software can be automatically configured. (RCC selects external high-speed clock).

4. Configuration of functional peripherals

In the configuration box, we can see that there are several areas with corresponding function settings, as follows.

Multimedia: audio and video, LCD.

Control: timer

Analog: digital-to-analog converter, analog-to-digital converter

Connection: serial port, SPI, I2C, USB, Ethernet.

System: DMA (direct memory access), GPIO, NVIC, RCC, watchdog.

Middleware): FreeRTOS, FATFS, LwIP, USB.

In this project, DMA is useless without configuration, and NVIC (Nested Vector Interrupt Controller) configures interrupt priority. There is no need to configure RCC.

GPIO pin level: low level.

GPIO mode: push-pull output.

Maximum output speed: low speed.

User label: LED 1.

Change the user label, and the pin configuration diagram will show the label of the pin.

4. Power consumption calculation

This will calculate the power consumption according to the configured peripherals, regardless of other factors.

5. Generate engineering report

Click project->; Generate a report or click the shortcut icon to generate a report. You will be prompted to create a project first. Click Yes to set up the project.

Enter the project name and select the project path (be careful not to appear in Chinese, otherwise you may make mistakes). Select MDK-ARM V5 for tool chain /IDE. You can set the stack size at the end, which will not be modified by default.

Locate the Generated files box in the code generator, and check that Generated Peripher a is initialized to a pair. c/。 H' each IP file. Peripherals are initialized to independent C files and header files.

Click Generate Report, and a txt file and a pdf file will be generated under the project directory to record our settings just now.

6. Generate engineering code

Click project->; Generate code or click the shortcut icon to generate engineering code.

Click Open Project to open the project. At this point, the initialization configuration of engineering peripherals is completed.

Click the Build button, and the Build Optput message box will not output any errors and warnings.

6. Add an application

You can see the initialization function of LED pins in the gpio.c file.

The operation function of GPIO can be seen in the header file stm32f1xx _ Hal _ gpio.h.

In the main function, the application of LED driving light effect in while loop is added.

Recompile the program and click to download it to the Open 103Z-C development board. If the prompt is wrong, you can click the icon to modify the Dubug option of the target option. (ST-LINK is selected on the picture)

Click Settings-> Flash download check reset and run options. In this way, the program automatically starts running after downloading, and can run without pressing reset or re-powering on.

The program is downloaded to the Open 103Z-C development board. You can see that LED 1~LED4 lights up in turn to achieve the effect of running water lamp.

Summary: STM32Cube provides a firmware library, and users can directly call the firmware library functions for development, which can well realize the code consistency of STM32-MCU. At the same time, the configuration functions such as visual pins, peripherals and clocks provided by STM32CubeMX tool can help to quickly complete the establishment and initialization of the project. Greatly reduced the workload of developers.