According to nRF51822/nRF51422 PS v3.1 table 34, current consumption can be decreased by executing code from RAM instead of from flash. How is it possible to execute code from RAM?
First you must define a specfic RAM block, then you need to assign your code to that RAM block.
RAM block layout is described in nRF51822/nRF51422 PS v3.1, table 6 and table 7. So the way to do this is to devide the RAM into two sections in Keil -> Options for Target and then assign the spi_slave.c RAM to the IRAM2 section as shown in the following images.
RAM configuration for S110 softdevice, 32kB RAM (e.g. nRF51 QFAC variant) could be:
RAM configuration for S110 softdevice, 16kB RAM (e.g. nRF51 QFAA variant) could be:
Right click the source code file in Keil and select "Options for File 'main.c' if you want to place source code for main.c into RAM:
Note that different softdevices reserve RAM space on the chip so there is limited amount of RAM remaining for the application, especially for 16kB RAM variants. The above configuration may be different for other softdevices as they use different amount of RAM, see Softdevice Specification (SDS) for the relevant softdevice, chapter about resource usage. Compatibility of different SDS's and softdevices is listed in the nRF51 compatibility matrix.
Also note that 2kB is reserved from the application RAM space for the softdevice and application stacks, see this thread and this thread
Make sure to allocate enough RAM space for the source code that you assign to RAM. It can be seen in the .map file in the _build folder how much RAM is actually used by the source file that are assigned to RAM.
Nice tutorial! I really appreciate you.
I have a question. I'm using IAR for ARM (in Windows 7) and GCC (in Fedora 13) when I work with my board.
Then what settings should be needed when I want to run my codes in the RAM?
I'm using Softdevice S110 7.1 and SDK 7.2 .
I have not tried exectute code from RAM using IAR but I can see there is some guide in the IAR C/C++ Development Guide, twelfth edition, page 64 and page 99, available when you click help->C/C++ Development Guide in the IAR IDE.
Nice! Is it possible to add instructions for us who don't have KEIL, but use makefiles and GCC?
Hi. We did not make time yet to dig into how to do this for GCC. Hopefully, someone can share info on that.