2. STM32 development environment build

2. STM32 development environment build2.1 Introduction to STM32CubeIDE2.2 Download the installation package2.3 Starting Installation2. 4. New project2.5 Pin configuration2.6. Writing the code2. 7 Compile the program2.8. Burning program2.9. Program Phenomena

2.1 Introduction to STM32CubeIDE

STM32CubeIDE is an all-in-one multi-operating system development tool, an advanced C/C++ development platform with peripheral configuration, code generation, code compilation and debugging for STM32 microcontrollers and microprocessors. It is based on the Eclipse®/CDT™ framework and the GCC tool chain for development, as well as GDB for debugging. It can select an STM32 microprocessor and then create a project and generate the initialization code to support graphical configuration of STM32 clocks and pins and other content, support for the mainstream platforms of Windows, Linux, Mac, very powerful and practical features.

 

2.2 Download the installation package

Open the following link with your computer browser:

https://www.st.com/zh/development-tools/stm32cubeide.html

Download according to the computer system, here to Win10 system to install version 1.9.0 as an example, select the latest version to download.

image-20220309095106970

If you have an account on my.st.com, you can log in and download the software directly. If you don't want to log in now, just provide your name and email address in the form below to download the software.

Unzip the downloaded file, and unzip the path without Chinese.

image-20220309100601767

2.3 Starting Installation

Double click to open the installation package. Then just follow the tutorial.

image-20220309100702670

image-20220309100727187

Installation path can be modified according to the actual self, pay attention to do not have Chinese.

image-20220309100759937

Check the driver and then click Install to install it.

image-20220309100939458

image-20220309101103308

Next just wait for the installation to complete.

image-20220309101409033

2. 4. New project

  1. Double-click the desktop shortcut to open STM32CubeIDE, you need to select the workspace, save the path can be based on the actual choice of other paths (do not bring Chinese).

 

image-20220309101938781

image-20220309103807055

  1. Click File->New->STM32 Project.

image-20220309103950961

  1. Search and select the chip STM32F103RCT6, then click Next in the lower right corner to go to the next step.

image-20220309104523552

  1. Enter the name of the project, here to LED as an example, other parameters can be default.

image-20220309104753828

  1. Click Yes and the graphical content will be loaded at this point.

image-20220309104926020

When completed, it is shown below:

image-20220309105514825

2.5 Pin configuration

  1. First of all, you need Debug information, under Pinout&Configuration, click SYS->Debug to select Serial Wire.

image-20220309111832426

  1. Modify the system clock of STM32, according to the schematic diagram, we can see that the external crystal is 8M frequency.

image-20220309110118096

In Pinout&Configuration select RCC->HSE select Crystal/Ceramic Resonator where HSE is the external clock and LSE is the internal clock, using the external clock can be more stable and efficient than the internal clock.

image-20220309110240836

Switch to Clock Configuration to modify the frequency of HCLK to 72 and press Enter to confirm.

image-20220309110757303

image-20220309110728487

  1. Increase the LED pin configuration, from the schematic diagram it can be seen that the LED is connected to the PC13 pin.

image-20220309112325122

Set the PC13 pin to GPIO_Output, and for convenience here change the Label to LED.

image-20220309112613410

Then press Ctrl+S to save, check Remember my decision, and click Yes. This will automatically generate the code every time you save.

image-20220309112812784

image-20220309112931421

2.6. Writing the code

  1. Since the previous step of graphical configuration has generated the initialization code of the system, we only need to add the functions to be implemented.

Find the main function in the main.c file and add the control LED under while (1). The function is to flash the LED every two hundred milliseconds. Press Ctrl+S to save the code.

image-20220309114143099

Note: The code content should be added between USER CODE BEGIN and USER CODE END. Otherwise, the code content will be overwritten next time when you generate the code through the graphical tool, but it will not be overwritten if you add it between USER CODE BEGIN and USER CODE END. Don't write Chinese comments in it, it may be messy.

2. 7 Compile the program

  1. Add the function of generating HEX files.

Click Project->Properties->C/C++ Build->Settings->MCU Post build outputs in order, and then tick the box in front of Convert to Intel Hex file(-O ihex), as shown below.

image-20220401105445775

image-20220401105123327

  1. Click the hammer in the toolbar to start compiling the project.

image-20220401105951706

STM32CubeIDE will pop up the Console console, see compile 0 error, 0 warning means compile successfully. As shown in the figure below, the project generates a file named LED.hex, and this file is saved in the Debug folder of the project directory.

image-20220401110314069

2.8. Burning program

1.Install CH340 driver

As the USB communication of Rosmaster expansion board uses CH340 chip, so you need to install the driver of CH340 chip, if your computer has already installed CH340 driver, you don't need to repeat the installation.

Unzip this course material in the [Uart drive (CH340).zip], double-click to open the CH341SER.EXE program

img

Click Install and the installation will be prompted as successful when it is complete.

img

  1. Download burning software

This burning Rosmaster expansion board MCU firmware need to use mcuisp (or flymcu) burning software, please go to http://www.mcuisp.com download mcuisp (or flymcu) burning software; you can also directly use the information provided in the mcuisp software.

mcuisp software is a green version of the software, do not need to install, double-click to open to use.

3.Connecting the device

Before connecting the Rosmaster to your computer, unplug the micro USB cable and power cable that connects the expansion board to the Jetson Nano.

Plug one end of the USB cable into the USB port of your computer and the other end into the Micro USB port of the Rosmaster expansion board.

image-20220401112853890

  1. Configure the burning software

image-20220325110607466

When searching serial ports, if there are more than one serial port number, and you can't confirm which one is Rosmaster's. Solution 1: Unplug the other USB port and search again; Solution 2: Unplug the USB cable of Rosmaster first, click Search Serial Port, write down the serial port number searched, plug in the USB cable of Rosmaster, search the serial port again, and compare before and after two times, the newly added serial port number is the serial port number of Rosmaster.

To select the firmware, you need to select the LED.hex file in the Debug folder of the project directory.

Finally, the bottom of the configuration selection, be sure to select [DTR's low level reset, RTS high level into the BootLoader] option, otherwise it may lead to download failure.

  1. Burning Program

Please first put the microcontroller on the expansion board into the burn mode:

First press and hold the BOOT0 key on the expansion board, then press the RESET key, and finally release the BOOT0 key.

image-20220325111504124

Click [Start Programming], the mcuisp burning software will burn the firmware we chose in the previous step to the microcontroller on Rosmaster's expansion board. When the prompt [Successfully run www.mcuisp.com Reporting to you. from 08000000, the command is executed, everything is normal] appears on the right side, it means the download is successful.

Note:

① Before you start burning, please make sure that the serial port number of Rosmaster is accessible, that is, no serial assistant occupies it.

② Rosmaster into the burning mode of operation, first press and hold the BOOT0 key on the expansion board, then press the RESET key, and finally release the BOOT0 key.

2.9. Program Phenomena

The LED on the expansion board flashes every 200 milliseconds.