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.

CCS/EK-TM4C1294XL: Bus fault when assign a value to a structure element(s).

Part Number: EK-TM4C1294XL


Tool/software: Code Composer Studio

Hi,

I have created and instantiated the below structure in separate header file in my CCS application but when I try to assign a value to any of the structure elements I get bus fault, so what is the issue here.

HEADER FILE Contents:

struct CPUParameter {
unsigned char name[26];
unsigned char PN[27];
uint32_t BaudRate;
uint8_t DataBits;
uint8_t StopBits;
uint8_t Parity;
uint8_t ID;
struct IOModule *ioModule[MAX_NUM_MODULES];
};

struct CPUParameter *CPUPara;

C FILE contents

void CPU_RESETPRMTRS(){
CPUPara->CPUSWFALUT = 0;
unsigned char tempPN[27] = "1985SE-F24-SR01-F512-C03-24";
uint16_t i;
for(i = 0; i < sizeof(tempPN); i++){
CPUPara->PN[i] = tempPN[i];
}

for(i = 0; i < sizeof(CPUPara->name); i++){
// clear the old name
CPUPara->name[i] = ' ';
}

unsigned char tempName[26] = "controller";
for(i = 0; i < sizeof(tempName); i++){
CPUPara->name[i] = tempName[i];
}

}

  • Hani Ahmed said:
    I have created and instantiated the below structure in separate header file in my CCS application but when I try to assign a value to any of the structure elements I get bus fault, so what is the issue here.

    Has the CPUPara pointer been initialised to point at a valid address in RAM?

    If CPUPara hasn't been initialised it will be NULL, which will cause a bus fault when attempt to a assign a value to any of the structure elements. In a TM4C device address zero (NULL) is on-chip flash, and attempts to write addresses in the flash range result in a bus fault.

  • Hi

    I have an initialization function which I used the malloc to init the CPUPara as below but I got the same bus fault error.

    CPUPara = (CPUParameter *) mem_malloc(sizeof(struct CPUParameter));

    regards

    Hani Ahmed

  • Hani Ahmed said:
    I have an initialization function which I used the malloc to init the CPUPara as below but I got the same bus fault error.

    Is malloc returning a NULL pointer indicating that was insufficient heap space for the allocation?

    When creating a project in CCS using the TI ARM compiler for a TM4C device the default is that the "Heap size for C/C++ dynamic memory allocation (--heap_size,-heap)" is set to zero:

    To allow malloc to work the heap size in project properties must be set to a non-zero value which is sufficient for the allocations made by the project.

    If you are using the GNU ARM compiler, the heap size is set in a different way.

  • Hi

    I changed the heap size but now i received this error which prevents me from testing the above solution and i can't figure it out

    #102 "CPUParameter" has already been declared in the current scope

    Hani

  • Hani Ahmed said:
    #102 "CPUParameter" has already been declared in the current scope

    That error means the compiler has seen two declarations of the CPUParameter structure.

    Can you post your complete program?

  • While the function called in this line of code ...

    Hani Ahmed said:
    CPUPara = (CPUParameter *) mem_malloc(sizeof(struct CPUParameter));

    ... is similar to malloc, it is not the same.  I do not recognize it, and thus I cannot assume what it does.  If it calls malloc (or calloc, or something similar) from the compiler RTS library, then the post from Chester Gillon about checking the setting of the build option --heap_size is correct.  If this is a call to a different implementation for dynamically allocating memory, then changing --heap_size does not help.

    Thanks and regards,

    -George

  • Regarding this error issued by the compiler ...

    Hani Ahmed said:
    #102 "CPUParameter" has already been declared in the current scope

    Here is another debug technique to consider.  Add the build option --gen_preprocessor_listing.  This causes the compiler create a preprocessor listing file.  It has the same name as the source file, with the extension changed to .rl.  To understand the format of this file, search on --gen_preprocessor_listing in the ARM compiler manual.  In this particular case, search for CPUParameter to find the two places where that structure is declared.  The root cause of the problem often becomes clear.

    Thanks and regards,

    -George

  • Hello George

    Thanks for your response and I agree with you that changing the heap size will not work, so i have solved the problem by initiated global variable with init values and assigned the pointer to my local variable.

    You may see it as dump solution but it solved my problem :)