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