Retain RAM data during reset on MKW38

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Retain RAM data during reset on MKW38

849 Views
xiaofenglei
Contributor II

Hello,

I'm working on MKW38 chipset, and want to keep some data in ram instead of flash when the device resets from application to bootloader side. Maybe I missed something in spec, I didn't find some special RAM related to this, and also the description about how to perform a WARM reset which is occasionally mentioned in TRM. Would you please point a way for such purpose through RAM or registers to pass some data from application to bootloader?

Thanks,

Xiaofeng

0 Kudos
Reply
3 Replies

543 Views
paulM90
Contributor II

Ill answer here, in case somebody else bumps into this.

First, find in your reference manual a region of SRAM that remains power through a reset. In my case (mx rt 595), thats SRAM partition 0.

paulM90_0-1686838893949.png

It's address range is: 

paulM90_1-1686838994102.png

 

First up, modify your linker script.

1. Add a memory region. In our case, m_persistent. I placed it at the beginning of the above-mentioned partition.

MEMORY
{
  m_flash               (RX)  : ORIGIN = 0x08000000, LENGTH = 0x00300000
  m_interrupts          (RX)  : ORIGIN = 0x00080000, LENGTH = 0x00000180
  m_persistent          (RW)  : ORIGIN = 0x20000000, LENGTH = 0x1000
  m_text                (RX)  : ORIGIN = 0x00080180, LENGTH = 0x7FE80
  m_data                (RW)  : ORIGIN = 0x200C0000, LENGTH = 0x400000
  m_usb_sram            (RW)  : ORIGIN = 0x40140000, LENGTH = 0x00004000
}

 

2. Add a section in the memory region.

SECTIONS
{
  ...

  .persistent_data (NOLOAD) :
  {
    . = ALIGN(4);
    __persistent_data_start__ = .;
    KEEP(*(.persistent_data))
    KEEP(*(.persistent_data*))
    . = ALIGN(4);
    __persistent_data_end__ = .;
  } > m_persistent
  
  ...
}

 

And place your variables in the newly created section. Here's a quick code to test the functionality. It should print the value, increment it, and reset after 3 seconds.

__attribute__((section(".persistent_data"))) int persistent_var;

int main(void)
{
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();


    SDK_DelayAtLeastUs(1000*2500, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
    printf("Hello World %u\n", persistent_var.PersistentValue++);
    NVIC_SystemReset();
}

 

Sample output:

paulM90_2-1686839268508.png

 

0 Kudos
Reply

835 Views
xiaofenglei
Contributor II

I tried to reset with watchdog which should be usually regarded as WARM reset, but looks like the ram data is still lost during reboot.

0 Kudos
Reply

830 Views
xiaofenglei
Contributor II

It's my bad, and the memory can retain content with watchdog. I will use this way.

0 Kudos
Reply