Programmer
In the previous article we got acquainted with several variants of ST-Link programmer. In this example I will use the stm32f4discovery debug board as a programmer, simply because I have it. In order to use this debug board as a programmer, you need to do 2 things:
Remove the jumpers that connect the programming lines of the embedded ST-Link to the microcontroller soldered on the board
Connect the signal lines of the programmer to the external microcontroller with the help of a comb, where the SWD bus is taken out.
The picture below shows the pinout of the SWD connector:
Chinese debug boards with the stm32f103c8 microcontroller have a corresponding connector through which you can load the firmware into the MC. These boards look like this:
The pins on the programming connector are labeled GND, CLK, DIO, 3V3. Connection to the programmer is made in this way:
- GND - GND
- CLK - SWCLK
- DIO - SWDIO
In this case, the debug board with stm32f103c8 is soldered to the "grid" where it is connected to the other components on the back side with an insulated wire. The same wire is used to connect the programmer to the debug board:
Software
Now let's move on to the software component. We will need a driver for the programmer and control software, through which we will load the firmware into the microcontroller. To do this we need to download the STM32 ST-LINK utility package on the official site www.st.com. And what should be done before downloading something from www.st.com? That's right! You need to register with them!
So, we got the archive with STM32 ST-LINK Utility package. After installation we connect the programmer to PC via USB and connect power to the debug board. If the drivers for the programmer are not installed automatically, then go to Device Manager, find our STM32 STLink, select Update Driver->Run search on this computer. After that everything should work. Then, from the "Start" menu run the program "STM32 ST-LINK Utility":
The ST-LINK Utility interface looks like this:
Next, we need to make some minor adjustments. In the menu select Target->Settings...
It opens a window like this:
Set the settings as shown on the screenshot and click OK. After that the programmer will automatically connect to the microcontroller being flashed. Let's run through the control buttons:
"Connect to microcontroller" - connects the programmer to the MC. This stops the firmware operation. After that you can perform further manipulations with the flash memory of the MC.
"Disconnect from microcontroller" - after we have done everything, press this button and SL-Link disconnects from the MC, at the same time the firmware loaded into flash-memory starts.
"Clear chip" - pressing this button erases all flash memory of the microcontroller. This must be done before loading another firmware into the MC.
In order to flash our .hex or .bin file into the MC you should do the following. Select Target->Programm... in the menu.
After that we get a window for selecting the firmware file. Select the file we need, and then this window appears:
Here we need to press Start to start the process. After the firmware has been downloaded to the MC, click on the "Disconnect from microcontroller" button.
Those who have worked with AVR microcontrollers before know about such a thing as fuse bits. If you set them incorrectly in AVRs, the firmware may not work correctly. Good news for you: in STM32 there are no fuse bits! It is enough just to pour a file with the control program into the MC and everything will work.
Well, that's probably the end of it, thank you all for your attention.