1. Differences between SWD and traditional debugging methods
1. SWD mode is more reliable than JTAG in high-speed mode. JTAG downloading will fail in the case of large amounts of data, but the probability of SWD failure is much smaller. Basically, you can directly use SWD mode when using JTAG emulation mode, as long as your emulator supports it. So it is recommended that you use this mode.
2. When you are short of one GPIO, you can use SWD emulation, which supports fewer pins.
3. When the size of your board is limited, it is recommended to use SWD mode, which requires fewer pins, and of course requires less PCB space! For example, you can choose a very small 2.54 pitch 5-core terminal as the simulation interface.
2. Emulator support for SWD mode
1. Support of SWD mode by common emulators on the market
(1) JLINKV6 supports SWD emulation mode, but the speed is slow.
(2) JLINKV7 supports SWD emulation mode better, and the speed has been significantly improved, which is 6 times that of JLINKV6.
(3) JLINKV8 supports SWD emulation mode very well, and the speed can reach 10M.
(4) ULINK1 does not support SWD mode.
(5) Pirated ULINK2 supports SWD mode very well, and the speed can reach 10M.
(6) Genuine ULINK2 supports SWD mode very well, and the speed can reach 10M.
2. Differences in SWD hardware interface
(1) The hardware interfaces required by JLINKV6 are: GND, RST, SWDIO, SWDCLK
(2) The hardware interfaces required by JLINKV7 are: GND, RST, SWDIO, SWDCLK
(3) The hardware interfaces required by JLINKV8 are: VCC, GND, RST, SWDIO, SWDCLK (Note: Below are my actual connections and corresponding experimental results using JLINKV8)
(4) ULINK1 does not support SWD mode
(5) The hardware interfaces required by the pirated ULINK2 are: GND, RST, SWDIO, SWDCLK
(6) The hardware interfaces required by the genuine ULINK2 are: GND, RST, SWDIO, SWDCLK
From this we can see that only JLINKV8 needs 5 pins, that is, one more VCC pin. The advantage is that the simulator needs to use the RST pin to simulate the target board. It is not very good to use the VCC inside the simulator for this function. Therefore, JLINKV8 chooses to share GND with the target board, but not VCC. Therefore, I think this mode is the most reasonable. Of course, it is not wrong for the simulator and the target board to share GND and VCC.
3. Setting SWD mode in MDK
When debugging simulation, it is sufficient to use J-LINK's Cortex-M3 method, and its function is very good under MDK. The download speed is very fast with the standard 20-pin JTAG, which is generally used by beginners. However, the SWD method seems to be faster, more convenient, and simpler. It is more beneficial for users who have strict requirements on board space and tight I/O port resources in the project. Normal JTAG requires 20 pins, while J-Link's SWD only needs 2 wires (PA13/JTMS/SWDIO, PA14/JTCK/SWCLK) (plus the power line , it is 4), which saves 3 I/O ports (PA15/JTDI, PB3/JTDO, PB4/JNTRST) for other use, and can save part of the board space (only 4 ports are needed).
Next, I will talk about some steps, precautions and issues that need attention for SWD two-wire simulation.
The connection of the interface is as follows: connect JLINK's 1, 7, 9, and 20 to the VCC, JTMS, JTCK, and GND of JTAG on your development board using Dupont lines!
Next, I will tell you how to use the SWD settings:
Open the project OPTION settings:
In the settings, set it to SWD mode as shown above. You can set the speed according to your actual needs. If your board power supply system is not particularly stable, the ripple is relatively large or the simulation line is relatively long, you can set it to 500K or 1M. If the environment is very good, of course you can choose 10M, and of course the speed will fly.
Remember not to ignore the USB or TCP mode in the lower left corner. Of course, we choose USB mode because sometimes the default mode is TCP mode. If we ignore this setting, the simulation will often fail to connect.
/////End of reprint
The following is my own test (using JLINK V8)
(1) To debug in SW mode, you actually need to connect pins 1, 7, 9, 15, and 20. Some materials say that 6 pins are needed (pin 13 SWO also needs to be connected), which is incorrect. SWO does not need to be connected.
The screen that appears when the 5 pins are connected as described above
The screen that appears when pin 1 is not connected
(2) There is not much difference in speed between the two methods.
Test again:
(1) Do not connect pin 15, which is the RESET pin. Only connect four pins , namely Vref, SWDIO, SWCLK, and GND.
(2) When setting, select the Reset position: AutoDetect, and you can download and simulate normally.
(3) If the Reset bit is selected as: HW Reset, downloading will not be possible.
(4) The speed is far from as fast as mentioned in the above reprint. It takes about 40 seconds to erase and write the ucosDemo project. The following is the amount of code for this project:
Program Size: Code=96830 RO-data=143650 RW-data=1016 ZI-data=16440
But there is a phenomenon, that is, after downloading once, exiting, and then entering again (without recompiling), it seems that there is no erasing and downloading process, and the time flies very fast. Maybe this is the reason for the fast time mentioned above?
////The following is from 21icbbs
Q: I have been playing with 103ZE on the core board. All small programs are debugged in RAM, and only three wires are connected: GND SWDIO SWCLK (VCC is directly connected to the inside of JLINK), which is very convenient. But today I want to try IIS and put a large amount of data in it, so I want to burn it into FLASH. I found that the progress bar is finished very quickly, and then it shows failure. I searched it on Google and it said that RESET should be connected, so I connected it, and it was downloaded... It's terrible. I have drawn the PCB, but there are only 4 wires (VCC SWDIO SWCLK GND). What should I do in the future?
A: You don't have to connect it. You can use system reset or vect reset instead of hardware reset in the MDK emulator settings. The former is more applicable to a wider range of situations.
/////End of reprint
JTAG pins can be reused as IO ports, but in this case, JLINK cannot connect to the chip. There are two solutions:
(1) Write another program, do not reuse JTAG as an I/O port, and then write this program into the chip using a serial port tool ;
(2) Set BOOT0/BOOT1 to boot from internal RAM. Then the program in FLASH will not be executed after power-on, and JLINK can successfully "take over" the JTAG pin.