In some cases, the J-Link/Flasher emulator may not be able to connect to the chip correctly, resulting in debugging failure in the IDE, with an error message such as "Failed to get CPU status after 4 retries". The chip status cannot be obtained, which may be caused by the failure of J-Link to connect to the chip successfully.
1. Verify the connection between J-Link and PC
J-Link Commander is usually used to verify the connection status between J-Link and PC, and whether the computer can successfully identify J-Link. Open J-Link Commander to view the current J-Link connection status and hardware version information.
If you cannot see the above information, you can open the device manager on your computer to see if the J-Link device can be detected in the device manager, as shown in the figure below:
If the device cannot be detected successfully, please try the following methods:
1. Restart the PC to ensure that the USB protocol itself is not in a messed up state
2. Replace the USB connection cable
3. Try another USB port
4. If a USB hub is used, remove it
5. Try to reinstall the J-Link driver, or upgrade the J-Link driver to the latest version
6. Switch to another PC for testing to rule out problems with the PC itself
2. Verify the connection between J-Link and chip
When verifying the connection between J-Link and the chip, it is recommended to use the chip company's official evaluation board or other reliable hardware devices for verification to avoid problems that may be caused by incorrect hardware design.
First, update the J-Link driver to the latest version through the following link:
https://www.segger.com/downloads/jlink
Follow the steps below to connect J-Link to the chip:
1. Connect J-Link to the PC
2. Power the development board
3. Connect J-Link to the development board
4. Open J-Link Commander and enter commands such as connect to test
If the connection fails when you enter the connect command line, check the following:
1. Vtref = 0 v
J-Link uses the target board reference voltage to create the level of the debug signal, so this pin must be connected to the chip's power pin to obtain the correct target board reference voltage. When the situation shown in the figure below occurs, please check the chip's power supply and the connection of the Vtref pin.
2. Check the power supply of the target board and verify its power supply
Use a multimeter to measure the voltage between pin 1 (Vtref) and pin 4 (GND) of the J-Link to make sure that the J-Link can detect the reference voltage of the target board.
3. Confirm whether the correct debugging interface is selected
There are multiple debugging interfaces on different chips, such as JTAG and SWD. First, you need to confirm whether the chip can support a certain debugging interface. For example, some earlier chip models may only support the JTAG debugging interface but not the SWD debugging interface.
In addition to confirming that the chip can support the debug interface, you should also further check the hardware design of the debug interface of the target board to ensure that the chip's debug pins are successfully connected to the debug interface.
4. After programming the target device, the connection can no longer be established
Please check the relevant security settings of the target device. In some devices, specific registers can be written to disable the debug interface, resulting in a failure to connect, or there are other security measures on the chip that affect the debugging function of the chip. It is recommended to check the chip manual for confirmation.