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.

Debug Problem - Tiva C Launchpad

Other Parts Discussed in Thread: LMFLASHPROGRAMMER

Hello,

I am trying to debug my code but every time I launch the debuggging session in CCS it doesn't pause at the start of the main function but instead when I hit pause it shows that I am already in the FaultISR.  I can see the global variables that I set before the main program but not any of the variables that I set inside the main function.

I have attached my code. Please help me figure out how to get the debugger to run until the start of the main function.

Regards,

Curtis

/*
 * GTBE_pllTest.c
 */
//Define Inputs\

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_ssi.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"

// Stellarisware
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"
#include "driverlib/debug.h"
#include "driverlib/flash.h"

// CMSIS
#include <math.h>
#include "arm_math.h"
#include "math_helper.h"

// PLL Loop Parameters
#define  PHASE_OFFSET 0.0
#define  F_C		  10000 // Center Frequency of the NCO

// Test Input data
//#define NUM_CYCLES 1000
#define F_S 		100000
#define A 			100000
#define F_IN 		10100
#define K_GAIN 		-0.01
#define NUM_SAMPLES 2000
//FIR Filter Data
#define NUM_TAPS    121
#define BLOCK_SIZE	1

#ifndef M_PI
#define M_PI                    3.14159265358979323846
#endif

/*******************
 * Flash Functions *
 *******************/

/**
 * Initializes the Flash
 *  Protects the part of the flash memory from address codeStart through
 *   codeStart + codeReserveLength by setting to only execute (FlashExecuteOnly)
 *  Sets up the flash interrupt in case the program attempts to access the
 *   protected flash portions.  Make sure the ISR is added to the NVIC table
 *
 *  \param codeStart - start location of flash memory that is to be reserved
 *  	it must land on a 2KB boundry
 *  \param codeReserveLength - length of code to prtotect in flash memory
 *  	it must land on a 2KB boundry
 **/
void initFlash(uint32_t codeStart, uint32_t codeReserveLength) {
	int32_t status;
	uint32_t modCheck;
	uint32_t block;
	// Check codeStart and codeReserveLength to ensure the protected memory
	//  block starts and ends on a 2KB boundry
	modCheck = codeStart - codeStart/0x800;
	modCheck = modCheck + codeReserveLength/0x800;
	ASSERT(modCheck == 0);
	// Setup code protection
	for(block = 0; block < (codeReserveLength/0x800); block++) {
		status = FlashProtectSet(0x800 * block, FlashExecuteOnly);
		ASSERT(status == 0)
	}
	//setup Flash Interrupt to handle any improper write attempts to flash
	FlashIntEnable(FLASH_INT_PROGRAM);
}
/**
 * Interrupt handler (ISR) that executes when an improper write to flash is attempted
 **/
void FLASH_badWriteISR(void) {
	while(1) {
		// Do nothing - save state for examination
	}
}

/******************
 * FPU Functions *
 ******************/

/**
 * Initializes the FPU
 **/
void setupFPU(void) {
	// Lazy Stacking increases interrupt latency and stack usage
	//  (only need if doing floating pt. in interrupts)
	//FPULazyStackingEnable();
	ROM_FPUEnable();
}

// Input
float32_t g_sig_I[NUM_SAMPLES];

