I would like to define a C variable in RAM which can survive a CPU reset in NIOS II IDE. Something like __persistent in PIC world or __no_init in Renesas world.

Is there a similar keyword for NIOS compiler, which is based on gcc?

  • 1
    \$\begingroup\$ In order to have a complete question first you need to identify the compiler, is it gcc? You may need to do this manually creating a section in the linker script. \$\endgroup\$ – Chris Stratton Jun 7 at 13:14

NIOS uses a GCC variant, so you can use the GCC style attributes to place a variable in the .noinit section which basically forgoes any initialisation of the variable. e.g.

char someVar __attribute__ ((section (".noinit")));

The RAM is not cleared during a NIOS processor reset, and GCC wont initialise the value of it, so the variable should survive.

It wouldn't however survive a full FPGA reset/reconfigure as that would reinitialise the RAM entirely. To cope with that you would need external SRAM.


Putting the variable in .noinit section seems to be the right way to do it. However, .noinit section is missing in auto-generated NIOS linker file, so I had to add it manually:

.noinit (NOLOAD):
    PROVIDE (_alt_partition_noinit_start = ABSOLUTE(.));
    *(.noinit .noinit.*)
    . = ALIGN(4);
    PROVIDE (_alt_partition_noinit_end = ABSOLUTE(.));
} > onchip_memory2_0

The important part is the (NOLOAD) directive which tells the linker that it shouldn't include any initialization code for this section.

Of course, the content of the on-chip RAM will be lost during reconfiguration or when its reset signal is asserted.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.