Hello there,
I am slowly transitioning to Freescale MCUs and right now I am working on my first prototype with a DEMO9S08QG8 board (MC9S08QG8 MCU). Up until now I had no major problems but now I am having a problem I can't seem to solve.
I am creating a little menu system for 2x16 LCD and for that I am trying to create some non volatile structures in FLASH memory (constants that will be flashed along the application code).
struct parameter;
struct menu;
struct menu_item;
typedef struct parameter
{
int* storage;
char* title;
byte type;
int min_range;
int max_range;
char* options[3];
}parameter;
typedef struct menu_item
{
byte type;
struct menu* menu;
parameter* param;
}menu_item;
typedef struct menu
{
char* title;
byte current_item;
byte num_elements;
menu_item* items[10];
}menu;
Initialization of constants:
extern int opc1 @0xFF00;
extern int opc2 @0xFF02;
extern int opc3 @0xFF04;
const parameter option1 ={
&opc1,
"Option 1",
PARAMETER_TYPE_YESNO
};
const parameter option2 =
{
&opc2,
"Option 2",
PARAMETER_TYPE_RANGE,
10,
50
};
const parameter option3 =
{
&opc3,
"Opcion 3",
PARAMETER_TYPE_OPTIONS,
0,
0,
{"Yes","No","Maybe"}
};
const menu_item submenu1_1 =
{
MENU_ITEM_PARAMETER,
0,
&opcion1
};
const menu_item submenu1_2 =
{
MENU_ITEM_PARAMETER,
0,
&opcion2
};
const menu_item submenu1_3 =
{
MENU_ITEM_PARAMETER,
0,
&opcion3
};
const menu_item* submenu1[3] =
{
&submenu1_1,
&submenu1_2,
&submenu1_3
};
const menu menu_ppal;
const menu_item submenu2_1 =
{
MENU_ITEM_SUBMENU,
&menu_ppal
};
const menu_item* submenu2[3] ={
&submenu1_2,
&submenu1_3,
&submenu2_1
};
const menu_item* menu_ppal_elements[2] = {
&submenu1,
&submenu2,
};
const menu menu_ppal ={
"Main menu",
0,
2,
menu_ppal_elements,
};
Note: My first version used unions to optimize memory size but I can't initialize const structs with unions.
Note2: This code resides in a menu.c, with the declarations for other modules in the menu.h header file
Note3: This is just an example to show how I declare and initialize the structs.
The thing is when I run/debug the application and inspect the constants they all have rubbish (and always the same rubbish). I suspected flash protection and when I try to unlock it with the FLASH Programmer in CW10.1 I get a timeout (as a matter of fact, I can erase and check erase, but I cannot program using that tool. But I can debug and run normally in debug mode). Am I forgetting something? Is there a better way of allocating constant data (strings and the sort) in C code?
Thanks in advance for your help!