This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123Gx Unable to connect to target device

Hello, when debugging I get the error that it cannot not find the device. It cannot be found in LM flash and doesn't appear in the com ports in device manager. It still holds the previously installed program but I just want it gone and my launchpad operational. I seriously need help because I have two boards with the same issue. 

  • Hello Jonathan

    Since you have 2 boards exhibiting the same problem, my usual suspect would be

    1. Did the boards work fine when you received them?
    2. Did you use USB to flash in a program or did you always use the JTAG to flash the program?
    3. When you connect the board to the PC, what does the Windows device manager show?
  • 1. Yes  both of the boards were operational before I loaded the program that caused it to freeze. I'm a student and one of the boards had more than 20+ sample codes ran on it flawlessly until it froze and then I grabbed the second and ran a sample code then my modified code and it seized up as well.

    2. The boards were programmed from USB to flash method and I'm not sure if the University has a JTAG device so if that is needed to debug the boards  I'll have to order one.  

    3. When the I plug the controller in the USB the device manager shows no change as if nothing was added to the COM ports. I also checked to see if it was my computer that was the real issue so I grabbed another students board, plugged it in and the device manager recognized it and I was able to run class example programs (not my modified program that caused the first two to freeze) from CCS without freezing up so I know all of that end is functional.

    NOTE: The modified program that I am talking about that froze the two boards is just a simple PWM function set at 50HZ

    /*************************************************
     Signal output with PWM
    
     By Dr. Xinrong Li, xinrong@UNT.EDU, Mar. 6, 2015
     *************************************************/
    
    #include <stdint.h> // Variable definitions for the C99 standard.
    #include <stdbool.h> // Boolean definitions for the C99 standard.
    
    #include "inc/tm4c123gh6pm.h" // Definitions for the interrupt and register assignments.
    #include "inc/hw_memmap.h" // Memory map definitions of the Tiva C Series device.
    #include "inc/hw_types.h" // Definitions of common types and macros.
    #include "inc/hw_ssi.h"
    
    #include "driverlib/sysctl.h" // Definitions and macros for System Control API of DriverLib.
    #include "driverlib/interrupt.h" // Defines and macros for NVIC Controller API of DriverLib.
    #include "driverlib/gpio.h" // Definitions and macros for GPIO API of DriverLib.
    #include "driverlib/timer.h" // Defines and macros for Timer API of DriverLib.
    #include "driverlib/pin_map.h" //Mapping of peripherals to pins for all parts.
    #include "driverlib/uart.h" // Definitions and macros for UART API of DriverLib.
    #include "driverlib/pwm.h" // Definitions for PWM API of DriverLib.
    
    
    #include "utils/uartstdio.h" // Prototypes for the UART console functions.
    							 // Needs to add "utils/uartstdio.c" through a relative link.
    
    
    #define TIMER0_FREQ    2 // Freqency in Hz, heartbeat timer
    #define UART0_BAUDRATE    115200 // UART baudrate in bps
    
    #define PWM_FREQ    50 // Frequency in Hz
    #define PWM_DUTYCYCLE_BASE    100
    #define PWM_DUTYCYCLE_MIN    1
    #define PWM_DUTYCYCLE_MAX    9.5
    
    #define RED_LED    GPIO_PIN_1
    #define BLUE_LED    GPIO_PIN_2
    #define GREEN_LED    GPIO_PIN_3
    
    #define NUM_DISP_TEXT_LINE    4
    
    
    // function prototypes
    void init_LEDs(void);
    void init_timer(void);
    void init_UART(void);
    void init_PWM(void);
    
    void Timer0_ISR(void);
    
    extern void UARTStdioIntHandler(void);
    
    
    // global variables
    uint8_t cur_LED = RED_LED;
    const char *disp_text[NUM_DISP_TEXT_LINE] = {
    		"\n",
    		"UART and LED Demo\n",
    		"H: help, R: red, G: green, B: blue, I: increase dutycycle, D: decrease dutycycle.\n",
    		"> " };
    
    uint32_t sys_clock;
    
    uint32_t PWM_clock;
    uint32_t PWM_timer_load;
    
    // PWM duty cycle: percentage of one period in which the signal is high
    uint8_t PWM_dutycycle = 1; //  duty cycle = PWM_dutycycle/PWM_DUTYCYCLE_BASE
    float PWM_dutycycle_step = 1;
    
    
    int main(void)
    {
    	uint32_t i;
    	unsigned char user_cmd;
    
    	// Configure system clock.
    	//SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // 50 MHz
    	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // 40 MHz
    	sys_clock = SysCtlClockGet();
    	//SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // 80 MHz
    	//sys_clock = 80000000; // Hard coded for 80MHz because of a bug in SysCtlClockGet().
    
    	init_LEDs();
    	init_UART();
    	init_timer();
    	init_PWM();
    
    	// Enable the processor to respond to interrupts.
    	IntMasterEnable();
    
    	// Start the timer by enabling operation of the timer module.
    	TimerEnable(TIMER0_BASE, TIMER_A);
    
    	// Initial display on terminal.
    	for(i=0; i<NUM_DISP_TEXT_LINE; i++)
    		UARTprintf(disp_text[i]);
    
    	while(1) {
    		// Read user inputs from UART if available.
    		if(UARTRxBytesAvail())
    	        user_cmd = UARTgetc();
    		else
    			user_cmd = 0;
    
    		switch(user_cmd){
    		case '\r':
    		case ' ':
    		case 'H':
    		case 'h':
    			for(i=0; i<NUM_DISP_TEXT_LINE; i++)
    				UARTprintf(disp_text[i]);
    			break;
    		case 'R':
    		case 'r':
    			cur_LED = RED_LED;
    			UARTprintf("\n> ");
    			break;
    		case 'B':
    		case 'b':
    			cur_LED = BLUE_LED;
    			UARTprintf("\n> ");
    			break;
    		case 'G':
    		case 'g':
    			cur_LED = GREEN_LED;
    			UARTprintf("\n> ");
    			break;
    		case 'I':
    		case 'i':
    			UARTprintf("\n> ");
    			PWM_dutycycle = PWM_dutycycle + PWM_dutycycle_step;
    			if(PWM_dutycycle > PWM_DUTYCYCLE_MAX) {
    				PWM_dutycycle = PWM_DUTYCYCLE_MAX;
    				UARTprintf("PWM_dutycycle has reached max value.\n> ");
    			}
    			PWMPulseWidthSet(PWM0_BASE, PWM_OUT_6, PWM_dutycycle*PWM_timer_load/PWM_DUTYCYCLE_BASE);
    			break;
    		case 'D':
    		case 'd':
    			UARTprintf("\n> ");
    			PWM_dutycycle = PWM_dutycycle - PWM_dutycycle_step;
    			if(PWM_dutycycle < PWM_DUTYCYCLE_MIN) {
    				PWM_dutycycle = PWM_DUTYCYCLE_MIN;
    				UARTprintf("PWM_dutycycle has reached min value.\n> ");
    			}
    			PWMPulseWidthSet(PWM0_BASE, PWM_OUT_6, PWM_dutycycle*PWM_timer_load/PWM_DUTYCYCLE_BASE);
    			break;
    		}
    	}
    }
    
    
    void init_LEDs(void)
    {
    	// Enable and configure LED peripheral.
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable GPIO Port F.
    	// Three onboard LEDs, R:PF1, B:PF2, G:PF3.
    	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
    }
    
    
    void init_timer(void)
    {
    	// Enable and configure Timer0 peripheral.
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    	// Configure as a 32-bit timer in periodic mode.
    	TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
    	// Initialize timer load register.
    	TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1);
    
    	// Registers a function to be called when the interrupt occurs.
    	IntRegister(INT_TIMER0A, Timer0_ISR);
    	// The specified interrupt is enabled in the interrupt controller.
    	IntEnable(INT_TIMER0A);
    	// Enable the indicated timer interrupt source.
    	TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    }
    
    
    void init_UART(void)
    {
    	// Enable and configure UART0 for debugging printouts.
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    	GPIOPinConfigure(GPIO_PA0_U0RX);
    	GPIOPinConfigure(GPIO_PA1_U0TX);
    	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
    	// Registers a function to be called when the interrupt occurs.
    	IntRegister(INT_UART0, UARTStdioIntHandler);
    	UARTStdioConfig(0, UART0_BAUDRATE, sys_clock);
    }
    
    
    void init_PWM(void)
    {
    	// PWM clock is set to be system clock divided by the specified divider, 64 in this case.
    	SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
    	PWM_clock = sys_clock/64;
    
    	// Enable and configure PC4 (M0PWM6) as PWM output
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    	GPIOPinTypePWM(GPIO_PORTC_BASE, GPIO_PIN_4);
    	GPIOPinConfigure(GPIO_PC4_M0PWM6);
    
    	PWM_timer_load = (PWM_clock/PWM_FREQ) -1;
    	PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN);
    	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, PWM_timer_load);
    
    	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_6, PWM_dutycycle*PWM_timer_load/PWM_DUTYCYCLE_BASE);
    	PWMOutputState(PWM0_BASE, PWM_OUT_6_BIT, true);
    	PWMGenEnable(PWM0_BASE, PWM_GEN_3);
    }
    
    
    // Timer0 interrupt service routine
    void Timer0_ISR(void)
    {
    	// Clear the timer interrupt.
    	TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    
    	// Blink LED. Read the current state of GPIO pins and write back the opposite state.
    	if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3)) {
    		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
    	}
    	else {
    		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, cur_LED);
    	}
    }
    

  • Hello Jonathan

    Regarding #2: I meant if it was the USB DFU you were using or the CCS Flashing. If it is the latter then it is JTAG.

    I don't see anything wrong with the code. Now is there something connected to your board?
  • I was using CCS flashing so I suppose I was using the JTAG. No additional device was connected to the board when I ran the program. The fist time it ran I had an oscilloscope connected to PC4 to measure the PWM as I was increasing/decreasing the the duty cycle via PUTTY with no issues. However when I tried to implement the same program with the MG-946R servo and increased the duty cycle, either PUTTY or the launchpad glitched where it would print the opening prompt repetitively until the 'Unable to locate target' error occurred and wasn't able to be found since. I am not sure how connecting a servo would cause it to do this or perhaps it's unrelated.
  • Hello Jonathan

    Did you remove the servo and then try. What is the current requirement of the servo motor?
  • Running current for the servo requires 500mA - 900mA with a stall current of 2.5mA.

    The servo was being powered from the launchpad and the signal from PC4. I have tried to debug the luanchpad without the servo along with various other methods for example holding down the reset button while powering the device with no luck. Could it be possible that I was trying to draw too much current from the launchpad and may may have damaged the launchpad?
  • Hello Jonathan,

    I am suspecting the same. The USB port is 5V @ 500 mA. The 500 mA is peak current, with the average current being lower. I would advise using an external power source for the servo motor.
  • Until yesterday I have had it on a power supply but I just wanted to see if I could get away with powering it on the Launchpad to save space. Do you think there is any hope at all in saving the two launchpads that are frozen?
  • Hello Jonathan,

    If the Main MCU is still OK, then you can use a 3rd LaunchPad or an external Debug Probe to connect to the main MCU. More details in the following application note

    www.ti.com/.../spma075.pdf