STM32 microcontroller burns hex program through serial port

    I bought a STM32 minimum program microcontroller before. I used to download 51 microcontrollers using the serial port method. Here I also burn the STM32 microcontroller through the serial port method, and I need a USB TO TTL tool.

    The USB TO TTL tool is similar to a U-disk tool, except that the other end of it is a connection. Generally, the computer will automatically install the driver. If it is plugged into the computer and the serial port number cannot be recognized, then the CH340 driver needs to be installed.

    This USB TO TTL tool requires four wires 3V3, RXD, TXD, and GND. Connect to 3V3, A9, A10, GND of the microcontroller respectively.

    There is another setting on the microcontroller, which is BOOT0. The jumper should be connected to the side of 1, and BOOT1 should be connected to the side of 0, as shown below:

    A9 and A10 are for sending and receiving data to the serial port. Here is a simple soldering. 

    Downloading the program to the STM32 MCU also requires a FlyMcu program. This program is very small and can be downloaded from many places. After opening, the interface is as follows:

    ①The serial port COM6 is connected to the USB TO TTL by the single chip microcomputer, and it is automatically recognized after plugged into the computer, and the baud rate is also the default. If it is not recognized here, check whether the CH340 driver is installed.

    ②The second is our lighting program, here is the compiled hex file.

#include "stm32f10x.h"

void Delay()
{
  unsigned int i,j;
	for(i=0;i<1000;i++)
	  for(j=0;j<1000;j++);
}

void LED_Config()
{
    GPIO_InitTypeDef GPIO_InitStructure;                 
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); 
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;      
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;             
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;     
    GPIO_Init(GPIOC, &GPIO_InitStructure);
	GPIO_ResetBits(GPIOC, GPIO_Pin_13);
}

int main(void)
{
	LED_Config();
	while(1)
	{
	    GPIO_SetBits(GPIOC, GPIO_Pin_13);
		Delay();
		GPIO_ResetBits(GPIOC, GPIO_Pin_13);
		Delay();
	}
}

    The minimum program single-chip microcomputer, one LED is for power management, and the other is connected to the PC13 port. The program here is used to make the PC13 port output high and low levels and delay to achieve the blinking effect. The program uses the standard library.

     ③ Check and execute after programming, that is, execute after downloading.

     ④ Select the fourth option: DTR low level reset, RTS high level into BootLoader

     ⑤ Start programming, click to download the program to the microcontroller.

     If the download is successful, then the MCU program is running, and the green LED will blink.

     It is worth noting that after the program is downloaded, it will be executed immediately, without any additional operation, and there is no need to switch BOOT0 to the 0 side, and there is no need to press the reset button. (After power off, power on again, to run the program, you need to switch BOOT0 to 0 first, and then press reset)

    It is normal to download the program here, so there may be no problem with the operation, but sometimes, when you click to start programming, the MCU does not download the program, and the FlyMcu tool shows that it is always connected, and finally fails. This kind of hardware problem troubleshooting is very painful, because we are not sure where there is no problem at all, so we can only keep checking this setting and that configuration. I also had this problem here. I began to suspect that the serial cable was wrongly connected, but after repeated confirmation, it was not the wrong connection. I also suspected that the jumper caps of BOOT0 and BOOT1 were set incorrectly, and changed them repeatedly, and then pressed the reset button, but there was still no change. Finally, I turned the problem to the settings of the FlyMcu tool. In fact, the only thing that may go wrong here is the drop-down selection of DTR and RTS level settings. Finally, I put the problem on the pin header of the MCU. I originally used the pin header, but I didn’t solder every pin, just let him fix it. 3 Later, I removed the pin header and directly connected A9 with male and female Dupont wires. ,A10, it was burned successfully, and the program runs normally. Finally, install the pin header again, solder the A9 and A10 ports, verify again, and the programming is successful again. The lesson this time is that the pin header may not be conductive even though it is inserted into the corresponding circuit board hole.

Guess you like

Origin blog.csdn.net/feinifi/article/details/132328389