Crash after powerdown if ram is not powered

sdk: 2.5.1

cpu: nrf5340

I have a bootloader which have a big ram block for upgrade purpose (around 250kb) in bss section (I will move it in noinit, but it is not the point here).

I  have an app, that poweroff unused ram with VMC register.

Sometimes, the app will enter in poweroff (using REGULATORS register), and will be awakened by vbus or nfc.

When the cpu is awakened, the bss section and idle stacks are in a part of the ram that is powered off, and this is a unrecoverable crash.

I found a solution with powering ram at early startup, but I would like to check with you if it is correct.

The solution may also be about powering up ram before entering poweroff, but I would like may bootloader to be robust.

I wrapped the method z_arm_reset (with linker argument --wrap), and wrote this method:

I checked the generated code, and no stack seem to be used:

Waiting for your answer.

Regards,

Parents
  • Hi, the following example code will configure the RAM blocks to behave as you describe:

    I created the following zephyr test application (modified main.c and prj.conf of the hello_world sample)

    Hopefully we can compare solutions to figure out why it is failing for you :)

  • I think I did not explained the problem correctly.

    At wakeup, the ram of the main stack inside the bootloader was turned off by the app because the main stack of the bootloader is in a part of ram unused for the app. When the reset function of the bootloader is called at wakeup, there is an exception immediately as the stack is used. The main method will never been executed. The purpose of my code was to turn ram on inside the bootloader before any use of ram.

  • Could you expand on what you mean by "main stack of the bootloader" and "reset function of the bootloader"? Maybe a diagram of your memory layout could help as well, where is your bootloader and app placed in ROM, and which RAM areas do they use?

Reply
  • Could you expand on what you mean by "main stack of the bootloader" and "reset function of the bootloader"? Maybe a diagram of your memory layout could help as well, where is your bootloader and app placed in ROM, and which RAM areas do they use?

Children
  • The reset function is the function called when the device start.

    Its implementation is in zephyr/arch/arm/core/aarch32/cortex_m\reset.S

    Its address is store in the vector table at addresse 0.

    By main stack I mean the main stack pointer registry (MSP).

  • OK, either your bootloader or application is must configure the behavior of the VMC before entering poweroff.

    The VMC automatically powers on/off sections of the RAM blocks depending on the system power state. You can configure two options for each section of each RAM block:

    1. Should this section be powered when the system is ON.

    2. Should this section be retained (powered) when the system is OFF.

    By default, after a "real" reset (using the reset pin or power reset), all RAM blocks will be powered when the system is ON, and not powered when the system is OFF.

    The behavior you are describing I have only been able to recreate by configuring the VMC to disable RAM sections in system ON which are in use by your bootloader/app, by doing the following:

    This will cause a crash when you reboot unless you manage to manually power the RAM sections again before accessing them, which seems to be what you are doing with
    How are you disabling power to the RAM blocks in power off would be my next question if the above is not accurate to your case :)
  • I power down ram inside app, at startup using power_up_unused_ram in nrf\include\ram_pwrdn.h.

    The ram power status is then not modified anymore.

    The app is a sample app with very low ram usage, so a lot of ram is powered down.

    The bootloader as a big ram buffer in bss section (that I will move in uninit, but it is not the point here). This buffer is before stacks that are in noinit sections. So the stacks are in positions that are powered off by app.

  • Ah, now I think I understand your setup. This is how I would solve your problem:

    The bootloader and application will share a "small" section of RAM, which will be configured to always follow the system state, powered when the system is ON, not powered when the system is OFF. I would make this explicit in the devicetree like this:

    The common_sram section is the RAM containing .bss, .no_init etc. shared by the application and bootloader. This section will never be powered down while the system is ON. The section bank_sram will be used exclusively for the RAM bank.

    Your bootloader will need to power this bank manually before using the memory, you can get the address and size of your memory section from the devicetree

     

    Which you can then pass to power_up_ram() and power_down_ram() before and after using the RAM bank. From you application, simply call power_down_unused_ram() if you don't intend to power down the bank_sram RAM from the bootloader before entering the application.

  • I can’t make myself understood.

    As the ram is powered down, the bootloader crash very very early. Far before init of the kernel. Inside the reset part, just when the MPS is needed.