##Enabling the Suspend To RAM capabilities on the RoadRunner 1.1 Board 

A tutorial on how to recompile the Linux kernel 4.9.109 from Linux4SAM 5.8+ in order to take advantage of the Suspend To RAM feature of the RoadRunner 1.1 Board


<span class="abstract">
The updated RoadRunner V 1.1 has the possibility to put the CPU in 
<b>Suspend To Ram</b> state in order to lower the power consumption but be 
able to awake in around 1s. Power consumption in this state is around 2mA @3,3V.
</span>

To recompile the right kernel to enable the lowpower <b>Suspend To Ram</b> capabilities of the 
RoadRunner 1.1 you can clone the GitHub repository:

* [GitHub Linux4SAM 5.8+ fork](https://github.com/asquini/linux-at91/tree/RoadRunner1_1_lowpower)

use the branch: RoadRunner1_1_lowpower.<br><br>

This is a fork of the official Linux kernel 4.9.109 from Atmel Linux4SAM 5.8+ GitHub repository: 

* [GitHub Linux4SAM 5.8+](https://github.com/linux4sam/linux-at91/commits/master)

with the only additions of the right <b>acme-roadrunner-defconfig</b> file and the right <b>acme-roadrunner-lowpower.dts</b> files.

Before recompiling you need to prepare the compilation environment with the correct config:
<pre class="terminal">
$ <b>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- acme-roadrunner_defconfig</b>
</pre>

To change some options in the kernel you can issue (not necessary at this point though):
<pre class="terminal">
$ <b>make ARCH=arm menuconfig</b>
</pre>

Then you need to generate the .dtb file:
<pre class="terminal">
$ <b>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- acme-roadrunner-lowpower.dtb</b>
</pre>

Now you can compile the kernel image:
<pre class="terminal">
$ <b>make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage</b>
</pre>

zImage will be in your directory tree in:
<pre class="terminal">
<b>arch/arm/boot/zImage</b>
</pre>

transfer zImage in the RoadRunner microSD directory /boot.

(in order to generate a working RoadRunner microSD please see this tutorial): 

* [Build a Debian Jessie root filesystem](https://www.acmesystems.it/debian_jessie)

To test the <b>Suspend To Ram</b> condition issue the following commands:
<pre class="terminal">
$ <b>mem2io -w -i fc040018,300</b>
$ <b>rtcwake -m mem -s 5</b>
</pre>

The first instruction sets a particular CPU memory mapped I/O register that corresponds 
to a backup pin of the SAMA5D27. This backup pin is used onboard the roadrunner1.1 to 
maintain enabled the DDR3 RAM power regulator even when in shutdown mode. Normally when 
in shutdown mode both CPU and DDR3 memory power regulators onboard the RoadRunner will 
be disabled.

The second instruction is used to put the CPU in "<b>mem</b>" state: one of the lowpower 
states supported by the Linux kernel.

In order to support the <b>Suspend To Ram</b> state it is necessary to insert a special 
directive in the command line parameters. This can be found in the 
acme-roadrunner-lowpower.dts file used in this tutorial.

<b>mem2io</b> is an utility program by Dougg Gilbert that lets change CPU and memory 
registers from userspace. You can recompile it for RoadRunner from this link<br> 
(download the SAMA5 version):

* [Dougg Gilbert gpio_utils](https://www.acmesystems.it/gpio_utils)

The <b>RoadRunner1.1</b> power consumption when in Suspend to RAM state is down to 
<b>3mA @ 3.3V</b> that corresponds to <b>2.4mA @ 5V</b> when using the suggested <b>BertaD2 
V1.1</b> power regulator: <b>Texas TPS62740</b>.

The <b>Suspend To Ram</b> state puts the DDR3 RAM in autorefresh mode so to maintain 
the complete memory state and stores the Linux internal state in order to let 
it "continue" from the point where it has been suspended. After that the CPU 
is put in shutdown mode and the CPU power regulator onboard the RoadRunner 
is disabled completely. Also all the hardware attached to the 3.3V output of 
the RoadRunner will be switched off as well as the microSD power.

When the mem state is finished (after 5s in our example) the Real Time Clock in the backup 
area of the CPU SAMA5D27 will raise the shutdown line restarting the CPU. However when the bootloader 
is loaded in memory it will find that the previous state was a <b>Suspend To Ram</b> so 
it will jump directly in a particular location of the main DDR3 RAM memory and 
Linux will continue from that point.
The process of reloading the bootloader and give out the Linux prompt is around 
<b>1s</b> only in this way.

  
To be able to support this capability also the bootloader at91bootstrap needs 
to be involved. From the 3.8.8 release of at91bootstrap the Suspend To RAM 
capability is supported:

 * [Compiling AT91bootstrap 3.8.8](https://www.acmesystems.it/at91bootstrap_3_8)
 
@include='adv_roadrunner'
 
