This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

A small timer_handler from RAM?

I have a timer that wakes up every 20ms to read twi.

Unfortunately it takes 4.4mA for the CPU to execute code from flash.

I would like to reduced the current consumption by executing the code from RAM 2.4mA. It would be better to use the EasyDMA to read twi. But that does not appear to be possible?

If it is possible to load the code for the small timer_handler into RAM? How is this done? Are there any examples of this?

  • Assuming you’re using Keil, I’ve been talking to our developers here now about your question and how we at least can help you implement this on your application. The easiest route would be to use a scatter file to load a file into a specific part of RAM and the run that piece of code for the duration you need. In the linker tab in “options for target” in Keil you’ll be able to define to use scatterfile and which one to use. You can autogenerate the scatter file in Keil and just define the section of the RAM you want to place the code in. I think this example from Keil themselves displays the settings quite well: www.keil.com/.../

    The downside is the you have to upload a complete file and not only sections, but it is simpler. There is an second option to use functions in Keil called attribute((section and/or attribute((address. This will enable you upload variables and sections of code to specific areas of memory, RAM included. www.keil.com/.../armccref_Caccache.htm

    Debugging RAM code isn’t possible as you can’t set break points in RAM in Keil. So the solution would be to stop the code as it exits RAM and start running in flash again.

    So, yes, it will be possible to run code for this from RAM, but unfortunately we don’t have an example ready to show this feature.

  • This works in GCC:

    void __attribute__((section(".data"))) functionInRam(void) {
    

    The linker complained about changin attributes for .data but the code run just fine. I used to make a fast flash write function. 8 words took 0.37ms when run from flash, but only 0.21ms when placed in RAM. This included the wait for the flash write to finish.

    Hope that can help.

    Best regards, Andreas Wileur

Related