Saving Cortex-M4 processor state for power-down and resume

Saving Cortex-M4 processor state for power-down and resume

1

I'm working on a SoC that can power-off the ARM (Cortex-M4) while retaining the system RAM, and I'm interested in saving the processor state then restoring it when the ARM is restarted so that the software resumes from the point where it stopped. I'm looking for code or documentation about this process.

Prior to power-off the software would save all necessary register values to RAM, then during boot, rather than performing a regular application start-up, the software would reload the saved values. There is hardware that informs the software which is required.

The power-down will be initiated by the ARM: although I could use WFI to halt the clock, the goal is to remove power from the ARM entirely. RAM will be in a low-power state where it retains its contents. I know how to deal with peripherals outside the ARM, but I'm less familiar with ARM's internal hardware.

My goal is for the application to resume execution from the point where it stopped, with all its variables and stack retained. I know I would need to save and restore core registers, plus system control, NVIC, systick, and perhaps other things, though I'm not sure of the full list.

I'm looking for code or documentation about this process. It seems like a reasonably common task, but my searches on the arm infocenter and the wider internet found only a document related to the out-dated ARM11.

Is this already implemented on M4 - perhaps somewhere like in CMSIS, FreeRTOS, or a published example?

If not, is there documentation on how to do this on M4?

If not, would the "Cortex-M4 Technical Reference Manual" identify all the registers I need to save? Or are there more?

There are several aspects to saving the state of a system to non-volatile storage ('hibernation' in desktop parlance). Only a few are directly related to the CPU itself.

  1. Some of the volatile context of the CPU will need saving and restoring. This is the only bit that's actually ARM specific. It's very similar to how a context switch works in an OS, so that would be a good place to start looking for examples. I've written a small OS for the M4 whose context switch is 8 lines of assembly language (12 with FPU support), so it's not actually a very complex process.

    Given that you're in control of the timing of the hibernation, you won't need to save everything; but any of the registers in the ARM calling convention that are callee-preserved (r0-r3r12lr and the PSR basically) will probably need saving, along with s15-s32 if the FPU is enabled. You might get away without saving lr and the PSR if your wake-from-hibernation routine doesn't need them. You'll also probably need to store the value of the stack pointer, possibly both stack pointers (MSP and PSP) if you're using an operating system of any type. This needs privilege, which usually implies handler mode. I'd do the whole thing in SVC handlers.

  2. The contents of RAM will need saving. Flash storage is slow, so copying the whole of the RAM in and out will be time consuming and increase wear on the flash. If you're not using all of the RAM I'd consider messing with the linker to restrict the address range of the RAM that the compiled code uses. But whatever the address range, this is a fairly simple process.

  3. The hard part is the peripherals. If you have any peripherals that are dynamically reconfigured, or that might be in a state that needs precise restoration (e.g. they have data in buffers) then you'll have to handle these on a case-by-case basis. On desktop, device drivers have to be written specifically to be hibernation-aware, and the same is effectively true for you here.

Low Power概念介绍<SRPG Cell>

Low Power概念介绍<SRPG Cell>_Tao_ZT的博客-CSDN博客

今天我们要介绍的Low Power概念是SRPG Cell,全称State Retention Power Gating Cell(状态保持电源门控单元)。这是一种特殊的寄存器,对于一般的寄存器来说,如果断电以后,原有的数据就无法保存,重新连通电源以后,就会出现原有数据丢失的情况。因此,我们可以给一些必须保持数据的寄存器建立一个类似备份的设备。电源关闭前,将寄存器的数据保存到备份设备上;电源打开后,从备份设备上将数据重新写入寄存器中。

SRPG cell工作在VDD电压域,是可以关断的电压域,D、Clk、Ret和Q是寄存器的控制和输出信号。该寄存器在断电时,会有一部分电源一直有电,也就是Ret电路工作在VDD电压域,不会被关闭。当“Save”信号有效,Ret会把寄存器的值保存起来;当"Restore"有效,Ret将保存的数值写入寄存器中 。需要注意的是,一个SRPG Cell一般要比普通寄存器面积要大约20%左右。

我们来看一下UPF文件中的SRPG cell:

set_retention ret_va1 \    srpg cell的前缀

       -domain VA1 \           指定voltage area

      -retention_supply_set ss_va1_base \    指定srpg cell的supply set

      -save_condition  save_en1 \    指定srpg cell "save"信号有效的条件

      -restore_condition  restore_en1   指定srpg cell "restore"信号有效的条件

set_retention ret_va2  \

      -domain VA2\

      -retention_supply_set ss_top \

      -save_condition  save_en2 \

      -restore_condition restore_en2
————————————————
版权声明:本文为CSDN博主「Tao_ZT」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Tao_ZT/article/details/102456727

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值