AnsweredAssumed Answered

Unconventional use of the FLASH memory of a STM32F4xx MCU. Possible?

Question asked by de_simone.francesco on Jun 26, 2017
Latest reply on Jun 27, 2017 by de_simone.francesco

Hello, 

I am developing an entertainment firmware for a custom board that mounts an STM32F469 microcontroller. This has 2Megs of FLASH and I would like to do something "unusual" with the memory use. My idea comes from the old retro video games consoles. Many of them had an embedded firmware ROM inside, that was available for user programs in ROM cartridges or programs written with an embedded BASIC interpreter.

I was wondering if it is possible to simulate a similar situation in the internal FLASH of the MCU I am using. Currently, I am using ATOLLIC TrueStudio. Let's look at, for example, a FLASH memory range of this type:

FLASH memory space 
+---------------------------------------------------------+------------------------+---------+
| User program                                            | Locked Code            | Address |
| The user can build his own code from within TrueStudio  | Pre-uploaded functions |  Table  |
+---------------------------------------------------------+------------------------+---------+
|<---------------------- 1,792KB ------------------------>|<------------ 256KB ------------->|

Locked code: Permanent firmware (Maybe factory burned?).

Address Table: Indexed table of pointers to firmware functions.
User programs: Memory space that can be used be the user.

The locked code is a library of functions stored at specific addresses in the FLASH memory. I thought to follow the example in:
Configuring memory space in ATOLLIC TrueStudio

 

So, somehow it's possible to force GCC to place of all functions at specific addresses. Then, all addresses could be stored in a [/url]indexed table of pointers located at the end of the FLASH memory. This is known by the user of course. At this point, the FLASH memory range from 0x08000000 up to the "Locked code" is available to the user for his own, and he could "invoke" a specific memory location in the table to call a function of the firmware.

 

Something like the example shown here:
Pointers to functions using memory address

 

typedef void func(void);
func* f = (func*)0xdeadbeef;
f();

So the user could use or not this code in his programs and take advantage of the "pre-uploaded firmware" that drives the board. When the user develops his code, the compiler should restrict the upload memory range available to the "User program area" only, so that the pre-uploaded firmware is not overwritten. In your opinion is this a good idea, is it possible to do it?

Thanks 

Outcomes