Tool/software: TI C/C++ Compiler
There is a bug in the TI compiler in at least versions C2000 6.2.11 and 18.9.0.STS. If a function has constant local data which is initialised with the address of an external variable or function, and the function doesn't call another external function, and the optimisation level is set to 3 or 4 then constant local data is not initialised. See example below. I have listed the source code which has a commented out call to function CONSOLE_Init. If this is uncommented then the constant local data is initialised correctly. See generated machine code. Note that the original intention of the code was to copy a locally defined interrupt vector table to the TMS320F28335's PIE vector memory at 0xD00, which is why the copying code has a loop that copies 128 uint32_t's. I know that code isn't technically correct as the source structure only has one uint32_t (it has been reduced to one entry to simplify the code).
Example Source Code
extern uint32_t myvar1;
extern void CONSOLE_Init();
struct MyStruct_t {
uint32_t* pValue;
};
void MyFunc(void)
{
// Structure containing the vector table which we want to use.
const struct MyStruct_t MyData =
{
&myvar1,
};
uint16_t Index;
const uint32_t* p_Source = (const uint32_t*)&MyData;
uint32_t* p_Dest = (uint32_t*)0xD00; //&PieVectTable;
EALLOW;
for (Index = 0u; Index < 128u; Index++)
{
*p_Dest = *p_Source;
p_Dest++;
p_Source++;
}
EDIS;
//CONSOLE_Init();
}
Generated Machine Instructions (when CONSOLE_Init() is not called)
MyFunc():
301afb: FE02 ADDB SP, #2
301afc: 7622 EALLOW
607 const uint32_t* p_Source = (const uint32_t*)&MyData;
301afd: 5CAD MOVZ AR4, @SP
301afe: DC82 SUBB XAR4, #2
301aff: 5CA4 MOVZ AR4, @AR4
301b00: BE7F MOVB XAR6, #0x7f
609 uint32_t* p_Dest = (uint32_t*)0xD00; //&PieVectTable;
301b01: 8F400D00 MOVL XAR5, #0x000d00
615 *p_Dest = *p_Source;
C$L4:
301b03: 0684 MOVL ACC, *XAR4++
301b04: 1E85 MOVL *XAR5++, ACC
613 for (Index = 0u; Index < 128u; Index++)
301b05: 000EFFFE BANZ 65534,AR6--
301b07: 761A EDIS
301b08: FE82 SUBB SP, #2
301b09: FF69 SPM #0
301b0a: 0006 LRETR
Generated Machine Instructions (when CONSOLE_Init() is called):
MyFunc():
3025d5: FE02 ADDB SP, #2
600 const struct MyStruct_t MyData =
3025d6: 8F00B1AE MOVL XAR4, #0x00b1ae
3025d8: A842 MOVL *-SP[2], XAR4
3025d9: 7622 EALLOW
607 const uint32_t* p_Source = (const uint32_t*)&MyData;
3025da: 5CAD MOVZ AR4, @SP
3025db: DC82 SUBB XAR4, #2
3025dc: 5CA4 MOVZ AR4, @AR4
3025dd: BE7F MOVB XAR6, #0x7f
609 uint32_t* p_Dest = (uint32_t*)0xD00; //&PieVectTable;
3025de: 8F400D00 MOVL XAR5, #0x000d00
615 *p_Dest = *p_Source;
C$L4:
3025e0: 0684 MOVL ACC, *XAR4++
3025e1: 1E85 MOVL *XAR5++, ACC
613 for (Index = 0u; Index < 128u; Index++)
3025e2: 000EFFFE BANZ 65534,AR6--
3025e4: 761A EDIS
3025e5: FF69 SPM #0
622 CONSOLE_Init();
3025e6: 7670177A LCR CONSOLE_Init
3025e8: FE82 SUBB SP, #2
3025e9: 0006 LRETR