Skip to main content
SShid
Associate III
December 10, 2019
Question

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

  • December 10, 2019
  • 8 replies
  • 3352 views

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?

This topic has been closed for replies.

8 replies

oleksandr.karbivsky
Senior II
December 10, 2019

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

SShid
SShidAuthor
Associate III
December 10, 2019

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

oleksandr.karbivsky
Senior II
December 10, 2019

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
Principal III
December 10, 2019

Do you mean RAM or FLASH?

Are you making firmware for Boeing 787?

SShid
SShidAuthor
Associate III
December 11, 2019

: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.

waclawek.jan
Super User
December 10, 2019

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