Question about recovery from VLLS3

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

Question about recovery from VLLS3

Jump to solution
1,084 Views
gauravbanyal
Contributor IV

Probably a lame question:

In MKL03 since the RAM is retained in VLLS3 mode, when the wake-up happens, can I skip the entire initialization sequence and treat it as if the while{} loop inside my main() just started running again and everything else remained as is?

If this is not the case, some explanation of what to expect would be much helpful.

Thanks much!

Labels (1)
Tags (1)
1 Solution
661 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Gaurav Banyal,

In MDK, there also has another way, just define the variable which don't do initialization after reset:

char mycode __attribute__((section("NO_INIT"),zero_init)); 

Wish it helps you!
Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

8 Replies
662 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Gaurav Banyal,

In MDK, there also has another way, just define the variable which don't do initialization after reset:

char mycode __attribute__((section("NO_INIT"),zero_init)); 

Wish it helps you!
Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

661 Views
gauravbanyal
Contributor IV

Hello Kerry,

(URGENT HEP NEEDED)

Here I have a new problem. I have now 2 applications that sit on the MCU flash. One is a custom bootloader (that sits at address zero in the program memory and at some point the execution jumps from the bootloader to the application firmware that sits in the higher area of program memory (flash).

The applicaton firmware is using this NO_INIT region (because its defined in its scatter file). When the execution jumps from the bootloader to the application, perhaps this NO_INIT area in the RAM is not available as the bootloader scatter file does not have it defined.

I tried to define it in the bootloader scatter file but I think it won't work like that. Following are the snippets from  the .map files of :

Application firmware

======================

Execution Region MYRAM (Base: 0x20000500, Size: 0x00000054, Max: 0x00000100, ABSOLUTE, UNINIT)

Base Addr Size Type Attr Idx E Section Name Object

0x20000500 0x00000001 Zero RW 77 NO_INIT invisibles_sys.o
0x20000501 0x00000003 PAD
0x20000504 0x0000004c Zero RW 417 NO_INIT sessionmanager.o
0x20000550 0x00000002 Zero RW 1019 NO_INIT clock_calibration.o

======================

Bootloader firmware

======================

Execution Region MYRAM (Base: 0x20000500, Size: 0x00000050, Max: 0x00000100, ABSOLUTE, UNINIT)

Base Addr Size Type Attr Idx E Section Name Object

0x20000500 0x00000002 Zero RW 315 NO_INIT clock_calibration.o
0x20000502 0x00000001 Zero RW 329 NO_INIT invisibles_sys.o
0x20000503 0x00000001 PAD
0x20000504 0x0000004c Zero RW 343 NO_INIT sessionmanager.o

======================

 

How do I make this work?

Best regards,

Gaurav.

0 Kudos
661 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Gaurav,

   For the new question, could you please create a new post?

  Thank you!

Best Regards,

Kerry

0 Kudos
661 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Gaurav Banyal,

    KL03 VLLS3 mode wake up will cause the system reset.

    The SRAM is retained down to VLLS3 mode, if you want to skip the entire initialization sequence, after the mcu reset, you can check the system reset status register 0(RCM_SRS0), if RCM_SRS0[WAKEUP] is 1, skip the according Copy RAM code, then your RAM data will be remained.

Wish it helps you!

Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
660 Views
gauravbanyal
Contributor IV

Hello Kerry Zhou,

what do you mean by "skip the according Copy RAM code"? how exactly is this done?

0 Kudos
661 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Gaurav Banyal,

     It determined by your code.

     Check the start flow in your code, did you do the copy data and bss section in the FLASH to RAM after reset?

     Take an example, this is the startup code from KL25 sample code:

pastedImage_1.png

    This bss, data init in the flash will reset the RAM code after reset, if you wake up from VLLS3, and don't want to change the RAM data, you can don't do this copy by judge the RCM_SRS0[WAKEUP] bit.

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
661 Views
gauravbanyal
Contributor IV

Hi Kerry Zhou,

I am not doing any copy to RAM explicitly in my code. An good reference is the example SDK_2.0_FRDM-KL03Z\boards\frdmkl03z\demo_apps\power_mode_switch. Its almost identical to the application I am writing.

In this example what I want to do is:

1. Create a variable in the global scope and assign it to some value (Run state).

2.  Enter VLLS3 state.

3. Exit the VLLS3 state by pressing SW2 and print the value of that variable. I expect it to hold the same value as was assigned in step 1.

In my experiment this does not happen. Please help me how I can make this happen.

My entire application architecture is based on the assumption that the values contained in the data structures I defined in my code will be in-tact when I exit the VLLS3 state to RUN sate.

Thanks much.

0 Kudos
661 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Gaurav Banyal,

    Ok, I also have test it on the SDK_2.0_FRDM-KL03Z\boards\frdmkl03z\demo_apps\power_mode_switch code, you need do some modifications.

   Now, let's take the MDK project as an example.

  Modification points:

 1. define the determined SRAM area for your according variable in the .scatter file like this:

#define m_data_size                    (0x00000700 - m_interrupts_ram_size) /*0x00000800*/

LR_m_text m_interrupts_start m_text_start+m_text_size-m_interrupts_start { ; load region size_region
  VECTOR_ROM m_interrupts_start m_interrupts_size { ; load address = execution address
    * (RESET,+FIRST)
  }
  ER_m_flash_config m_flash_config_start FIXED m_flash_config_size { ; load address = execution address
    * (FlashConfig)
  }
  ER_m_text m_text_start m_text_size { ; load address = execution address
    * (InRoot$Sections)
    .ANY (+RO)
  }

#if (defined(__ram_vector_table__))
  VECTOR_RAM m_interrupts_ram_start EMPTY m_interrupts_ram_size {
  }
#else
  VECTOR_RAM m_interrupts_start EMPTY 0 {
  }
#endif
  RW_m_data m_data_start m_data_size-Stack_Size-Heap_Size { ; RW data
    .ANY (+RW +ZI)
  }
  ARM_LIB_HEAP +0 EMPTY Heap_Size {    ; Heap region growing up
  }
  ARM_LIB_STACK m_data_start+m_data_size EMPTY -Stack_Size { ; Stack region growing down
  }
  MYRAM 0x20000500 UNINIT 0x00000100{
  .ANY (NO_INIT)
  }
}

Define the sram address 0x2000500, the leghth is 0X100 as the your own ram, and don't initialize it after reset.

This step is very important.

2. define a variable in the range of mysram

char mycode __attribute__((at(0x20000500)));

After the above 2 steps, after you modify the mycode data, and enter VLLS3, then wake up by SW2 button, you will find the data retains.

in my example, before enter vlls3, I set mycode to 0x55, I have attached my code, in power_mode_switch.c line 297.

After test, I read mycode, it turns out 0x55.

So, the data really retains.

I also attached the scatter file for your reference.

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------