Initialize RAM with value for benchmark

I am trying to initalize the RAM of a microcontroller (STM32F429I-DISC1) with a Hexspeak value (e.g. DEADBEEF). In C it worked by adding following lines to the linker script:

 .fill :
    . = ORIGIN(RAM) + LENGTH(RAM) -1;
  } >RAM

My first idea was to change the memory.x file, but I don't know the exact syntax to initialize the RAM like I did in C. My memory.x file currently looks like this:

 /* NOTE K = KiBi = 1024 bytes */
 FLASH : ORIGIN = 0x08000000, LENGTH = 2M 
 RAM : ORIGIN = 0x20000000, LENGTH = 192K

/* This is where the call stack will be allocated. */
/* The stack is of the full descending type. */
/* NOTE Do NOT modify `_stack_start` unless you know what you are doing */
_stack_start = ORIGIN(RAM) + LENGTH(RAM);

Thanks in advance :smiley:

It looks like memory.x is a regular linker script, so you can just take what you wrote for C and paste it after the MEMORY block.

Out of curiosity: What exactly are you benchmarking? If it's RAM fill speed, it'll be the same.

Thanks for the fast reply :slight_smile:

Yes, I already tried that but i get the following error while building:

"<user>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7em-none-eabihf/lib/libcompiler_builtins-09c3e5620e7b76e8.rlib" "-Tlink.x" "-Bdynamic"
  = note: rust-lld: error: memory.x:8: unknown directive: .fill
          >>> .fill :
          >>> ^

error: aborting due to previous error; 3 warnings emitted

error: could not compile `stm32f429i-disc

To your question: My goal isn't to compare the the RAM fill speed. I want to determine the maximum heap workload. By overwriting the whole RAM with a hexspeak value I can see how many values changed after my program finished. The number of changed values ​​then describes how high the workload is.


It seems that lld doesn't support .fill. Try using the same linker as you use for your C project.

1 Like

@bjorn3 is correct. I forgot that the GNU linker supports some options that the default Rust linker doesn't. In order to switch to the GNU linker, see Configuration - The Cargo Book

Sorry for my late response, I was trying to make it work.
At the end, like you said, the linker was the problem. I updated the rustflags in the config file to use the same linker I used in C. After that, my memory got filled as expected.
Thanks for the help :slight_smile:

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.