The linker in the Nios® II IDE will not automatically put a subroutine in a memory that is not designated as .text.
In order to include the subroutine in a specific memory section other than .text (in this example, .rwdata), do the following:
- Define a custom section for this specific routine, for example: void my_subroutine(void) __attribute__ ((section (".usersection")));
- Open the generated.x file that is located in your <sw_proj>_syslib/Debug/system_description folder and look for the __ram_rwdata_end
- Add the following lines to the generated.x file:
.usersection : AT ( LOADADDR (.rwdata) SIZEOF (.rwdata) ){
PROVIDE (_alt_partition_usersection_start = ABSOLUTE(.));
*(.usersection .usersection.*)
. = ALIGN(4);
PROVIDE (_alt_partition_usersection_end = ABSOLUTE(.));} >onchip_ram
PROVIDE (__flash_alt_partition_usersection_start = LOADADDR(.usersection));
- Modify alt_load.c to perform the custom section copy operation. See below for reference:
extern void __flash_alt_partition_usersection_start;
extern void _alt_partition_usersection_end;
extern void _alt_partition_usersection_start;/*
* Copy the .usersection section.
*/
alt_load_section (&__flash_alt_partition_usersection_start,
&_alt_partition_usersection_start,
&_alt_partition_usersection_end);