1、 stay ST Download from the official website STM32CubeIDE instead of STM32CubeMX, also STM32CubeIDE It's free. .（STM32CubeIDE Chinese path... Is not supported , Otherwise, the compilation will be wrong ）
2、 If you're using a keil Development environment so STM32CubeIDE =（STM32CubeMX + Keil）STM32CubeMX It's just a configuration code generator
3、STM32CubeIDE Software download link ：https://www.st.com/zh/development-tools/stm32cubeide.html#tools-software
4、STM32CubeMX Software download link ：https://www.st.com/zh/development-tools/stm32cubemx.html
5、 Start the installation when the download is complete , You can change the installation path , All the rest are by default （ Only install this time STM32CubeIDE ）
6、 Open the software after installation , Set your own work environment path , Click on Launch（ The path cannot have Chinese , Some Chinese will compile error ）
7、 Click on Start new STM32 project Create a new project , Input the corresponding chip model on the hardware , Click on Next, Enter the project name BASIC_GPIO, Click on Next Pop-up dialog box , Click on Yes.
8、 Once I've created it , The following interface is the new project created
9、 Start configuring engineering parameters ：1） To configure SYS Debugging mode ,2） Configure the system clock RCC,3） To configure GPIO port
10、 Configure debugging mode （debug Choose the right option according to your hardware , This use is CMSIS DAP debug , Using wildfire guider development board selection JTAG ( 5 pins )
11、 Configure the system clock RCC（ Using an external crystal oscillator 8MHz, The highest dominant frequency is 72MHz）
12、 To configure GPIO port （ This hardware for wildfire guide ） With LED For example, a lamp , The hardware circuit diagram is as follows
13、 For each one GPIO Parameter modification （ Click left and right on the corresponding pin in the diagram to configure , The specific operation of their own points a few times to understand ）
14、 Because it's configured with GPIO Peripherals , Modify and generate the corresponding H Document and C file
15、 Click Save to show whether to generate code , Click is the code that generates the response , You can see the generated code in the following location
16、 In position 1 Right click the mouse to select Build Project Compile project program , You can see the compiled code
17、 Now write code control LED The state of the light （ This use is HAL library <<HAL Generally refers to the hardware abstraction layer . The hardware abstraction layer is located in the operating system The interface layer between the kernel and the hardware circuit , Its purpose is to abstract the hardware . It hides the hardware interface details of a specific platform , Provide virtual hardware platform for operating system , Make it hardware independent , It can be transplanted on multiple platforms >> ）
18、GPIO It's using HAL library , Most functions are in the form of HAL At the beginning , stay main Program to write the following code , And compile ：（ When editing the code, you can use the code completion function shortcut key ： ALT+/ ） The added code must be in /* USER CODE BEGIN */ and /* USER CODE END */ Between , Otherwise, saving or compiling will delete the code .
19、 Compile and pass , Start debugging the program ： Check through software debugging Debug_num Change in value , and GPIO Changes in register values
20、 In position 1（ See above 15 Step ） Right click mouse ->Debug As -> STM32 Cortex-M C/C++ Application
21、 Because this time is used CMSIS DAP Debug（ Hold fire D Ordinary DAP Emulator ）STM32CubeIDE Not supported by default DAP Of , But by ST-Link（OpenOCD Indirect support ）, a key ：：：：：：《 Choose to connect to remote GDB Server port 》
22、 Once the configuration is complete , It shows no, no ST-link
22、 There is an error indicating that there is no ST-Link, Is the computer does not have the corresponding driver installed
23、 install ST-LinkOCD drive , Download link ：https://gnutoolchains.com/arm-eabi/openocd/ After downloading, unzip and open the folder
24、 Press and hold in the blank Shift Right click the mouse button to open PowerShell window , Press enter for the following command ：./openocd -f interface/cmsis-dap.cfg -f target/stm32f1x.cfg If it doesn't work, try it a few more times , Before executing, it is better to connect the MCU and computer .
25、 go back to STM32CubeIDE in , Recompile the program , Click the ladybug button , Go to the following interface
26、 according to LED The light interface to see the corresponding GPIO Port of ODR register , You can see the change in values , At the same time, observe the development board of LED Light status .
27、 Click the full speed button , Check out the development board LED The light is flashing .
28、 Because the default setting port is low level during initialization , That is, the light is on by default , So in LED_BLUUE When flashing, the other light is always on , How to modify GPIO The default output of the port is high level or low level , You can modify it in the following places .