-1
\$\begingroup\$

I have this really simple "Hello world" piece of software (project attached), running on a STM32WB55 Nucleo board (basically, it sends "HELLO WORLD\n" via USART1, every 1000 ms).

I would be particularly happy if I could manage to run this piece of software from RAM, instead of Flash. This MCU has 196604 bytes of RAM. And my project has a total size of 13332 bytes. So size should not be an issue.

What I'd like to do is: Program starts: load the program in RAM. Afterwards, disable flash, as to increase the overall performance of my program (faster access time) and decrease power consumption.

From what I've read, I should modify the linker script as to create a special section to place the code into and afterwards disable the MCU's flash.

Being the beginner that I am, I have no clue as to where to start.

PS: I'm using CLion (CMake) and GCC.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Are you sure it will be faster? If you run code from RAM the instruction fetches must contend with data access on the same bus. Why do you care about speed if you are printing a message once every second? Have you tried to do any research on your own...a great deal of information on STM32 processors is available. \$\endgroup\$ Commented Oct 16, 2021 at 13:03
  • \$\begingroup\$ @ElliotAlderson This is but a "hello world" project. The one I have in mind would actually benefit from running from ram. And it's not about the great deal of info available regarding stm32s. It's about how you actually get stuff done in this particular case. While not being an embedded systems engineer. Skills arent always portable. \$\endgroup\$
    – Paul Jon
    Commented Oct 16, 2021 at 13:29
  • \$\begingroup\$ I think this is not the ideal site for your question on software on embedded systems. I suggest you ask in StackOverflow instead. \$\endgroup\$ Commented Oct 16, 2021 at 15:59
  • 1
    \$\begingroup\$ @DavideAndrea I think you might be right. Thanks. \$\endgroup\$
    – Paul Jon
    Commented Oct 16, 2021 at 19:12
  • \$\begingroup\$ @PaulJon I haven't used the Armv7E-M architecture (I believe you are discussing a Cortex M4.) But from what I can readily find they are 3-stage Harvard architecture. This doesn't mean code cannot be executed from RAM. But it does strongly suggest that you look closely at how RAM is arranged in the Nucleo board. If it is possible (there is RAM located in the instruction address space), then this may just be a linker issue. Linkers almost always permit manual positioning of code, though you may need to dig into the linker manual to work out the details. (Or you may need to manually copy code.) \$\endgroup\$
    – jonk
    Commented Oct 17, 2021 at 3:43

1 Answer 1

1
\$\begingroup\$

there are times when you want to for example write to flash and at the same time you can not read from flash you can load your code into RAM. using RAM may increase the speed of fetching code into CPU (it depends on Architecture but in ARM I think it will increase).

you have to use specific keyword related to your compiler so the compiler will place the code right at the startup into RAM before "main" function starts so the first things you should do in main is calling your code that is in RAM and inside that code you can disable flash. you should make sure you never refer to flash after disabling flash or else an exception will occur. (so be careful of using things like const variable) take a look at this answer

https://stackoverflow.com/questions/15137214/how-to-run-code-from-ram-on-arm-architecture

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.