This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problems with struct&graphic library.

Hello,

I'm trying to display a menu on my device, with str710 mcu. To do that, I create use structs to hold the variables and display them later. My structs look like this:

typedef const struct mMenu_s
  {
    int type;
        char text[3][20];
        struct command
          {
        int command;
                int argument;
          } commands;
        struct specialline
          {
        int een;
                int twee;
                int drie;
          }     speciallines;
  } menutype;

typedef struct sMenuTemp {
  menutype *mCurmenu[20];
  int iCurmenu;
  int iCurmenupos;
  int iOldmenu;
  int iOldmenupos;

  int menuactive;
} cmdMenu;
extern cmdMenu sMenu;

And to place data in it I use:

cmdMenu sMenu;
        menutype Backlightmenu[] =
        {
          { 1, {"Rood", "Red", "Rot"}, {SET_BACKLIGHT,RED}, {NULL,NULL,NULL} },
          { 2, {"Groen", "Green", "Grun"}, {SET_BACKLIGHT,GREEN}, {NULL,NULL,NULL} },
          { 3, {"Wit", "White", "Weiss"}, {SET_BACKLIGHT,WHITE}, {NULL,NULL,NULL} },
          { NULL }
        };
sMenu->mCurmenu[BACKLIGHTMENU] = Backlightmenu;

With this method I can let (other) programmers create/delete/edit a menu very easy. So far so good.. All the text, commands, arguments and the rest of variables are stored in the memory OK (checked the memory watch, all OK!). But then.. I wan't to display the texts. Selecting the menu, the menuline, the language and the text is no problem. But, with the displaying, the last line of my struct is getting destroyed.

I've debugged my program, and it seems that the LCD-library caused the problem. It does an integer division, and the assembly calls "__aeabi_idivmod", which is an divide-function. On the first instruction, which is: PUSH {R4-R6,LR}, the data of my struct get destroyed, and it very, very weird values on the place of the struct..

And, the stupid thing.. When I remove the graphic-function, it's all normal. And, it doesn't matter on what memory-location my struct is placed, it happens every time.. It looks like the divide haunts my struct =S.

I'm working with the MDK-Arm 3.70 toolchain, in uVision3. Does anybody have an idea why this happens? Or, even better, the solution? I've tried a lot of other things, but it would be so d*mn easy to build and display my menu like that...

Thank you so very much.

Jay.

Parents
  • First are your menu's supposed to be unmodifiable? If so they should be written to be in ROM space only. Second if the division function is modifying your data, then it is likely pointing to your data and your data pointers are getting messed up.

    You should always know WHAT you are pointing at. That is what you should check in the debugger. Find out what points to your structure (IE register) and find out what the parameters to your division function are (registers).

    You may need to examine your LCD drivers or if someone else wrote them, you should contact them and ask what the LCD drivers are expecting and how to avoid conflict.

    Since I normally write my LCD drivers I talk to myself (it's quite humorous but short). Erstwhile be sure the data you are using needs to be modified and if something is modifying it, THAT is a VERY serious bug. Always look at your pointers in the debugging MAKE notes also. If you don't have documentation make it, this will save you time debugging. IE what function is causing corruption where it's located what it's doing what you expect it to do etc.

    Stephen

Reply
  • First are your menu's supposed to be unmodifiable? If so they should be written to be in ROM space only. Second if the division function is modifying your data, then it is likely pointing to your data and your data pointers are getting messed up.

    You should always know WHAT you are pointing at. That is what you should check in the debugger. Find out what points to your structure (IE register) and find out what the parameters to your division function are (registers).

    You may need to examine your LCD drivers or if someone else wrote them, you should contact them and ask what the LCD drivers are expecting and how to avoid conflict.

    Since I normally write my LCD drivers I talk to myself (it's quite humorous but short). Erstwhile be sure the data you are using needs to be modified and if something is modifying it, THAT is a VERY serious bug. Always look at your pointers in the debugging MAKE notes also. If you don't have documentation make it, this will save you time debugging. IE what function is causing corruption where it's located what it's doing what you expect it to do etc.

    Stephen

Children