# Tick-less FreeRTOS with LPC4337 and power down mode

**URL:** <https://forums.freertos.org/t/tick-less-freertos-with-lpc4337-and-power-down-mode/1586>\
**Category:** Kernel\
**Created:** [November 9, 2015, 10:58pm UTC](https://forums.freertos.org/t/tick-less-freertos-with-lpc4337-and-power-down-mode/1586 "2015-11-09T22:58:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 9, 2015, 10:58pm UTC](https://forums.freertos.org/t/tick-less-freertos-with-lpc4337-and-power-down-mode/1586/1 "2015-11-09T22:58:31Z")

</div>

**[h-pan](https://sourceforge.net/u/h-pan/)** wrote on [Monday, November 09, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/45ac392d/#feae):

Hi,

I am working on project with Tick-less FreeRTOS using deep sleep low power mode of LPC4337 working on it. In Deep-sleep mode the CPU clock and peripheral clocks are shut down to save power; logic states and SRAM memory are maintained.  
Platform: LPC4337  
Compiler:LPCXpresso7.9  
FreeRTOS V8.0.1

Now I want to use Power Down mode in which all SRAM memory except for the upper 8 kB of the local SRAM located at 0x1008 0000 is maintain. In addition, Power down mode doesn’t do system reboot it resume from last instruction after wake-up.

My question is how I can reallocate Stack and heap memory in this 8kb safe memory area? What are the variable I need to save before I goto power-down mode to resume the normal functionality after wake-up (task stack, system stack other required variable to maintain RTOS kernel?

Regards,

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [November 10, 2015, 3:44am UTC](https://forums.freertos.org/t/tick-less-freertos-with-lpc4337-and-power-down-mode/1586/2 "2015-11-10T03:44:29Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Tuesday, November 10, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/45ac392d/#7560):

Hi Henna,

That is quite ambitious what you want to do!  
I never went further than “Power-save mode” and “Sleep mode”, because that is much easier: clocks remain running.

> the upper 8 kB of the local SRAM located at 0x1008 0000 is maintain[ed]

If you use ‘portable/MemMang/heap\_5.c’ it is easy to tell where to put the HEAP.

Or when using heap\_4.c you can define ‘configAPPLICATION\_ALLOCATED\_HEAP=1’ and tell the compiler where (in which sector) to put the ucHeap block.

See heap\_4.c :

```auto
    #if( configAPPLICATION_ALLOCATED_HEAP == 1 )
        /* The application writer has already defined
        the array used for the RTOS heap - probably so
        it can be placed in a special segment or address. */
        extern uint8_t ucHeap[configTOTAL_HEAP_SIZE];
    #else
        uint8_t ucHeap[configTOTAL_HEAP_SIZE];
    #endif

```

Declare the HEAP space in your code:

```auto

    __attribute__ ((aligned(8)))
    __attribute__ ((section(".sram_high")))
        uint8_t ucHeap[configTOTAL_HEAP_SIZE];
    /* '.sram_high' refers to a name defined in your xxx.ld
    you will have to edit it. */

```

Doesn’t your application need a notion of time, a continuous clock?

> reallocate Stack and heap memory

There is a temporary start-up stack that can be allocated anywhere, see your link file ‘xxx.ld’.  
After vTaskStartScheduler() is called, only FreeRTOS stacks are in use, and these stacks are located in the HEAP ( by xTaskCreate() ).

Have you also tried-out lighter ways of sleeping? Normally the tickless mode uses the system clock or a hardware timer (TC\*) to count-down. That makes it possible to use the timed blocking options of FreeRTOS.  
\*TC’s are preferable if you need long sleeps, they often have a 32-bit counter.

Some things are important for power consumption in the low-power/sleep modes :

- Low CPU frequencies consume much less power. You might consider implementing an on-demand variable CPU frequency ( in analogy with the Linux kernel ).

GPIO’s are very important:

- Make sure that inputs are never floating.

- If an input has an internal pull-up, make sure it is not tied to ground

- Same for outputs, make sure there is no current running

- Make sleeps long enough, preferably at least 30 seconds.

Some more questions:

- How many µA is your application allowed to consume while in low power?
- Does it wake-up often? How long is is allowed to remain in low power?
- What are the events that will wake-up your application?

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 13, 2015, 12:33am UTC](https://forums.freertos.org/t/tick-less-freertos-with-lpc4337-and-power-down-mode/1586/3 "2015-11-13T00:33:01Z")

</div>

**[h-pan](https://sourceforge.net/u/h-pan/)** wrote on [Friday, November 13, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/45ac392d/#b055):

Hi Hein,

Thank you for such an elaborated answer.

About questions you asked:

1. In low power mode my application is allowed to consume 100uA.
2. The sleep time is variable and it can be from 1 min to several hours.
3. I am using default implementation of tickless and Alarm timer, External trigger and RTC alarm timer as a wake up source.

As you suggest I have changed to heap\_4 earlier I was using heap\_3. I modified the linker file to allocate the 4 kB of the local SRAM starting at location 0x1008 8000 with heap size 4kB as a freertos heap memory. I confirmed the proper heap allocation by printing the stack pointer using asm instruction. (I got SP = 1x10088678, which is in the 4kB safe memory area allocated to heap).

Now after this modification I am able to go-to power down mode and wake up if any wake-up source triggers, but my application goes to hard fault once the global interrupts are enabled. I am not sure what are the variable I need to save before I go-to power-down mode.

[http://www.freertos.org/FreeRTOS\_Support\_Forum\_Archive/July\_2013/freertos\_FreeRTOS\_with\_standby\_mode\_in\_STM32\_8557400.html](http://www.freertos.org/FreeRTOS_Support_Forum_Archive/July_2013/freertos_FreeRTOS_with_standby_mode_in_STM32_8557400.html)

This thread suggests every static variables in task.c must be saved, I am doing this using \<cr\_section\_macros.h\> header file and \_\_DATA(RAM) macro to locate task.c variables in this 8kB memory area.

I am not sure why my code is going into hard-fault after enabling the global interrupt. Am I missing something? Any idea?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 13, 2015, 4:24pm UTC](https://forums.freertos.org/t/tick-less-freertos-with-lpc4337-and-power-down-mode/1586/4 "2015-11-13T16:24:26Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, November 13, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/45ac392d/#72fd):

The variables used by FreeRTOS are qualified by the macro PRIVILEGED\_DATA - although the macro is empty by default you can define it in FreeRTOSConfig.h to force the variables into a certain linker section.

Regards.

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [November 14, 2015, 9:41am UTC](https://forums.freertos.org/t/tick-less-freertos-with-lpc4337-and-power-down-mode/1586/5 "2015-11-14T09:41:36Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Saturday, November 14, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/45ac392d/#138a):

> 1. In low power mode my application is allowed to consume 100uA.

Hm that’s indeed a challenge!

> 1. The sleep time is variable and it can be from 1 min to several hours.

I asked that to know if you can just power-down the device, and save essential information in flash or eprom?

> Now after this modification I am able to go-to power down mode and wake up if  
> any wake-up source triggers, but my application goes to hard fault once the  
> global interrupts are enabled.

I would first think of the vector table, but that is declared const in flash section “.isr\_vector”, I suppose?

> This thread suggests every static variables in task.c must be saved,  
> I am doing this using \<cr\_section\_macros.h\> header file and \_\_DATA(RAM)  
> macro to locate task.c variables in this 8kB memory area.

Can your compiler produce a .SYM or .MAP file that shows all variables? And then look at all variables that are **not** saved during low-power?

Isn’t it possible to change your .LD file and **only** use the safe (saved) part of SRAM?  
Or you might also use the other RAM areas, as long as you make the access very explicit.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 16, 2015, 6:02am UTC](https://forums.freertos.org/t/tick-less-freertos-with-lpc4337-and-power-down-mode/1586/6 "2015-11-16T06:02:21Z")

</div>

**[h-pan](https://sourceforge.net/u/h-pan/)** wrote on [Monday, November 16, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/45ac392d/#72fd/c1c9):

Thanks rtel for your prompt reply.

I was already using \<cr\_section\_macros.h\> header file and \_\_DATA(RAM) macro to locate variables qualified by PRIVILEGED\_DATA in task.c in this 8kB memory area.

In addition there are some variables in port.c which has to be saved before going into power down mode.

Regards,

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 16, 2015, 11:29pm UTC](https://forums.freertos.org/t/tick-less-freertos-with-lpc4337-and-power-down-mode/1586/7 "2015-11-16T23:29:46Z")

</div>

**[h-pan](https://sourceforge.net/u/h-pan/)** wrote on [Monday, November 16, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/45ac392d/#138a/508e):

Hi Hein,

I truly appreciate your time and effort.

> I would first think of the vector table, but that is declared const in flash section “.isr\_vector”, I suppose?

Yes, Vector table is stored in flash memory.

> Can your compiler produce a .SYM or .MAP file that shows all variables? And then look at all variables that are not saved during low-power?

Yes LPCxpresso creates .map file which helped me a lot to look at the address of variables in safe and different RAM sections.

The good news is I got Tick-less FreeRTOS working with power down mode. I split the safe RAM into two areas one for storing freertos variables (2kB) and other for heap (6kB). Also, I had to modify .LD file to use safe part of SRAM.

Regards,

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [November 17, 2015, 8:35am UTC](https://forums.freertos.org/t/tick-less-freertos-with-lpc4337-and-power-down-mode/1586/8 "2015-11-17T08:35:26Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Tuesday, November 17, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/45ac392d/#f005):

Very well, thanks for notifying…

Of course it is still possible to put the other RAM area in a special section and declare variables that you can use during a wake-up session only, the contents is gone after a sleep:

```auto
__attribute__ ((section(".non_permanent_ram")))
    unsigned temporary_space[1024];

```

Regards.
