How to allocate an array

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to allocate an array

1,605 Views
giannigrondona
Contributor III

Hi

I am using LPC54608 with MCUXPresso IDE. I'd like to allocate an array of const uint8:t at a fixed address of read only memory. ( address 0x7ffc) I tried to use the keywoord __allocate__at  but it doesn't work. Someone could help me ?

Thank you in advance

Giovanni Grondona

0 Kudos
5 Replies

1,104 Views
giannigrondona
Contributor III

Hi Bob

Thank you for your help. I use MCUXpresso as IDE and it generates in automatic way the script file, so I am not able to add  custom sections .How can I do ?

Thank you for your help.

Giovanni Grondona

0 Kudos

1,104 Views
giannigrondona
Contributor III

Hi

Enrich thnak you for upir help, I know I can place  my code or my data in different memory support ( internal flash memory  or serial flash memory or external RAM) but  cannot choose the address where to put my data. The address is choosen by linker,

0 Kudos

1,104 Views
BlackNight
NXP Employee
NXP Employee

Hi Giovanni,

see that article above: you can decide at which address you want the data and tell this the linker.

Additionally, you can configure the linker file of the MCUXPresso IDE with your own linker file script extensions using the managed linker script, see Tutorial: Porting BLE+NRF Kinetis Design Studio Project to MCUXpresso IDE | MCU on Eclipse  as a possible use case. It shows how to add custom sections to the linker file.

I hope this helps,

Erich

1,104 Views
bobpaddock
Senior Contributor III

A custom section needs added to the linker script file with the fixed address that you want to use.

Quickly hacked example of far from complete linker section for GCC from linker script I had at hand:

MEMORY
{

...

MYTABLE = 0x7FFC;

...

}

.mtb : /* Micro Trace Buffer (MTB) memory buffer address as defined by the hardware */
{
. = ALIGN(4);
_mtb_start = .;

. = 1K; /* Allocate 1K of space for MYTABLE */
KEEP(*(.mtb_buf)) /* Need to KEEP MBT as not referenced by application */
. = ALIGN(4);
_mtb_end = .;
} > MYTABLE;

How do define it in C:

#define SA_MTB_ALIGNEMENT (64U) /* Alignment of the MTB buffer */
uint8_t __attribute__((section (".mtb_buf"))) mtb_buf[__SA_MTB_SIZE] __attribute__ ((aligned (SA_MTB_ALIGNEMENT)));

Make sure to align the table to a 4, 8, or 64 byte boundary as needed using the ALIGN directive to prevent bus faults on some parts.


BTW 0x7FFC seems like an unlikely address to use for all but the smallest of parts, it will collide with code in the .text section.

0 Kudos

1,104 Views
BlackNight
NXP Employee
NXP Employee

Hi Giovanni,

this one should help you: Defining Variables at Absolute Addresses with gcc | MCU on Eclipse 

In addition to that, check the MCUXpresso IDE user Guide (in the Help menu):

pastedImage_2.png

I hope this helps,

Erich

0 Kudos