This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Placing Constants at a Specific RAM Address

Other Parts Discussed in Thread: MSP430F6723

I'm implementing an application with the MSP430F6723 which requires use of a RAM ISR table, so as per some example code from TI I've made a table of ISR addresses and located it at the proper RAM address:

#pragma RETAIN
#pragma location=INT_VECT_START_ADDR
isr_struct_t const ram_isr_table =
{
	{
		EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR,
		EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR,
		EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR,
		EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR,
		EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR,
		EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR,
		EMPTY_ISR, EMPTY_ISR, EMPTY_ISR, EMPTY_ISR
	},
	(isr_type_t) &RTC_RAM_ISR,
	// ... etc ...
};

This works fine during debugging, but once power is removed then restored, the table is not restored in RAM. Those addresses just contain random noise. Looking at the disassembly file, I don't actually see any code to initialize this table - I suspect that the debugger simply loaded the table into RAM during programming.

However, this behavior is fixed when I remove the "const" keyword. In this case, the table is stored in the Data section of flash and loaded into RAM during boot.

I would like to understand what logic in the compiler is causing this to happen. The program works now, but I would like to be able to mark this table as "const" to ensure that no user code modifies it. As far as I know, "const" normally causes the compiler to put variables into Flash, so perhaps specifying a location in RAM together with "const" are conflicting orders. Can somebody with more insight to the compiler please explain the cause of this behavior?

  • Jacob Dickinson said:
    perhaps specifying a location in RAM together with "const" are conflicting orders

    That's correct.  If you use "const", then this data is placed in the .const section, an initialized section.  Typically, this section is allocated to FLASH.  It is possible to allocate to RAM.  But that is more involved.  You actually allocate to RAM for running, but to non-volatile memory (i.e. FLASH) for loading.  You have to insure that, as part of system start up, the section is copied from FLASH to RAM.  While there are some compiler features which make this straightforward, none of it is done automatically.  

    If you don't use "const", then compiler allocates it to .data.  The linker collects all the .data sections together and uses that to create a section named .cinit.  The system startup (or boot) routine  processes the .cinit section so that the .data sections are initialized before main starts to run.

    The compiler should handle this better.  I filed SDSCM00050801 in the SDOWP system to have this investigated.  Feel free to follow it with the SDOWP link below in my signature.

    Thanks and regards,

    -George

  • Thanks George! I'll keep an eye on the issue report.