Error about OpenOCD+JLink under Linux

JLink is IAR J-Link-ARM version 6.0. At first when I run OpenOCD in terminal it gave erro messgae like:

Open On-Chip Debugger 0.2.0-in-development (2009-06-10-15:31) svn:2182

BUGS? Read http://svn.berlios.de/svnroot/repos/openocd/trunk/BUGS

$URL: http://svn.berlios.de/svnroot/repos/ope … /openocd.c $

12 kHz

jtag_nsrst_delay: 100

jtag_ntrst_delay: 100

Error: J-Link command 0x01 failed (-1)

Error: J-Link command EMU_CMD_VERSION failed (-1)

Error: J-Link command 0x01 failed (-1)

Error: J-Link command EMU_CMD_VERSION failed (-1)

Error: J-Link command 0x01 failed (-1)

Error: J-Link command EMU_CMD_VERSION failed (-1)

Info : J-Link initial read failed, don’t worry

Info : J-Link JTAG Interface ready

Error: J-Link command 0xdd failed (-1)

Error: J-Link command 0xdf failed (-1)

Error: J-Link setting speed failed (-1)

Error: usb_bulk_write failed (requested=6, result=-1)

Error: jlink_tap_execute, wrong result -107 (expected 1)

Error: usb_bulk_write failed (requested=6, result=-1)

Error: jlink_tap_execute, wrong result -107 (expected 1)

Error: J-Link command 0xdd failed (-1)

Error: J-Link command 0xde failed (-1)

Error: J-Link command 0xdc failed (-1)

Error: J-Link command 0xde failed (-1)

Error: J-Link command 0xdc failed (-1)

Error: J-Link command 0xdf failed (-1)

Error: usb_bulk_write failed (requested=6, result=-1)

Error: jlink_tap_execute, wrong result -107 (expected 1)

Error: J-Link command 0xdd failed (-1)

Error: J-Link command 0xdf failed (-1)

Error: usb_bulk_write failed (requested=6, result=-1)

Error: jlink_tap_execute, wrong result -107 (expected 1)

Error: usb_bulk_write failed (requested=6, result=-1)

Error: jlink_tap_execute, wrong result -107 (expected 1)

Error: couldn’t bind to socket: Address already in use

and I use J-link commander to get the info about the jlink. What i got is :

SEGGER J-Link Commander V4.03a (‘?’ for help)

Compiled Feb 2 2009 11:34:21

Updating firmware: J-Link ARM V6 compiled Jan 15 2009 11:58:34

Replacing firmware: J-Link ARM V6 compiled Jul 30 2008 11:24:59

Waiting for new firmware to boot

New firmware booted successfully

****** Error: Communication timed out after firmware update

DLL version V4.03a, compiled Feb 2 2009 11:34:13

Unable to retrieve firmware info !

S/N : 156003954

OEM : IAR

VTarget = 3.287V

Info: TotalIRLen = 9, IRPrint = 0x0011

WARNING: Identified core does not match configuration. (Found: Cortex-M3, Configured: None)

Info: Found Cortex-M3 r1p1, Little endian.

Info: TPIU fitted.

Info: FPUnit: 6 code (BP) slots and 2 literal slots

Found 2 JTAG devices, Total IRLen = 9:

Id of device #0: 0x3BA00477

Id of device #1: 0x16410041

Cortex-M3 identified.

JTAG speed: 5 kHz

J-Link>f

Unable to retrieve firmware info !

J-Link>usb

Connecting to J-Link via USB (Port: 0)

Updating firmware: J-Link ARM V6 compiled Jan 15 2009 11:58:34

Replacing firmware: J-Link ARM V6 compiled Jul 30 2008 11:24:59

Waiting for new firmware to boot

New firmware booted successfully

****** Error: Communication timed out after firmware update

DLL version V4.03a, compiled Feb 2 2009 11:34:13

Unable to retrieve firmware info !

S/N : 156003954

OEM : IAR

VTarget = 3.287V

Info: TotalIRLen = 9, IRPrint = 0x0011

Info: Found Cortex-M3 r1p1, Little endian.

Info: TPIU fitted.

Info: FPUnit: 6 code (BP) slots and 2 literal slots

Found 2 JTAG devices, Total IRLen = 9:

Id of device #0: 0x3BA00477

Id of device #1: 0x16410041

Cortex-M3 identified.

JTAG speed: 5 kHz

J-Link>

The board is STM32F10X_128k_Eval.

