__flash causing "unrecognizable insn" error when passing struct to function

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm working a menu system and am having issues passing structures by reference using __flash.  I'm using the Atmel AVR8 3.4.5 toolchain (GCC 4.8.1) in Atmel Studio 6.2 SP1, and testing on an ATxmega128A1.  

 

In Menu.h, I have the following to generate my menu structures:

/* Menu structures and Macros */
typedef struct {
    const __flash char *choice;         /* Text to be displayed for this menu item choice */
    const char key;                     /* Keystroke this menu choice responds to */
    const __flash struct _menu *menu;   /* Menu to call for this choice */
    void (*callback)(void);             /* Function callback for this menu item. Executed before menu call */
} menu_item_t;

typedef struct _menu {
    const __flash char *banner;         /* Banner to be displayed at top of the menu */
    const __flash char *prompt;         /* Menu prompt text */
    void (*callback)(void);             /* Function callback - executed between banner and items */
    const __flash menu_item_t *item[];  /* Array of ordered menu items to be displayed */
} menu_t;

#define MENU_ITEM(name, choice, key, menu, callback) \
    static const __flash char name##_choice[] = choice; \
    static const __flash menu_item_t name = { name##_choice, key, menu, callback }

#define MENU(name, banner, prompt, callback, ...) \
    static const __flash char name##_banner[] = banner; \
    static const __flash char name##_prompt[] = prompt; \
    static const __flash menu_t name = { name##_banner, name##_prompt, callback, {__VA_ARGS__} }
    

In main.c, the relevant code is as follows:

/* Menu Items */
MENU_ITEM(MI_SERIAL_CONFIG, "[S]erial Configuration", 's', NULL, NULL);
MENU_ITEM(MI_RADIO_CONFIG, "[R]adio Configuration", 'r', NULL, NULL);
MENU_ITEM(MI_PIPE_CONFIG, "[P]ipe Routing", 'p', NULL, NULL);

void m_main_callback() {
    printf_P(PSTR("** Main Menu Callback **\n"));
}

MENU(M_MAIN, "-= Main Menu =-", ">", m_main_callback,
        &MI_SERIAL_CONFIG,
        &MI_RADIO_CONFIG,
        &MI_PIPE_CONFIG,
        NULL
    );

void test(const __flash menu_t *menu) {
    printf_P(PSTR("T1: \n%S\n"), M_MAIN.banner);
    printf_P(PSTR("T2: \n%S\n"), menu->banner);
}

/* Main Menu Loop -- called from main */
void menuMain() {
    test(&M_MAIN);

    while(1) {

    }
}

As is, I receive the following errors:

unrecognizable insn:    
in extract_insn, at recog.c:2150

If I change the declaration of test() to "void test(const menu_t *menu)", it compiles fine with T1 of test() printing the expected text and T2 printing garbage of course.  Any tips on what I'm doing wrong?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It looks like this:

 

https://gcc.gnu.org/bugzilla/sho...

 

Fixed at 4.8.2 it says.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thought it was me, thanks!  I changed test() to use pgm_read_word and that worked:

void test(const menu_t *menu) {
    printf_P(PSTR("T1: \n%S\n"), M_MAIN.banner);
    printf_P(PSTR("T2: \n%S\n"), pgm_read_word(&menu->banner));
}

Are there any versions of 4.8.2 for AVR compiled or is this a "wait for Atmel" thing? Thanks again for the help!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thought it was me, thanks!

Then one could say it only happened sporadic-ally, right?  <groan>

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are there any versions of 4.8.2 for AVR compiled or is this a "wait for Atmel" thing? Thanks again for the help!

4.9.2, courtesy of SprinterSB

http://sourceforge.net/projects/...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

Thought it was me, thanks!

Then one could say it only happened sporadic-ally, right?  <groan>

cool

 

wek3 wrote:

Are there any versions of 4.8.2 for AVR compiled or is this a "wait for Atmel" thing? Thanks again for the help!

4.9.2, courtesy of SprinterSB

http://sourceforge.net/projects/mobilechessboar/files/avr-gcc%20snapshots%20%28Win32%29/

 

That worked, thanks!  One thing I noticed using that toolchain however, is that Atmel Studio no longer tells me program / data usage after compilation.  Any tips on getting it to work? I get the following in my output:

	Task "RunOutputFileVerifyTask"
				Program Memory Usage 	:	0 bytes   0.0 % Full
				Data Memory Usage 	:	0 bytes   0.0 % Full
	Done executing task "RunOutputFileVerifyTask".

 

Everything is progressing much cleaner now not having to use all the pgm_read stuff.

void menu_call(const __flash menu_t *menu) {
    char buff[2];
	
    printf_P(PSTR("\f%S\n\n"), menu->banner);
    if (menu->callback)
        menu->callback();

    int i = 0;
    while (menu->item[i])
        printf_P(PSTR("%S\n"), menu->item[i++]->choice);

    bool done = false;
    while(!done) {
        printf_P(PSTR("%S "), menu->prompt);
        if (menu_getcmd(buff, sizeof(buff))) {
            printf("buff: %s\n", buff);
        }
    }
}
-= Main Menu =-

** Main Menu Callback **
[S]erial Configuration
[R]adio Configuration
[P]ipe Routing
> p
buff: p

  Now time for me to go code some actual menu logic.  Thanks again for the help everyone.

Last Edited: Wed. Nov 5, 2014 - 05:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok... Everything was working great with the 4.9.2 toolchain until I migrated to my target device, which is a Xmega32E5.  Only then did I find out that the 4.9.2 toolchain referenced didn't support the E5 chips :( I see three options... Add E5 support to the newer toolchain, attempt to fix the issue in Atmel's toolchain and re-compile, migrate everything to the old pgm_read stuff which would be a pain now and I've progressed much further on it.  What's my best bet? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sporadic wrote:
Only then did I find out that the 4.9.2 toolchain referenced didn't support the E5 chips :( I see three options...

GCC Wiki

avr-gcc

Supporting "unsupported" Devices

http://gcc.gnu.org/wiki/avr-gcc#Supporting_.22unsupported.22_Devices

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

It looks like this:

 

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57844

 

Fixed at 4.8.2 it says.

 

I just checked the GCC 4.8.1 source in the Atmel 3.4.5 toolchain and that fix has already been applied, so guess it's something else has been fixed between their 4.8.1 and 4.9.2.  I'll dig around and see if I can find the fix, thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman wrote:

 

sporadic wrote:

Only then did I find out that the 4.9.2 toolchain referenced didn't support the E5 chips :( I see three options...

 

GCC Wiki

avr-gcc

Supporting "unsupported" Devices

http://gcc.gnu.org/wiki/avr-gcc#Supporting_.22unsupported.22_Devices

 

Wasn't aware of that, thanks!  Will give me something to fall back on if I fail to compile my own toolchain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is PR61443, fixed in 4.8.4 and 4.9.1+.

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SprinterSB wrote:

This is PR61443, fixed in 4.8.4 and 4.9.1+.

Thank you!  Is this fixable in 4.8.1 by applying https://gcc.gnu.org/viewcvs/gcc?... to Atmel's 3.4.5 toolchain?  I've been running rounds w/ MinGW trying to get a 4.9.2 toolchain working w/ full XmegaE5 support. I finally had a avr-gcc 4.9.2 compiled with my modified avr-mcus.def, but had some linking issues due to some mistakes I made earlier in the build process.  This stuff is so much easier on Linux...