I am using 16bit microcontroller which uses gcc4.5 compiler, 32kbyte flash/1kbyte ram. compiling is fine without error, memory is reaching to it's limit but it has some vacancy on both flash/ram and works just fine
However, when i define static array without initialization it causes system to die. I cannot use debugger to watch what's going on inside my system.
I didn't even use the array other than define it. so I assume compiler should skip below code but it kept making a problem.
typedef enum
{
PTC_VOLT_ERROR = 0,
PTC_LINE_ERROR,
PTC_ERROR,
PTC_PCB1TEMP_ERROR,
PTC_PCB2TEMP_ERROR,
PTC_COMM_ERROR,
PTC_SELF_DIAG_ERROR,
PTC_PCB1TEMPSSR_ERROR,
PTC_PCB2TEMPSSR_ERROR,
NUM_OF_PTC_ERROR_TYPE
}PtcErrorTypeInfo_t;
(...)
static INT8U preErrorInfo[NUM_OF_PTC_ERROR_TYPE]; // This cause system to die
//static INT8U preErrorInfo[NUM_OF_PTC_ERROR_TYPE]={0,}; // This is ok
Then I tried with non-static global arry and found it was working well.
INT8U preErrorInfo[NUM_OF_PTC_ERROR_TYPE]; // This is ok
static INT8U preErrorInfo[2]; // This is also ok
static INT8U preErrorInfo[9]; // This is not working
static INT8U preErrorInfo[2]; // This is working
I want to know what could make my system down?
→→→ It turned out that it had something to do with overflow and trap error.
first>> when I compile without static, in the map file
.data.g_PtcProtectionState
0x0000007e 0x2 obj/EcuProtectCTR.o
0x0000007e _g_PtcProtectionState
.data.preErrorInfo
0x00000080 0x9 obj/EcuProtectCTR.o
.data.u1_ErrorDeterTmr
0x00000089 0x1 obj/EcuProtectCTR.o
.data.pendingCalibOn
0x0000008a 0x6 obj/EcuSsrInputCTR.o
0x0000008a _pendingCalibOn
(...)
.bss.g_u4_ErrorCntrInfo
0x00000144 0x4 obj/EcuProtectCTR.o
**.bss.g_u1_TmrInt
0x00000148 0x1 obj/SchM.o
0x00000148 _g_u1_TmrInt**
.bss.u1_ElapsedTime
0x00000149 0x1 obj/SchM.o
it makes preErrorInfo[9] array seats in the data area.
second>> if i compile with 'static'
.bss.g_u4_ErrorCntrInfo
0x0000013c 0x4 obj/EcuProtectCTR.o
.bss.preErrorInfo
0x00000140 0x9 obj/EcuProtectCTR.o
.bss.g_u1_TmrInt
0x00000149 0x1 obj/SchM.o
0x00000149 _g_u1_TmrInt
preErrorInfo arry nicely seats on bss area. However, there is a variable 'g_u1_TmrInt' which keeps causing a problem. this timer-interrupt geard variable keeps making an overflow.
since 'static preErrorInfo array' will seat right above 'g_u1_TmrInt' somehow it could be messed up with 'static preErrorInfo array' when overflowing.
But I wonder why it didn't cause a problem when it comes to a case 'first>>' which has a 'g_u4_ErrorCntrInfo' 4byte array seated right above 'g_u1_TmrInt' and it would surely make the same overflow error.
※ when I change 'g_u1_TmrInt' type to 16bit(no-overflow and no error), it would look like this and work like charm.
.bss.preErrorInfo
0x00000140 0x9 obj/EcuProtectCTR.o
*fill* 0x00000149 0x1
.bss.g_u1_TmrInt
0x0000014a 0x2 obj/SchM.o
0x0000014a _g_u1_TmrInt
.bss.u1_ElapsedTime
0x0000014c 0x2 obj/SchM.o
.bss.SchConfig
User contributions licensed under CC BY-SA 3.0