STM32CubeMx tutorial (2) - create a project, light up the LED

The power of STM32CubeMx was briefly introduced earlier. Through this experiment, we will introduce how to use cubemx to create projects and light up LED lights. This will be the first lecture to formally bring you closer to embedded development.

1. Preliminary preparation

1. stm32 main control board (this experiment uses the common STM32F103C8 core board, which can be bought on Taobao for 20 yuan);

2. Downloader (ST-Link, J-Link can be used, more than a dozen yuan can be solved on Taobao);

3. STM32CubeMX, Keil5_MDK software (see the first lecture for specific installation tutorial and installation package).

There is a shopping list at the end of the article.

2. How to light up (hardware control)

By observing the circuit diagram, we found that there are two LED indicators on the core board, which are the LED indicator (PC13) and the power indicator, which belong to a relatively common LED circuit. The diode has unidirectional conductivity, a path is formed between the anode and cathode of the LED, and the LED is lit. Similarly, when PC13 is connected to a high level (1), there is no potential difference between the anode and cathode of the LED, and the LED cannot be lit. This is why the power indicator light will be continuously lit when the main control board is powered on.

3. Use cubemx to generate code to light up (software control)

As mentioned above, we need to give the PC13 pin a low level to turn on the LED indicator light. Here we control the LED to turn on through the cubemx configuration.

First, open cubemx

 We click to select the MCU model and create a project

 Select the corresponding chip type, double-click to enter the project

Enter the project interface, first configure the clock, configure the clock as an external high-speed clock, select the crystal oscillator, and you can see that the OSC pin of the right chip turns green (1. Green means configured 2. Yellow means not configurable, such as power supply VBAT 3. Gray means not yet configured)

 Configure the clock tree, fill in the frequency of the external crystal oscillator, select the HSE external high-speed clock, PLL frequency multiplication, and configure the maximum frequency of 72Mhz

 

 Select the SYS configuration download debugging mode as SW mode. If the Bebug mode is not configured, the chip will be locked once downloaded. At this time, you need to reconfigure the Bebug mode, and then press and hold the reset button to download (it is troublesome, it is recommended to develop a habit and configure it first. ).

 Configure the GPIO of the LED to be low level, push-pull output, no pull-up and pull-down, and finally the pin label can be customized to facilitate porting

 Select project management, fill in the project name and path, and select the IDE as Keil5 MDK. Note: The project name and path cannot exist in Chinese.

 Choose to copy the necessary libraries to the project to reduce compilation time. Choose to generate .c/.h files to facilitate project management.

 Open the project.

 

After opening the project, enter the downloader selection, select the corresponding downloader to download

It can be seen that the LED is lit 

The code project and purchase list have been uploaded to Baidu Netdisk

Link: https://pan.baidu.com/s/1cpwJ5O2TMAr3BPtwYoZFrg?pwd=rzp v (delete the last space, copy the link to open)
extraction code: rzpv

Guess you like

Origin blog.csdn.net/weixin_49821504/article/details/126694467