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
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.
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.
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.
Double click to open the installation package. Then just follow the tutorial.
Installation path can be modified according to the actual self, pay attention to do not have Chinese.
Check the driver and then click Install to install it.
Next just wait for the installation to complete.
When completed, it is shown below:
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.
Switch to Clock Configuration to modify the frequency of HCLK to 72 and press Enter to confirm.
Set the PC13 pin to GPIO_Output, and for convenience here change the Label to LED.
Then press Ctrl+S to save, check Remember my decision, and click Yes. This will automatically generate the code every time you save.
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.
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.
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.
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.
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
Click Install and the installation will be prompted as successful when it is complete.
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.
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.
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.
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.
The LED on the expansion board flashes every 200 milliseconds.