// PFD
float32_t g_msig_I[1];
uint32_t  gp_msig_I = 0x2800; // Address to save data to in flash
float32_t g_msig_Q[1];
uint32_t  gp_msig_Q = 0x3600; // Address to save data to in flash
// FIR Filter
uint32_t blockSize = BLOCK_SIZE;
const float32_t firCoeffs32[NUM_TAPS] = {
0.0006830547454, 0.0007069055674, 0.0007422978673, 0.000790029838, 0.0008508535077, 0.0009254696142, 0.001014522694,  0.001118596418, 0.001238209203,  0.001373810118,  0.001525775132,
0.001694403697,  0.001879915716,  0.002082448903,  0.002302056559, 0.002538705765,  0.002792276037,  0.003062558419,  0.003349255047, 0.00365197918,   0.003970255708,  0.00430352213,
0.00465113001,   0.005012346894,  0.0053863587,    0.005772272552, 0.006169120058,  0.006575861016,  0.006991387523,  0.00741452848,  0.007844054463,  0.008278682938,  0.008717083793,
0.009157885164,  0.00959967952,   0.01004102998,   0.01048047682,  0.01091654416,   0.01134774676,   0.01177259695,   0.01218961154,  0.01259731883,   0.01299426559,   0.01337902392,
0.01375019813,   0.01410643139,   0.01444641227,   0.0147688811,   0.01507263604,   0.01535653896,   0.01561952094,   0.01586058754,  0.01607882362,   0.01627339785,   0.01644356679,
0.01658867855,   0.01670817598,   0.01680159946,   0.0168685891,   0.01690888657,   0.01692233637,   0.01690888657,   0.0168685891,   0.01680159946,   0.01670817598,   0.01658867855,
0.01644356679,   0.01627339785,   0.01607882362,   0.01586058754,  0.01561952094,   0.01535653896,   0.01507263604,   0.0147688811,   0.01444641227,   0.01410643139,   0.01375019813,
0.01337902392,   0.01299426559,   0.01259731883,   0.01218961154,  0.01177259695,   0.01134774676,   0.01091654416,   0.01048047682,  0.01004102998,   0.00959967952,   0.009157885164,
0.008717083793,  0.008278682938,  0.007844054463,  0.00741452848,  0.006991387523,  0.006575861016,  0.006169120058,  0.005772272552, 0.0053863587,    0.005012346894,  0.00465113001,
0.00430352213,   0.003970255708,  0.00365197918,   0.003349255047, 0.003062558419,  0.002792276037,  0.002538705765,  0.002302056559, 0.002082448903,  0.001879915716,  0.001694403697,
0.001525775132,  0.001373810118,  0.001238209203,  0.001118596418, 0.001014522694,  0.0009254696142, 0.0008508535077, 0.000790029838, 0.0007422978673, 0.0007069055674, 0.0006830547454
};
static float32_t firStateF32_I[BLOCK_SIZE + NUM_TAPS - 1]; //Declare State buffer of size (numTaps + blockSize - 1)
static float32_t firStateF32_Q[BLOCK_SIZE + NUM_TAPS - 1];
static float32_t I_err[1]; //output of I FIR filter
static float32_t Q_err[1]; //output of Q FIR filter

// Loop Gain and phase offsets
float32_t g_err[1];
uint32_t  gp_err = 0x4400; // Address to save data to in flash
float32_t g_errAdj;
float32_t g_K = K_GAIN;
float32_t g_phaseOffset = PHASE_OFFSET;

// NCO
float32_t g_currPhase[NUM_SAMPLES];
uint32_t  gp_currPhase;

float32_t g_nco_I[1];
float32_t g_nco_Q[1];
uint32_t gp_nco_I;
uint32_t gp_nco_Q;
/********
 * Main *
 ********/
