How to Force Specific Memory Area for Specific Variables in S32DS (RAM, Flash, Data Flash)

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

How to Force Specific Memory Area for Specific Variables in S32DS (RAM, Flash, Data Flash)

298 Views
karmegancjk
Contributor III

Hi,

I am working with the S32K358 and using S32 Design Studio (S32DS) as my IDE. I would like to reserve specific memory regions for certain variables and ensure that these allocations are not affected by the compiler or linker during build time—especially when new variables or arrays are introduced later in the project.

My Requirements

1. Dedicated RAM Section

I need to allocate a specific section of RAM exclusively for my own variables. These variables should be placed at fixed memory locations and must not be moved or overwritten by the compiler/linker during future software builds or updates.

2. Dedicated Flash / Data Flash Section (EEPROM-like usage)

I want to reserve areas in Flash or Data Flash for persistent data storage. For example:

  • Application_Valid_Flag

  • Bootloader_Valid_Flag

  • Arrays or structures containing configuration or runtime state data

These variables should be stored at fixed memory addresses and should remain unaffected by firmware reprogramming or section relocations—functioning similarly to EEPROM.

My Questions

  1. How can I configure the project settings in S32DS to reserve and assign specific memory addresses for variables (RAM, Flash, or Data Flash)?

  2. How do I declare variables in code so they are placed into these custom-defined memory sections?

  3. If S32DS or the compiler does not provide direct settings for this, how can I manually modify the linker script to define and reserve these specific memory areas?

Thanks and Regards,

Karmegan C

0 Kudos
Reply
6 Replies

249 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @karmegancjk,

It depends on the compiler. For example, GCC does not support placing a variable directly at a specific address. Instead, GCC requires you to place variables in named sections, and then use the linker script to assign those sections to specific memory addresses.

Have a look at any RTD example, the linker file already defines multiple memory sections. You can create new sections by referencing these existing ones and extending them as needed.

For example, Placing a Variable in int_sram_no_cacheable:

#pragma GCC section bss ".mcal_bss_no_cacheable"
uint8_t variable;
#pragma GCC section bss

 

Here is an example that uses ITCM and DTCM and the linker file is modified because of that.

https://community.nxp.com/t5/S32K-Knowledge-Base/Example-Siul2-Port-Ip-Example-S32K344-ITCM-DTCM-S32...

 

Regards,

Daniel

 

 

0 Kudos
Reply

172 Views
karmegancjk
Contributor III

Hi Daniel,

  1. If I place a variable in the int_pflash0 custom flash memory section or the int_dflash0 custom data flash memory section, how can I access that variable? Since writing to flash memory requires high-voltage operations, is it possible to write directly to variables placed in the flash or DFlash memory regions?

  2. How can I verify whether the flash or DFlash memory region I created is correct?

Thanks and regards,
Karmegan C

 

0 Kudos
Reply

164 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi Karmegan C,

1.

It is not possible to write there.

The flash sector (0x2000 size) would need to be erased first.

You could use FEE driver on DFlash for non-volatile variables in flash.

2.

Check the .map file after compilation.

You should be able to locate the data names and their locations.

 

Regards,

Daniel

 

0 Kudos
Reply

153 Views
karmegancjk
Contributor III

Hi Daniel,

1. I have checked the variable names and their memory locations; they are listed in the .map file.

  • The array is declared in the main.c file.

            uint32_t my_array[10] __attribute__((section(".my_section")));

  •  In the linker, file 

           Memory command:

           MEMORY
           {
                    int_pflash : ORIGIN = 0x00400000, LENGTH = 0x00600000 /* 6144KB */
                    int_pflash0 : ORIGIN = 0x00A00000, LENGTH = 0x001D4000 /* 1872KB - 176KB (sBAF + HSE)*/

             }

           Section command:

           /* Custom section in Flash */
           .pflash0:
            {
                 KEEP(*(.my_section))
             } > int_pflash0
  • map file
         .pflash0               0x00a00000 0x28
         *(.my_section)
          .my_section      0x00a00000 0x28 ./src/main.o
                                      0x00a00000 my_array
 

My questions are:

  1. How can I use (read and write operation) the array my_array[]?

  2. After a power-on reset, can the array my_array[] retain data from the address of 0x00A00000?

MCU - S32K358

SW - RTD 4.0.0

IDE - S32DS 3.5.13 IDE

0 Kudos
Reply

151 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @karmegancjk,

1. 

The my_array data cannot be overwritten.

You would need to erase the whole sector at 0x00A00000 (0x00A00000 - 0x00A02000) first.

Use RTD FEE driver instead.

2.

Sure, this is non-volatile flash memory.

 

Regards,

Daniel

 

0 Kudos
Reply

145 Views
karmegancjk
Contributor III

Hi Daniel,

  1. The above memory force approach assumes an increase in application code size in the future. Will the compiler or code be able to access my custom memory region?

  2. When I try to directly access My_array[], I am encountering a hard fault. 

  3. To explain my case: I have both bootloader and application code running on the MCU. When transitioning from the application code to the bootloader (or vice versa), I am using flags like application_valid_flag and boot_valid_flag. I want to declare these flags in my custom memory region to ensure they are not affected by memory address increments or compiler optimizations. Additionally, I need 16KB of flash memory, which I want to use like EEPROM. Importantly, this 16KB section should remain unaffected. How should I handle this scenario?

Thanks and Regards,

Karmegan C

 

 

0 Kudos
Reply