# 0. The reason for the project is
that my NANO board with stlink on it will be returned to the teacher in the near future. So I don’t have the board and stlink anymore, but for a stmer, how can I not have stlink! ? So I decided to buy a stlink. But some of the ones I bought were not fully functional, some were very expensive, and some were quite large. At the same time, I didn’t have a board after returning it, so I decided to make a minimal system blueboard with onboard stlink peripheral circuits. In this way, after flashing the stlink firmware, it can be used as stlink. When not flashing the stlink firmware, it can also be used as a minimal system. System version to use. But if I make one myself, if others want to copy my project, they have to make it from scratch like me, which is a bit troublesome. **Considering that if you use stlink, there is a high probability that you will have the smallest system blue board that can be purchased. So I decided to let everyone use their own little blue board and use my stlink extension (pin_to_pin compatible with the smallest system board on the market) to make a stlink debugger. **
Let me start with this: The hardware of this project is not very difficult. The main reason is that there are too many pitfalls in the mysterious capacity of c8t6 and firmware compatibility issues.
# 1. Introduction
ST-LinkV2-1: Supports STM32 debugging, with virtual serial port and virtual U disk download. What this project produces is ST-Link V2-1 (extended plate).
The stlink expansion board + the STM32F103C8T6 core board available on the market can form a complete stlink V2-1 debugger.
# 2. The
3D picture of the stlink expansion board double-layer board is as follows.
![image.png]

The 3D diagram of my c8t6 minimum system four-layer board is as follows. (This is my first drawing, please forgive me for any unreasonable parts)
![image.png]

The actual picture of the stlink expansion board double-layer board is as follows.
![1664802604744.jpg]

# 3. Schematic diagram reference
The schematic diagram of this project refers to the ST-link V2-1 design on the NANOF1 development board of Punctual Atom, as shown below.
![image.png]

## 3.1 ST-LINK V2.1 circuit
STlink v2.1 on the NANOF1 development board. Here I use the chip on the stm32f103c8t6 minimum system board, and some peripheral circuits are on the stlink expansion board.
![image.png]

## 3.2 USB interface circuit
USB_ST_LINK on the NANOF1 development board can be directly cv'd over. The extended version in this design uses **female header** and is connected to the stm32f103c8t6 minimum system board.
![image.png]

## 3.3
The interface for downloading circuit flash firmware is on the minimum system board, and the stlinkV2.1 interface is on the expansion board.
![image.png]

## 3.4 COM indicator light
This LED will display the ST-LINK status:
LED flashes: Data is being exchanged between the target and the PC.
LED is always on: Communication between PC and ST-LINK has been established.
![image.png]

## 3.5 For the LDO power circuit,
please refer to the manual of this chip. (1117 is used on NANOF1. Why don’t I use 1117? Because my smallest system board is a bit small and the big 1117 takes up too much space)
![image.png]

