const in flash memory

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

const in flash memory

2,600件の閲覧回数
davetelling
Contributor I

I am using the IAR toolset, and the device is MKE02Z64. I have several constant values that I'd like to place in flash memory (if possible) to free up RAM, but I cannot find a way to do this with the IAR tools.

Initially, I just had a fairly standard: const uint16_t foobar;

That still placed foobar in data memory. I next tried (based on something I found online): const volatile uint16_t foobar @ "FLASH";

This did not generate any errors or warnings, but foobar is still in data memory, not code memory.

Can this be done? If so, how?
Thanks!

タグ(3)
0 件の賞賛
3 返答(返信)

1,274件の閲覧回数
davetelling
Contributor I

Well, it appears that mark Butcher is correct - I dug through the output of the linker, and in deed, the const are in flash memory. What put me off is that the map file generated showed const as "Data" rather "Code", and I just assumed that it was talking about the memory section, not the actual type of data.

Thanks for your replies!

0 件の賞賛

1,274件の閲覧回数
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Dave,

Please check below examples about how to place const at Flash address of IAR IDE software.

In *.icf file define a section [.myparameter] start address  and place this section in ROM memory:

define symbol __region_FlexNVM_start__  = 0x10000000;

place at address mem:__region_FlexNVM_start__ { readonly section .myparameter };

In code file (*.c) place data into this section:

const char parameter1[16] @ ".myparameter" = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF};

Another way for IAR to place variable in dedicated address:

#pragma location=0x3000

const int test1 = 1;

const int test2 @ 0x3004 = 2;

Then in the map file, I could find below result:

test1                   0x00003000    0x4  Data  Gb  hello_world.o [1]

test2                   0x00003004    0x4  Data  Gb  hello_world.o [1]

If I use below code:

#pragma location=0x3000

const int test1 = 1;

const int test2 = 2;

Then there only place test1 variable in 0x3000, and test2 in another place, the map with below result:

test1                   0x00003000    0x4  Data  Gb  hello_world.o [1]

test2                   0x000016ec    0x4  Data  Gb  hello_world.o [1]

Another way to put variables in dedicated address:

In .icf file define memory region, such as:

define symbol __ICFEDIT_region_ROM_DATA_start__ = 0x0003F800;

define symbol __ICFEDIT_region_ROM_DATA_end__   = 0x0003FFFF;

define region ROM_DATA_region   = mem:[from __ICFEDIT_region_ROM_DATA_start__   to __ICFEDIT_region_ROM_DATA_end__];

place in ROM_region   { readonly, block CodeRelocate};

In C code, such as:

#define NVM_DATA      _Pragma("location=\"NVM_DATA\"")

NVM_DATA const int test1 = 1;

NVM_DATA const int test2 = 2;

_Pragma("location=\"NVM_DATA\"") is same as #pragma location="NVM_DATA"

Wish it helps.


Have a great day,
best regards,

Ma Hui

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,274件の閲覧回数
mjbcswitzerland
Specialist V

Hi Dave

The @ "FLASH" is only used for volatile consts.

The IAR (default) behavior is to put consts (both global and static) into Flash, although strictly the const keyword means that the variable has read-only attributes and not that it is located in a certain memory area (although embedded systems would normally work as if it were sicn eit makes sense).

Eg.

static const unsigned char usb_language_string[] = {4,  DESCRIPTOR_TYPE_STRING, LITTLE_SHORT_WORD_BYTES(UNICODE_LANGUAGE_INDEX)};

static const unsigned char manufacturer_str[] = {10, DESCRIPTOR_TYPE_STRING, 'M',0, 'a',0, 'n',0, 'u',0};

static const unsigned char product_str[] = {16, DESCRIPTOR_TYPE_STRING, 'M',0, 'y',0, ' ',0, 'P',0, 'r',0, 'o',0, 'd',0};

static const unsigned char serial_number_str[] = {10, DESCRIPTOR_TYPE_STRING, '0',0, '0',0, '0',0, '1',0};

static const unsigned char config_str[] = {10, DESCRIPTOR_TYPE_STRING, 'C',0, 'o',0, 'n',0, 'f',0};

static const unsigned char interface_str[] = {8,  DESCRIPTOR_TYPE_STRING, 'I',0, 'n',0, 't',0};

static const unsigned char *ucStringTable[] = {usb_language_string, manufacturer_str, product_str, serial_number_str, config_str, interface_str};

Here the map shows:

usb_language_string 0x00003d24

manufacturer_str 0x00003d28

product_str 0x00003d34

serial_number_str 0x00003d44

config_str 0x00003d50

interface_str 0x00003d5c

ucStringTable 0x1ffff11c


Notice that the arrays are all put into flash apart from the final one. I can't explain why there are some exeptions to the rule, whereby your particular case may be such an exception, for whatever reason.

It is probably best to contact IAR directly since I have also not been able to find a method to control the final few remaining exceptions. Fortunately it only affects very few such things as far as I have been able to see.

Regards

Mark

Kinetis: µTasker Kinetis support

KE: µTasker FRDM-KE02Z support / µTasker FRDM-KE02Z40M support / µTasker FRDM-KE06Z support

For the complete "out-of-the-box" Kinetis experience and faster time to market