○ Software list

  • STM32CubeMX
  • Clion
  • En.stsw-link009.zip — St-link V2 driver, Clion needs to update this driver
  • Gcc-arm-none-eabi-54-2016q3-20160926-win32. exe — ARM architecture cross-compilation environment in WIN
  • Java1.8.0 _261 – the JDK
  • Java1.8.0 _261 – jre
  • Llvm-9.0.0-win64.exe — c compiler, I have VScode with this + MinGW below
  • MinGW — c compiler, which seems to be what the Zhihu tutorial uses
  • Openocd -esp32-win32-0.10.0-esp32-20200526.zip
  • St_nucleo_f103rb_stlink_v2.cfg — a self-written OpenOCD configuration file that is placed under XXX\ OpenOCD — esp32\share\ OpenOCD \scripts\board

A, CubeMX

1, the introduction of

  • Cubemx is ST official out, a use of HAL library, automatically generate STM32 initialization code software. The accompanying IDE is called STM32CubeIDE, which I haven’t used, so you can try it.
  • HAL library: Hardware Abstract layer, ST official. First of all, compare this to the standard library, which wildfire uses as its library functions. It is characterized by very detailed hardware implementation and close to register operations. HAL is more encapsulated, and the naming of various functions and variables is easy to understand, so it’s easier to use.
  • Automatic generation: literally, FULL AUTO.
  • Initialize code: this code only initializes for you, but still needs to boot itself. In the Wildfire system, initialization and startup are written together. If there are multiple devices working together, the initialization will run first (such as timer interrupt), which is quite heretic.

2. Usage process

2.1 General usage process

  1. Selection of the chip
  2. Configure the RCC: select HS-Crystal /Ceramic Resonator and configure the clock tree
  3. Configure SYS: select Debug-Serial Wire
  4. other
  • Note: Only after the completion of step 1-3 can you configure the other, otherwise you may encounter strange bugs, such as the debug mode is not selected next time the program will not enter.

2.2 Novice on the road process

  1. Usually when the software is installed and opened, it will let you guide the package. Click on this

2. Select STM32F1 series and install

3. Get on the road and build new projects

4. Enter the model

5. After opening the interface, I will not do the translation. I understand all the above tabs, and you can check if you don’t know

6. Configure the System Core (RCC, SYS, default). One is the clock tree, the other is the Debug mode, which is the download mode, and we use SWD.

7. Then open the Clock Configuration, which is the true Clock tree. Generally, type 72 here and press Enter.

8. Then configure other things, here direct reference (can not be temporarily done) : timer interrupt:Blog.csdn.net/toopoo/arti…Timer PWM:Blog.csdn.net/toopoo/arti…Timer input capture:Blog.csdn.net/as480133937…9. Then save it and give it a name, CTRL +S

10. Then select the toolchain and version

11. The two chosen

12. Then save the side and click generate directly

13. Then take a look at the CODE it generates. It’s important to note that your own CODE must be in this format [USER CODE BEGIN/END].

14. Read the notes for the rest.

Clion+CubeMX linkage

Needless to say, clion is one of the few large, modern ides that currently support proper C. Pycharm, Idea, and Goland, all from jetBrains, have a unified interface and are very friendly.

2.1, preview

  • With clion stm32 programming, first look at this article: zhuanlan.zhihu.com/p/63672432
  • After the above work is configured (meaning it can be compiled through), start the configuration process. If you do not care about this step, it may not work.
  • Proceed to the next step only when the above work is complete.

2.2. General usage process

  1. First open Clion and create a stM32Cubemx project. Understand the concept of workspaces and project folders. For example, in the following picture, create a workspace on the desktop, create a project folder in the workspace, and then the project file content is stored in the folder “project”. Cubemx or Clion will not recognize the toolchain if it is a single-level directory.

2. Open the. Ioc file.

  1. After [chip selection], [set clock tree], [set debug mode].

4. Configure the following parameters based on the following figureFile name and file path, the file name must be the same as the original to successfully overwrite the original file.

5. The file will be overwritten only after the prompt appears

6. Switch back to Clion, it will refresh automatically, select [this], [this] is written by myself, I will send it to you after you do this step. It opens at mian

7. Then you can code, the small hammer is compiled, the arrow is compiled and downloaded.

8. If the pin is renamed by Cubemx, this code will be automatically completed.

9. Then the download is complete

10. Turn on the LED light

Third, Issues

  1. Before using Cubemx, ensure that the Java version is 1.8 or later and that the environment variables are configured correctly, that is, both Java and Javac can run in CMD.
  2. When using Clion, you need to deploy native and cross-compilers properly. LLVM+MinGW is used in conjunction with the native compiler, and gcc-ARM-None-eABI is installed for cross-compiler.
  3. In Clion, if you encounter a compiler that can’t be found, check that the native and cross-compiler are installed correctly.
  4. “Xxxlevel-low” is displayed when downloading the program. Please update the ST-link V2 driver.
  5. To use the online debugging function, select XXX\GNU Tools ARM Embedded\5.4 2016Q3 \bin\arm-none-eabi-gdb.exe from the Debug ToolChain.