# 4 ST-Link V2.1 Firmware Burning & Firmware Update
# # 4.1 Obtaining Firmware
Since ST officially does not make the ST-Link source code public, nor does it directly provide the ST-Link firmware (because of read protection), there are multiple versions of firmware transmitted online. Here I only found the V2J28 version of the firmware (see attachment), but this firmware cannot be used for c8t6 with 64k flash (I have a solution later, and it has been successful). 128k c8t6 and cbt6 can use the V2J28 version without brainstorming (the actual test is complete ok) or higher. How to check the flash size of c8t6, [see my B site](https://www.bilibili.com/video/BV1RP411j7GT?share_source=copy_web&vd_source=584714a0cf29c22026ad8acbe10986af).
I successfully extracted the V2J27 version (see attachment). The bricked 64k c8t6 can use this version (both hex and bin formats are available. Whether you use the serial port tool flymcu, Utility or STM32CubeProgrammer, you can flash it. Finally Get rid of the mysterious download logic of flymcu, haha)
**Note: 128k c8t6 or cbt6 flashed with V2J27, usually can be used directly; 64k c8t6 flashed with V2J27, there is a small probability that it cannot be used, then just use ST- Upgrade LinkUpgrade_V2.J27.M15 again, then unplug the USB and restart the burning software. (Actual test successful) **
## 4.2
You can choose any of these 3 burning software, please choose the one that is convenient.
1. flymcu (see attachment): The main function is programming and burning. It can only use the serial port and cooperate with the USB to TTL download of CH340 (51 friends said that they are familiar with the formula).
![image.png]

2. [Utility](https://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32- programmers/stsw-link004.html) (also available in attachments): The main function of STM32 ST-LINK Utility is also programming download, which must be downloaded using stlink, which means you must have a working stlink and borrow it from the friend next door.
![image.png]

3. [STM32CubeProgrammer](https://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-programmers/stm32cubeprog.html) (It’s too big, and there are no attachments. If you want to use it, go directly to the official website): The main function is also programming download, and it supports Windows, Linux, and macOS operating systems. At the same time, you need to install the [JRE](https://www.java.com/zh-CN/download/) environment to use it. I have only used stlink to download this tool. It seems that this tool can also use serial port and USB.
![image.png]

**I use Utility and STM32CubeProgrammer, because sometimes I have to open STM32CubeProgrammer to recognize the stlink I made. **
## 4.3 Firmware Update
** Note: Do not upgrade the 64k c8t6, it is very likely to become bricked. If it becomes bricked, you need to re-flash my V2J27. **
1. Use ST-LinkUpgrade_V2.J27.M15 (see attachment) to upgrade. This upgrader can only upgrade to V2J27. It is not recommended for non-64k flash.
2. Download the official firmware upgrade application [STSW-LINK007](https://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/ stm32-programmers/stsw-link007.html): Firmware upgrade for ST-LINK, ST-LINK/V2, ST-LINK/V2-1 and STLINK‑V3 boards.
2. Use the upgrade tool provided by STM32CubeProgrammer or STM32 ST-LINK utility to upgrade.
3. Use the built-in upgrade tool of Keil MDK-ARM to upgrade. When the ST-link version is lower than the built-in version of MDK, you will be prompted to upgrade.
For the video of the firmware burning and update process, please see [My B Station](https://www.bilibili.com/video/BV1RP411j7GT?share_source=copy_web&vd_source=584714a0cf29c22026ad8acbe10986af).
The U disk drag and drop download video and the stlink serial port transceiver video are shown in the attachment.
# 5 Verification
! [QQ screenshot 20221005205431.png]

![image.png]

Generally, ST-Debug is displayed and the UNDEFINED folder will automatically pop up when plugged into the computer, which means it is ok.
# 6 Test
1. Test the burning function, use Keil-MDK, download the program successfully, indicating that the burning function is normal. (The video is too large, it is on my B station)
2. Test the Debug function, use Keil-MDK for debugging, It can be debugged, indicating that the Debug function is normal. (The video is on my B site)
3. To test the U disk drag and burn function, you need to generate a bin file ([bin file generation method](https://blog.csdn.net/Mr__Shen /article/details/105184963)), drag the bin file to the USB flash drive simulated by ST-link, and burn it successfully, indicating that the virtual USB flash drive functions normally. (See attachment for video)
4. Test the serial port transceiver function: Use Dupont cable to connect the TX and RX of ST-LINK V2-1, open the serial port assistant, send data, and the receiving area receives the same data, indicating that the serial port transceiver is normal (see attachment for video) ); or let the usart port of other development boards send data to the virtual serial port for verification. (The video is on my B site)
# 7 Notes
1. Recent versions of ST-LINK have added read protection, and the SWD port is locked On, the firmware cannot be read or written through the SWD port.
2. If you want to change to firmware such as DAP-LINK, you cannot burn the firmware through the SWD port, but you can erase the STM32 firmware information through ISP, and then you can use the SWD port to read and write normally. (This article refers to Siege Lion)
# 8 Error record
The error record document is in [My CSDN](https://blog.csdn.net/Aaags/article/details/127196750)
The video is in [My B station](https ://www.bilibili.com/video/BV1RP411j7GT?share_source=copy_web&vd_source=584714a0cf29c22026ad8acbe10986af)
-----
*Finally: If you have any questions, you can leave a message in the comment area. We will reply in time after seeing the message. If this project of mine is helpful to you, please like it in the comment area, thank you! *
-----