A Method for Absolute Memory Address Location in MCUs

Follow+Star Public Account Number, don’t miss out on exciting contentSource | Renesas Embedded EncyclopediaIn a previous article titled “How to Add Version Information to MCU Projects?” we used absolute addresses:

#define VERINFO_ADDR_BASE   (0x0800FF00) // Address for storing FLASH
const char Software_Ver[] __attribute__((at(VERINFO_ADDR_BASE + 0x00)))  = "Software: 1.0.0";
const char Compiler_Date[] __attribute__((at(VERINFO_ADDR_BASE + 0x40))) = "Date: " __DATE__;
const char Compiler_Time[] __attribute__((at(VERINFO_ADDR_BASE + 0x60))) = "Time: " __TIME__;

Today, I will share another method for absolute address location in Flash on Renesas e2 studio.

The main approach is to modify the .ld script file using the official Renesas compiler tool e2 studio, allocating a small section in Flash, and then implementing it through __attribute__.

The specific steps are as follows

1

First, allocate a section in Flash and modify the .ld file in e2 studio. The project path is shown in the image below

A Method for Absolute Memory Address Location in MCUs

2

In the fsp.ld file, under the memory options, add a new partition, directly specifying the starting address and length.

A Method for Absolute Memory Address Location in MCUs

3

In fsp.ld, under text editing, initialize my_code (!rx), and remove the “!”

A Method for Absolute Memory Address Location in MCUs

4

Edit my_code as shown below

A Method for Absolute Memory Address Location in MCUs

The text editor will automatically create the following code:

A Method for Absolute Memory Address Location in MCUs

5

To avoid potential issues, it is best to modify the Flash address space, as at this point, my_code is encapsulated in the Flash area, requiring modification of the Flash area address.

First, copy memory_regions.ld and rename it in the same directory, then include the newly copied file in the fSP.ld file’s text editor:

A Method for Absolute Memory Address Location in MCUs

Next, we need to modify the Flash space in memory_regions_my.ld

A Method for Absolute Memory Address Location in MCUs

Similarly, we can set the starting address and length of my_code here, directly replacing the starting address and length alias in the newly created partition from step 2.

6

In the main function variable declaration, add the following code

const char buff[16] __attribute__((section(“.my_code “))) = {“1234567890abcdef”};

The length of buff must match the partition size, otherwise an error will occur.

Build needs to use release.

7

After compilation, check as follows:

A Method for Absolute Memory Address Location in MCUs

I recommend using e2 studio help contents.

———— END ————

A Method for Absolute Memory Address Location in MCUs

How to Build a Development Team for Embedded Projects?

A Method for Absolute Memory Address Location in MCUs

Several Detection Methods for MCU Automatic Baud Rate Recognition

A Method for Absolute Memory Address Location in MCUs

32-bit Application Development in a 64-bit MPU Linux Environment

Leave a Comment