cancel
Showing results for 
Search instead for 
Did you mean: 

How to fill unused memory locations with RESET opcode or specific pattern?

SShid
Associate III

I've developed a safety critical application over STM32F103RG microcontroller.

I want to add a fail-safe mechanism to it by making sure that all unused memory locations are either carrying opcode to RESET (like available in PICmicros) or any specific pattern.

I went through this question on the forum, but it doesn't provide instructions to follow for the STM32CubeIDE platform.

Also, if this feature is not available in STM32F, how can this be taken care of? The answer which I've linked says accessing unused memory will throw unhandled exception anyway (is it the hardfault?) If yes, then how should this exception / fault be handled?

8 REPLIES 8

Hi. It is linker option. For IAR: Option->Linker->Checksum select "Fill unused code memory" specify pattern and address range.

Thanks for the response;idea how can it be done through the STM32Cube platform (MX / IDE / Programmer)?

STM32CubeMX used only for generation of initial configuration for MCU.

Filling of unused memory locations possible only after linking. So linker can do this. What IDE are you used? IAR, Keil, AtolicTrueStudio?

Piranha
Chief II

Do you mean RAM or FLASH?

Are you making firmware for Boeing 787?

You are talking about filling gaps in a physically existing memory, so the "unused memory will throw unhandled exception" does not apply here.

Think more of "filling the whole memory with the pattern, and then overlaying the program over it".

CubeIDE uses the GNU toolchain (GCC and binutils), so you would do it in the linker script:

https://sourceware.org/binutils/docs/ld/Output-Section-Fill.html#Output-Section-Fill

Alternatively, you can do it as a post-linking step, using a tool which can handle hexfiles, such as Srecord.

If your mcu does have an MPU, you can use that to define an executable region excluding the "unprogrammed" part; not a trivial undertaking either.

JW

:D :D :D

No no, nothing for the Boeing.

It's not a jet, but I do take safety considerations of my products seriously.

I'm referring to FLASH memory for filling up unused locations.

SShid
Associate III

I'm using STM32CubeIDE.

I did check the options available in Project Properties > C/C++ Build Settings > MCU GCC Linker > General,

but the closest I could find to the ''Fill unused code memory" option as you've mentioned for IAR was

"Discard unused sections (-WI, --gc-sections)"

Any idea if this does the same, or something else?

SShid
Associate III

Never mind about the "Discard unused sections" option.

I found that it only finds and clears off unreachable code to save memory.

Not what I'm looking for.