I m totally new to OpenOCD and Jlink. Looking for help. Thanks very much.

Anyone have any info on this? I really wanted to use linux for development and it seems like there is no way with the current state of this driver.

Here’s what I get, I hope that helps

brfindla@LinuxAtom:~/dev/linux$ openocd

Open On-Chip Debugger 0.2.0 (2009-08-10-12:31) Release

$URL: http://svn.berlios.de/svnroot/repos/ope … /openocd.c $

For bug reports, read http://svn.berlios.de/svnroot/repos/openocd/trunk/BUGS

Info : J-Link initialization started / target CPU reset initiated

Error: J-Link command 0xde failed (-1)

Error: J-Link command 0xdc failed (-1)

Error: J-Link command 0x01 failed (-1)

Error: J-Link command EMU_CMD_VERSION failed (-1)

Info : J-Link JTAG Interface ready

Error: J-Link command 0xdd failed (-1)

Error: J-Link command 0xdf failed (-1)

Error: J-Link setting speed failed (-1)

Error: usb_bulk_write failed (requested=6, result=-1)

Error: jlink_tap_execute, wrong result -107 (expected 1)

Error: usb_bulk_write failed (requested=6, result=-1)

Error: jlink_tap_execute, wrong result -107 (expected 1)

Error: J-Link command 0xdd failed (-1)

Error: J-Link command 0xde failed (-1)

Error: J-Link command 0xdc failed (-1)

Error: J-Link command 0xde failed (-1)

Error: J-Link command 0xdc failed (-1)

Error: J-Link command 0xdf failed (-1)

Error: usb_bulk_write failed (requested=6, result=-1)

Error: jlink_tap_execute, wrong result -107 (expected 1)

Error: J-Link command 0xdd failed (-1)

Error: J-Link command 0xdf failed (-1)

Error: usb_bulk_write failed (requested=6, result=-1)

Error: jlink_tap_execute, wrong result -107 (expected 1)

Error: usb_bulk_write failed (requested=6, result=-1)

Error: jlink_tap_execute, wrong result -107 (expected 1)

Hi All,

I’m pretty time constrained, but will attempt to submit my fix to openOCD. My problem was that I was working on a mini2440 board which has only a 10 pin JTAG connector. Conveniently, they left off the RTCK signal (Pin 11 on the 20 pin connector) which is used for adaptive clocking. I have gone into jlink.c into the jlink_init function and wrote the code to see if adaptive clocking was working (which it won’t on a 10 pin). If it fails, then I manually set the speed to 1/2 Max. In the event that I do not get the time to check in the code to openOCD, I post the necessary code here. I modified jlink_init() and jlink_speed(), and jlink_get_speeds() is an entirely new function.

Best all brfindla from Gods Country… beautiful Nashua, NH

#define EMU_CMD_GET_SPEEDS              0xc0
#define EMU_CAP_GET_SPEED_INFO     	9  