int main(void) {
	int i;


	// FIR Filter Variables
	arm_fir_instance_f32 S_I;
	arm_fir_instance_f32 S_Q;
	float32_t  *inputF32_I, *outputF32_I;
	float32_t  *inputF32_Q, *outputF32_Q;
	//Initialize input and output buffer pointers
	inputF32_I  = &g_msig_I[0];
	outputF32_I = &I_err[0];
	inputF32_Q  = &g_msig_Q[0];
	outputF32_Q = &Q_err[0];

	// NCO
	float32_t phaseInc;

	//
	// System Initialization
	//
	// Set system clock to 80 MHz (400MHz main PLL (divided by 5 - uses DIV400 bit)  [16MHz external xtal drives PLL]
	ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
	setupFPU();
	initFlash(0x0, 0x2800);

	// Initialize FIR Filter
	/* Call FIR init function to initialize the instance structure. */
	arm_fir_init_f32(&S_I, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32_I[0], blockSize);
	arm_fir_init_f32(&S_Q, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32_Q[0], blockSize);

	//
	// Generate Test Input cosine
	//
	for(i=0; i<NUM_SAMPLES; i++) {
		g_sig_I[i] = arm_cos_f32((2 * M_PI * F_IN / F_S) *i);
	}
	


	phaseInc = (2 * M_PI * F_C)/F_S;

	g_nco_I[0] = 1;
	g_nco_Q[0] = 0;

	FlashProgram(g_nco_I,gp_nco_I,4);
	gp_nco_I += 4;
	FlashProgram(g_nco_Q,gp_nco_Q,4);
	gp_nco_Q += 4;

	int n;
	// Main "Time" sim loop
	for(n = 0; n < NUM_SAMPLES; n++) {
		//
		// Phase Detection
		//

		// PD Multipliers
		g_msig_I[0] = g_sig_I[n] * g_nco_I[0];
		g_msig_Q[0] = g_sig_I[n] * g_nco_Q[0];
		FlashProgram(g_msig_I,gp_msig_I,4);
		gp_msig_I += 4;
		FlashProgram(g_msig_Q,gp_msig_Q,4);
		gp_msig_Q += 4;

		// PD FIR Filter
		arm_fir_f32(&S_I, inputF32_I, outputF32_I, blockSize);
		arm_fir_f32(&S_Q, inputF32_Q, outputF32_Q, blockSize);

		g_err[0] = atan2(Q_err[0],I_err[0]); // Take the 4 quadrant arctan
		FlashProgram(g_err,gp_err,4);
		gp_err += 4;
		g_errAdj = g_K * (g_err[0] + g_phaseOffset);

		if(n>0) g_currPhase[n] = g_currPhase[n] + phaseInc + g_errAdj;
		else    g_currPhase[0] = 0;

		g_nco_I[0] = arm_cos_f32(g_currPhase[n]);
		g_nco_Q[0] = arm_sin_f32(g_currPhase[n]);
		FlashProgram(g_nco_I, gp_nco_I, 4);
		FlashProgram(g_nco_Q, gp_nco_Q, 4);
	}

	while(1) {} // End of program execution
}

  • Hello Curtis,

    There is an option in CCS "run to main". Is that set? A snapshot of the configuration would be useful

    When the Fault occurs, can you read the following two address and send the data. It gives the Fault Type and Fault Address

    0xE000ED28

    0xE000ED38

    There is already a App Note on Faults. You may want to refer to the same.

    http://www.ti.com/lit/an/spma043/spma043.pdf

    Regards

    Amit

  • Hey Amit,

    Thanks for the prompt response, I appreciate it!

    Here are the memory addresses you requested:

    0xE000ED28 is 0x00008200

    0xE000ED38 ia 0x00001478

    Also, the debugger was set to stop at main as shown in the screenshot below.

    Here are the rest of the tabs:

    I will take a look at the app note.

    Regards,

    Curtis

  • Hello Curtis,

    Thanks for the data. I revisted the code and it seems to be that you are writing to Flash and the address is not defined to a value. At the same time a protect mechanism is there, which could cause the Fault.

    Regards

    Amit

  • What write to flash are you talking about?

    Also, I'm not sure how that is the problem when it isn't able to reach the start of the main function even.

    I was just looking at my flash code also but haven't found the problem yet.

    The debugger is currently giving me the error below:


    Trouble Reading Memory block at 0xXXXX on page 0 of length oxXXX errors when I pause and try to step it.

    - Curtis

  • Now every time I run the program it gets to instruction 0xCB2 and then stops. (more like when I pause it and try to run it past that point it never changes.  I even power cycled the board and tried a different project and it does the same thing.

    -Curtis

  • Hello Curtis,

    The original code post you have sent has FlashProgram which will write to the Flash. The address parameter is not initialized.

    If you do a erase of the entire flash using LMFlashProgrammer, power cycle the board and then run the CCS program does it behave the same way?

    Regards

    Amit

  • Hey Amit,

    I tried erasing the entire flash and the LM Flash Programmer status read "Erase Complete" but when I try the debugger I am getting the same issue.  Also, If I try to use the "Blank check" utility below the flash erase utility I get the following error  message:

    "**ERROR**: The blank check failed block read at: 0x00000000.

    While this is the start of the block that I had tried to restrict to execute only only, my understanding was that unless I use the permanent protecton function that the protection shouldn't be active after a reset.

    Regards,

    Curtis

  • Hello Curtis,

    Your observation is correct. But it seems that something else did happen into which I need to look into. In the meantime you can run the JTAG Unlock Sequence to recover the device.

    Regards

    Amit

  • Thanks Amit,

    The JTAG Unlock Sequence fixed the programming the problem.  I have fixed the original uninitialized flash address bug and now I'll try the original code again.

    -Curtis

  • Hey Amit,

    So I went ahead and fixed the flash addressing bug and redid the flash memory mapping that I had come up with to allocate and protect the data while reserving room for data I needed to store.  Now the debugger is running well.

    I appreciate the help!

    Regards,
    Curtis