Crash on global variable assignment in banked and direct RAM.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Crash on global variable assignment in banked and direct RAM.

Jump to solution
1,312 Views
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
 
Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
523 Views
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

View solution in original post

0 Kudos
Reply
1 Reply
524 Views
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 Kudos
Reply