I need help figuring out how to store data in flash memory that my application can use. I am using a MSP430F5437A device.
What I want to do is store two types of data. One is result data that I collect periodically (~every 2 sec) and the second is reference data that is updated occasionally (twice a year). The reference data is read from the main application and is used to perform calculations.
I would like to map two variables to flash memory and read as if they were any other variable
I modified the .cmd file first by adding “MYDATA” as follows:
/****************************************************************************/
/* SPECIFY THE SYSTEM MEMORY MAP */
/****************************************************************************/
MEMORY
{
SFR : origin = 0x0000, length = 0x0010
PERIPHERALS_8BIT : origin = 0x0010, length = 0x00F0
PERIPHERALS_16BIT : origin = 0x0100, length = 0x0100
RAM : origin = 0x1C00, length = 0x4000
INFOA : origin = 0x1980, length = 0x0080
INFOB : origin = 0x1900, length = 0x0080
INFOC : origin = 0x1880, length = 0x0080
INFOD : origin = 0x1800, length = 0x0080
FLASH : origin = 0x5C00, length = 0xA380
/* old line; keep as reference */
/* FLASH2 : origin = 0x10000,length = 0x35C00 */
FLASH2 : origin = 0x10000,length = 0x1AE00
MYDATA : origin = 0x2AE00,length = 0x1AE00
INT00 : origin = 0xFF80, length = 0x0002
…
/****************************************************************************/
/* SPECIFY THE SECTIONS ALLOCATION INTO MEMORY */
/****************************************************************************/
SECTIONS
{
.bss : {} > RAM /* GLOBAL & STATIC VARS */
.data : {} > RAM /* GLOBAL & STATIC VARS */
.sysmem : {} > RAM /* DYNAMIC MEMORY ALLOCATION AREA */
.stack : {} > RAM (HIGH) /* SOFTWARE SYSTEM STACK */
.text : {}>> FLASH | FLASH2 /* CODE */
.text:_isr : {} > FLASH /* ISR CODE SPACE */
.cinit : {} > FLASH /* INITIALIZATION TABLES */
.const : {} > FLASH | FLASH2 /* CONSTANT DATA */
.cio : {} > RAM /* C I/O BUFFER */
.pinit : {} > FLASH /* C++ CONSTRUCTOR TABLES */
.init_array : {} > FLASH /* C++ CONSTRUCTOR TABLES */
.mspabi.exidx : {} > FLASH /* C++ CONSTRUCTOR TABLES */
.mspabi.extab : {} > FLASH /* C++ CONSTRUCTOR TABLES */
.mydata : {} > MYDATA /* custom data */
…
In my source file I have the following functions to read and write flash data:
#define ARRY_SZ 5000
typedef struct _run_data
{
unsigned long value; // actual value
unsigned int time_ms; // time in millisecond
} tRUN_DATA;
#pragma DATA_SECTION(flash_run_data, ".mydata");
#pragma DATA_ALIGN(flash_run_data, 1);
tRUN_DATA flash_run_data[ARRY_SZ];
#pragma DATA_SECTION(flash_reference, ".mydata");
#pragma DATA_ALIGN(flash_reference, 1);
tRUN_DATA flash_reference[ARRAY_SZ];
//--------------------------------------------------
void FLASH_Read(tRUN_DATA *data, int index)
{
data->value = flash_run_data[index].value;
data->time_ms = flash_run_data[index].time_ms;
}
//--------------------------------------------------
void FLASH_Write(tRUN_DATA data)
{
FLASH_UNLOCK;
flash_run_data[flash_index].value = data.value;
flash_run_data[flash_index].time_ms = data.time_ms;
FLASH_LOCK;
flash_index++;
}
I am getting warnings during compile that I don’t understand. They are:
#17003-D relocation from FLASH_Read” to symbol “flash_run_data” overflowed; the 18-bit relocated address 0x2ae00 is too large to encode in the 16-bit filed
#10015-D output file “.out” cannot be loaded and run on a target system.