Three methods of STM32 download program (serial port, ST-LINK, ST-LINK Utility)

ST-LINK v2 wiring and download program

insert image description here

ST-Link V2

ST-Link v2 is an online emulator and downloader for STM8 and STM32 series microcontrollers.STM8 adopts SWIM interface modeSTM32 uses the SWD interface mode, so ST-Link is born with two interface modes.

ST-Link V2 supports all chip models of the STM32 family. Because of its unique features, it is a bit more comprehensive than jlink ob. For example, the ob model cannot support the STM32 of the H7 series.

Jlink ob

ST-link supports STM8, STM32 full range of chips;

Jlink ob supports Cortex-M0\M1\M2\M3M4\A5\A8\A9 ST (STMicroelectronics) Freecale (Freescale) NXP (NXP);

If the pure ST series has many advantages in developing ST-Link, if the multi-chip development ob is better , then it is best to have both.

remember

The power supply of the target chip remains only one way

If you choose to use ST-Link's VCC, do not connect other power supplies

If the target board is powered by an external power supply, disconnect the VCC of the emulator

It can prevent reverse electricity from being supplied to ST-Link and play a certain protective role

ST-Link V2 wiring

Interface Description:

Front (computer side) USB interface

Back-end (mcu end) 10 pin headers; 5V, 3.3V power supply

SWD wiring (for STM32): 3.3V, GND, SWDIO, SWCLK

SWIM wiring (for STM8): 3.3V, GND, SWIM, RST

5V or 3.3V selective power supply can be used according to the actual power supply requirements of the mcu

Some emulators may have different pins, but just connect the pins listed in the above two wiring methods, and leave other pins blank

download program

Serial download

First check whether the STM32 development board in hand supports serial port download. The information provided by the merchant will explain the supported download methods.

The STM32F103C8T6 development board in my hand supports USB serial port download and ST-Link SWD download

insert image description here

1. First install the CH340 driver on the computer

2. Open the STM ISP downloader MCUISP, and select the hex file to download

insert image description here

3. Connect the TXD, RXD, and GND of the USB to TTL downloader (CH340) with the RXD, TXD, and GND of the development board, and plug the other end of the downloader into the computer

4. The BOOT0 of the development board should be jumped to the 1 terminal by jumping

insert image description here

There are two jumpers on the development board to adjust the status of BOOT0 and BOOT1. Jumping the cap to the top is to choose 1, which is high level, and jumping to the bottom is to choose 0, which is low level

BOOT0 and BOOT1 are used to set the startup mode of STM32

insert image description here

Here is to use USB to download, that is, serial port download, so choose the second method in the table, which isBOOT0 selects 1, BOOT1 selects 0

4. Then the downloader will display the port number, the baud rate can be default, the fastest is 460800

insert image description here

5. Click to start programming, and then the waiting connection will appear on the right

insert image description here

6. At this time, the development board is powered on, and the program can be downloaded automatically

insert image description here

7. After the program is downloaded, the LED light of the board will flash, but if the reset button is pressed or the power is turned off and restarted, the LED light will not flash, because ISP is selected as the startup mode when the serial port is downloaded, and it needs to be switched back to start from the falsh area to run normally. program

So after downloading, remember to jump the jumper of BOOT0 back to 0 , BOOT0 and BOOT1 are both 0, so that the program will start from the falsh area, and the LED light of the development board will be on at any time;

ST-Link V2 Download

1. Install the ST-Link driver first, select the amd64.exe installer for a 64-bit computer, and continue to the next step

insert image description here

2. The driver is installed successfully

insert image description here

3. Insert ST-Link V2 into the computer, you can see the serial port of ST-Link in the device management, indicating that the driver is ok

insert image description here

4. Connect the SWDIO, GND, SWCLK, 3.3V of ST-Link V2 to the DIO, GND, CLK, 3.3 pins of the development board. Some boards have different silk screen marking methods, but they can be seen correspondingly, and then connect ST-Link plugged into the computer

5. Open the keil software, and open a project, then open the magic wand, select Debug, select ST-Link Debugger, and then click Settings

insert image description here

6. Port is JTAG by default, change it to SW

insert image description here

7. In the Flash Download interface, first of all, the three checks of the download function must be ticked. Reset and Run are not ticked by default. This is to restart the MCU and run the program after downloading, so sometimes the download is successful and there is no phenomenon, maybe It is not ticked here;

Click Add to see the model of the development board in hand, the one in hand is STM32F103C8T6, then find the STM32F10x series, select the medium capacity Med-density, 128k, and finally click OK

insert image description here

8. Go back to the interface where the magic wand is opened, click Utilities, select ST-Link Debugger, and click OK

insert image description here

9. Go back to the programming interface, compile the program first, make sure the compilation is passed, and then click the download option

insert image description here

10. When you see Verify OK, it means that the program is downloaded successfully, and the LED light on the development board flashes

insert image description here

STM32 ST-LINK Utility Download

STM32 ST-LINK Utility is a tool for programming (reading, writing, erasing, option words) for all STM32 chips.

ST-LINK Utility only supports the download debugger of ST-Link (multiple versions), and the supported chip is only STM32.

1. Install the ST-LINK Utility tool on the computer

2. Open the tool, plug ST-Link V2 into the computer, and connect the other end to the development board with SWD, click Connect on the tool to connect with ST-Link V2
insert image description here

3. Device connection successful interface

insert image description here

4. Open the hex file generated by kei software

insert image description here

5. You can click the Program option of Target to start the download, or you can directly click the graphic in the figure below, and after the download box pops up, make sure that the downloaded file is correct, and then click Start to download the program

insert image description here

6. If you see the message that the program has been downloaded successfully, and the development board has corresponding phenomena, it means that the program has been successfully downloaded to the development board

insert image description here

STM32 ST-LINK Utility read

Use the STM32 ST-LINK Utility tool to set the start address, size, and width of the read. The read is actually automatically read after the chip is connected.

insert image description here

STM32 ST-LINK Utility erase

insert image description here

The difference between hex file and bin file

hex file

To put it simply: Hex is a hexadecimal standard file format formulated by Intel, which is converted by a compiler and used to download files with a processor.

The Hex file format is composed of hexadecimal data line by line, and each line contains: start, length, data, type, checksum and other important information.

bin file

A Hex file has a certain format, while a Bin file is a program file without a format, but only contains program data. Therefore, when we download the bin file, we need to specify the starting address. If the starting address is wrong, your program will not run normally.

Guess you like

Origin blog.csdn.net/weixin_46251230/article/details/126301012