Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

Can't run code out of flash!

I am trying to run my Nios II code from flash with no success. I can run from the IDE, no problem when program memory is in RAM. I then change the build for flash. The flash programmer works fine - no errors. When I set the PC to base address of flash (using FS2's CLI) and issue the "GO" - nothing happens. I also tried to click the "RUN as Hardware" button in the IDE - same result. I also tried to boot from internal ROM and call my app in flash from a function pointer (recommended by "smcnutt") but it does nothing. In fact when I use the FS2's CLI, after I type GO I can't halt. I can initially step fine - but at some point it gets lost or something????

any suggesstions?

I don't know if it's related but when I load my code built for RAM - into RAM, and then set the PC mannually from FS2's CLI and type GO - same result, nothing happens...

7 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Silly question but how exactly are you specifying that your program be located in flash? The system library properties dialog in the IDE allows you to select memory devices for several things - .text, .rodata, .rwdata, etc. Obviously .text (code) and .rodata (read only data) can be in flash, but anything that requires the CPU to write/modify data (.rwdata and stack) must be in a RAM of some sort.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have the .text set to flash and the other 2 set to RAM. This is how I get the code compiled for flash. Then I run the Flash programmer and it works fine - code programmed to flash successfully. When I reset, the "Boot ROM" message comes up, but when I use the function call below (where SOME_ADDR is the address of flash) nothing happens. In addition I try to set the PC to 0x100000 (flash base) directly using the CLI, and then GO - nothing happens.

    # define SOME_ADDR 0x ....

    void whatever ()

    {

    void (*foo)(void) = (void (*)(void)) SOME_ADDR;

    ...

    foo(); /* call SOME_ADDR */

    }
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi lemonoje,

    Can you post your section info for the RAM code (e.g. objdump -h)?

    Regards,

    --Scott
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Scott,

    Not sure what you mean. How/where do I get that? I was just looking around trying to find a map file. Does Nios II make a map file so you can see where everything falls??

    John
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    > How/where do I get that?

    Use objdump for your elf file that's built for RAM:

    nios2-elf-objdump -h ram.elf

    > Does Nios II make a map file ...

    I don't think it does by default ... you need to add it as

    an option (-Map mapfile) to ld.

    --Scott
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I thought you could just load code pretty much wherever you want, set the PC and GO!

    Guess it's not that simple. After I'm done re-synthesizing, I'll get that objdump -h. What will that tell me?

    John
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Alright - I got something working, I just don't know what it means. I set the IDE up as follows:

    .text - ext_SRAM

    .rodata - int_SRAM

    .rwdata - int_SRAM

    This should put the boot copier at the beginning of flash so that when the board powers up - the copier will copy the program to RAM from flash and run it from RAM. THIS WORKS! the code runs fine.

    What should the "Configuration:" setting be? Release or Debug? One thing I noticed. I can't run at all from SRAM with the IDE Configuration: set to the Release setting.

    hmmm why?