Crash on global variable assignment in banked and direct RAM.

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Crash on global variable assignment in banked and direct RAM.

跳至解决方案
1,361 次查看
sbelanger
Contributor I
Hi,
 
I'm currently using CodeWarrior 4.7 on a HC12XDP512 microcontroller. I've been debugging a series of unexpected crashes in our user interface and located the cause of the problem. However, I'm a bit confused why this is happening.
 
Here it goes :
 
unsigned16 gRefreshDelay :
global variable in direct RAM to control the refresh rate of the UI. Unsigned word.

S_INFO_MENU_CURRENT gInfoMenuCurrent :

global structure containing the current menu and associated functions. This structure contains a pointer to a banked structure (structPtr). See the following :

typedef struct
{
s16 choix_u08;      
/*!< Menu current choice. Shall be signed for cds getString() */
u08 refresh_u08;      
/*!< Do we need a refresh? TRUE/FALSE */
u08 curseurPos_u08;
/*!< Menu current possition. */
HID_LANGUE_TYPEDEF langue_enum;
/*!< Current language. */
s08 menuFct_s08;
/*!< Menu type. */
void BANK_PTR structPtr; /*!< Menu Structure. */
u08 DontWantLangueChoice;
/*!< On specific menu, we don't want FN1 as langue button. */
}S_INFO_MENU_CURRENT;


The following code will generate a crash :

HID_CONFIG_MENU_INFO BANK_PTR menuPtr = (HID_CONFIG_MENU_INFO BANK_PTR)gInfoMenuCurrent.structPtr;

// Banked variables first

gInfoMenuCurrent.curseurPos_u08 = menuPtr->cursorPosPrec_u08;
gInfoMenuCurrent.
choix_u08 = menuPtr->choixPrec_u08;
gInfoMenuCurrent.
structPtr = menuPtr->menuPrecStruct;
gInfoMenuCurrent.
menuFct_s08 = menuPtr->menuPrecFct_s08;
gInfoMenuCurrent.
refresh_u08 = TRUE;

// Direct variable after

gRefreshDelay = HID_KEY_HOLD_DELAY; // WARNING : code will crash HERE! Tested with debugger

return;

However, the code won't crash if I do the following :
HID_CONFIG_MENU_INFO BANK_PTR menuPtr = (HID_CONFIG_MENU_INFO BANK_PTR)gInfoMenuCurrent.structPtr;

// Direct variable first
gRefreshDelay = HID_KEY_HOLD_DELAY;           // Code won't crash. Tested with debugger.
// Banked data afterward
gInfoMenuCurrent.curseurPos_u08 = menuPtr->cursorPosPrec_u08;
gInfoMenuCurrent.
choix_u08 = menuPtr->choixPrec_u08;
gInfoMenuCurrent.
structPtr = menuPtr->menuPrecStruct;
gInfoMenuCurrent.
menuFct_s08 = menuPtr->menuPrecFct_s08;
gInfoMenuCurrent.
refresh_u08 = TRUE;
return;
 
In short, if I assign stuff in a global banked structure and then assign a direct global variable, my code will crash. If I do the reverse, direct and then banked, everything is fine. This shouldn't happen. Please note that this code don't generate any error or warning when compiled.
 
Thanks
 
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
572 次查看
CrasyCat
Specialist III
Hello
 
This may be related to the application memory map or anything else.
 
I would recommend you to submit a service request for that.

Click here to submit a service request.

Make sure to attach a reproducible project and installed product information to the service request.
To generate the required information:
- Start CodeWarrior
- Open the project
- Select "Help" -> "Pack and Go" and follow instructions on the screen.

Attach the generated .zip file to the SR.
 
CrasyCat

在原帖中查看解决方案

0 项奖励
回复
1 回复
573 次查看
CrasyCat
Specialist III
Hello
 
This may be related to the application memory map or anything else.
 
I would recommend you to submit a service request for that.

Click here to submit a service request.

Make sure to attach a reproducible project and installed product information to the service request.
To generate the required information:
- Start CodeWarrior
- Open the project
- Select "Help" -> "Pack and Go" and follow instructions on the screen.

Attach the generated .zip file to the SR.
 
CrasyCat
0 项奖励
回复