This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Does RAM need to be re-powered before soft reset?

Hello -

We are developing a product for the nRF52840 using SDK v17.0.2 and FreeRTOS. Our application uses the RTC configured by FreeRTOS to implement a System ON sleep wake on timer feature. The SoftDevice is not enabled. The feature works well, though I have a question related to RAM power. Here is the code:

	// Power off all ram sections except for retention memory (slave 2, section 0)
	NRF_POWER->RAM[0].POWERCLR = 0x03;
	NRF_POWER->RAM[1].POWERCLR = 0x03;
	NRF_POWER->RAM[2].POWERCLR = 0x02;
	NRF_POWER->RAM[3].POWERCLR = 0x03;
	NRF_POWER->RAM[4].POWERCLR = 0x03;
	NRF_POWER->RAM[5].POWERCLR = 0x03;
	NRF_POWER->RAM[6].POWERCLR = 0x03;
	NRF_POWER->RAM[7].POWERCLR = 0x03;
	NRF_POWER->RAM[8].POWERCLR = 0x3F;

	// Wait for RTC compare interrupt event
	do {
		__WFE();
	} while (!nrf_rtc_event_pending(portNRF_RTC_REG, NRF_RTC_EVENT_COMPARE_0));

	// Power on all RAM (seems to be required in order for reset to work)
	NRF_POWER->RAM[0].POWERSET = 0x03;
	NRF_POWER->RAM[1].POWERSET = 0x03;
	NRF_POWER->RAM[2].POWERSET = 0x02;
	NRF_POWER->RAM[3].POWERSET = 0x03;
	NRF_POWER->RAM[4].POWERSET = 0x03;
	NRF_POWER->RAM[5].POWERSET = 0x03;
	NRF_POWER->RAM[6].POWERSET = 0x03;
	NRF_POWER->RAM[7].POWERSET = 0x03;
	NRF_POWER->RAM[8].POWERSET = 0x3F;

	// Reset device
	NVIC_SystemReset();

We power off all RAM except for one section before waiting for the RTC event. After the RTC event we power RAM back on and perform a soft reset. We have found that our application does not successfully re-launch after the soft reset unless we power the RAM back before the soft reset. I haven't found any documentation on whether or not the RAM power state (on or off) is maintained across soft reset after exiting System ON sleep mode. Our theory is that we must power RAM back on in order for the boot loader to function properly after the reset. Is this true and is the current RAM power state maintained across soft reset?

Regards,

Brian

  • Hi Brian

    The reset chapter in the nRF52840 Product Specification shows an overview of what is retained or reset during different types of reset (soft reset, pin reset, power reset etc). 

    As you can see the peripherals are reset, which means that all non retained peripheral registers will also be reset to their default values, but the RAM will remain if RAM retention is enabled. 

    It is odd that enabling RAM retention is necessary for your application to boot. Have you done any debugging to see if you can spot where in the startup sequence the code fails?

    What kind of bootloader architecture are you using?

    Best regards
    Torbjørn

  • Torbjørn -

    Thank you for the quick follow-up and tips about the reset information in the Product Specification. I found a useful table in section 5.3.6.8 Reset behavior. In that table, I see that RAM is not a reset target for Soft reset. Does that mean that if we power off RAM slaves before the soft reset, by setting the associated bits in the POWERCLR register, the RAM slaves will remain powered off after the soft reset? If that is the case, then that would explain why we need to explicitly power RAM back on before the soft reset. Neither the app nor boot loader can function with no RAM. :-)

    Note that we are only leaving power on one section before waiting for the RTC event.

    	NRF_POWER->RAM[2].POWERCLR = 0x02;
    

    The rest of the RAM is powered off and hence not retained I believe before the soft reset.

    We are using the Adafruit nRF52 boot loader.

    Regards,

    Brian

  • Hi Brian

    When the CPU is running the RAM is always enabled, the RAM POWER registers only determine whether or not the RAM is active when the system is in sleep mode. 

    This is probably made a bit confusing by the fact that the two sleep modes in the devices are called "System OFF" and "System ON" respectively. System ON really means System ON Idle, which is a mode where the CPU is sleeping, but various regulators and clocks are kept running to ensure that you can wakeup the CPU very fast to process events and interrupts. 

    So there is no way to disable the RAM in active mode, in this mode the entire RAM will always be running. 

    It is possible that the Adafruit bootloader stores something in RAM that it relies on upon reset. 

    The Nordic DFU solution should not require this. 

    Best regards
    Torbjørn

Related