static int jlink_init(void)
{
	int i, base_freq = 0, div_min = 0, freq;

	jlink_jtag_handle = jlink_usb_open();

	if (jlink_jtag_handle == 0)
	{
		LOG_ERROR("Cannot find jlink Interface! Please check connection and permissions.");
		return ERROR_JTAG_INIT_FAILED;
	}
	
	/*
	 *  The next three instructions were added after discovering a problem while using an oscilloscope.  For the V8
	 *	SAM-ICE dongle (and likely other j-link device variants), the reset line to the target microprocessor was found to
	 *	cycle only intermittently during emulator startup (even after encountering the downstream reset instruction later
	 *	in the code).  This was found to create two issues:  1) In general it is a bad practice to not reset a CPU to a known
	 *	state when starting an emulator and 2) something critical happens inside the dongle when it does the first read
	 *	following a new USB session.  Keeping the processor in reset during the first read collecting version information
	 *	seems to prevent errant "J-Link command EMU_CMD_VERSION failed" issues.
	 */
	
	LOG_INFO("J-Link initialization started / target CPU reset initiated");
	jlink_simple_command(EMU_CMD_HW_TRST0);
	jlink_simple_command(EMU_CMD_HW_RESET0);
	usleep(1000);

	jlink_hw_jtag_version = 2;

	if (jlink_get_version_info() == ERROR_OK)
	{
		/* attempt to get status */
		jlink_get_status();
	}

	LOG_INFO("J-Link JTAG Interface ready");
	jlink_reset(0, 0);
	jtag_sleep(3000);
	jlink_tap_init();  	

	jlink_speed(jtag_get_speed());
	
	/* v5/6 jlink seems to have an issue if the first tap move
	 * is not divisible by 8, so we send a TLR on first power up */
	for (i = 0; i < 8; i++) {
		jlink_tap_append_step(1, 0);
	}

	/* There are now ARM Boards with 10 Pin JTAG connectors.
	   Amoung them are the FriendlyArm mini2440 a Samsung S3C2440A
           based board. Unfortunately, they dropped the RTCK (pin 11 on 
	   20 pin connector) signal which is used for adaptive clocking. 
	   We test this by checking jlink_tap_execute which will fail on 
	   a 10 pin JTAG connector as we are set to adaptive clocking.
           If it fails, we attept to set the clock to 1/2 max speed
           and reinitiate the sequence.
	 */
	LOG_INFO("Testing TAP - Adaptive clocking with 10 pin JTAG will Fail");
	if(ERROR_OK != jlink_tap_execute()){	
		LOG_INFO("Failed TAP - Attempting Recovery - Setting Clk Speed Manually");
		jlink_get_speeds(&base_freq, &div_min);
		freq = base_freq/div_min;
        	jlink_speed(freq/2);
		LOG_INFO("Max JLINK Freq: %dkHZ, setting JTAG speed to %dkHZ",
			freq, freq/2);
		for (i = 0; i < 8; i++) {
			jlink_tap_append_step(1, 0);
		}
		if(ERROR_OK !=jlink_tap_execute()){
			LOG_ERROR("FAIL TAP - Setting Clk Speed Manually did not fix the problem.");
		} else {
			LOG_INFO("PASSED TAP - RTCK PIN (adaptive clocking) probably not connected");
		}
	}

	return ERROR_OK;
}

static int jlink_speed(int speed)
{
	int result, base_freq = 0, div_min = 0, jlink_max_speed;
	
	jlink_get_speeds(&base_freq, &div_min);
	jlink_max_speed = base_freq/div_min;

	if (speed > jlink_max_speed)
	{
		LOG_INFO("Ignoring speed request: %dkHz exceeds %dkHz maximum",
				speed, jlink_max_speed);
		return ERROR_OK;
	}

	/* check for RTCK setting */
	if (speed == 0)
		speed = -1;

	usb_out_buffer[0] = EMU_CMD_SET_SPEED;
	usb_out_buffer[1] = (speed >> 0) & 0xff;
	usb_out_buffer[2] = (speed >> 8) & 0xff;

	result = jlink_usb_write(jlink_jtag_handle, 3);
	if (result != 3)
	{
		LOG_ERROR("J-Link setting speed failed (%d)", result);
		return ERROR_JTAG_DEVICE_ERROR;
	}

	return ERROR_OK;
}

static int jlink_get_speeds(int *base_freq, int *div_min )
{
	int result;
	uint32_t jlink_caps;

	/* query hardware capabilities */
	jlink_simple_command(EMU_CMD_GET_CAPS);

	result = jlink_usb_read(jlink_jtag_handle, 4);
	if (4 != result)
	{
		LOG_ERROR("J-Link command EMU_CMD_GET_CAPS failed (%d)\n", result);
		return ERROR_JTAG_DEVICE_ERROR;
	}

	jlink_caps = buf_get_u32(usb_in_buffer, 0, 32);
	LOG_INFO("JLink caps 0x%x", (unsigned)jlink_caps);

	if (jlink_caps & (1 << EMU_CAP_GET_SPEED_INFO))
	{
		jlink_simple_command(EMU_CMD_GET_SPEEDS);

		result = jlink_usb_read(jlink_jtag_handle, 6);
		if (result != 6)
		{
			LOG_ERROR("J-Link command EMU_CMD_GET_SPEEDS failed (%d)\n", result);
			return ERROR_JTAG_DEVICE_ERROR;
		}

	        /* Get our base frequency in kHZ */
		*base_freq = (usb_in_buffer[0] + (usb_in_buffer[1] << 8) + 
				(usb_in_buffer[2] << 16) + (usb_in_buffer[3] << 24))/1000;
		*div_min = usb_in_buffer[4] + (usb_in_buffer[5] << 8);

	        LOG_INFO("Base Frequency = %dkHZ, Minimum Divider = %d", *base_freq, *div_min);
	}
       
	return ERROR_OK;
}