This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSPM0G3507: How to allows a variable to be not zero-initialized at startup or reset

Part Number: MSPM0G3507

Tool/software:

When I use the "persistent  attributeon MSPM0G3507, I see that the variable is allocated in the SRAM and is re-initialized to 0 at RESET or startup:

I want to know if there is any method on the MSPM0G that allows a variable to be not zero-initialized at startup or reset, similar to the persistent attribute works on the MSP430FR.

Thanks and Regards,

SON.

  • Hi SON,

    Below is the method what I used to work with:

    -----------------------------------------------------------------------

    You can add a new memory in cmd file:

    SRAM_NOINIT (RWX) : origin = 0x20200000, length = 0x00000200

    -----------------------------------------------------------------------

    Then, you can add a new section in cmd file:

    .NoInitSection : > SRAM_NON_INIT TYPE=NOINIT

    -----------------------------------------------------------------------

    After that, you can set the variable in this new section:

    __attribute__((section (".NoInitSection"))) int32_t test = 0;

    -----------------------------------------------------------------------

    As for persistent, the detail clarification you can find it in TI CLANG user guide:

    https://software-dl.ti.com/codegen/docs/tiarmclang/compiler_tools_user_guide/ 

    So it will aslo be initialized once the application is loaded. While it should non-initialized again during the reset.

    I see the compiler warning if I use __attribute__((persistent)):

    Please manually add this sections in cmd file and take another try.

    B.R.

    Sal

  • Thank you very much!
    I followed your instructions:
            

    and the variable in SRAM is only not reinitialized upon a level 0 reset  as described in the table: 

    DL_SYSCTL_resetDevice(0);

    -----------------------------------------------------------------------

    However, when I perform a hardware reset or other reset levels, the variable still gets reinitialized. 

    Did I do it correctly, or is there a way to prevent the variable  re-initializing with any reset (besides storing it in FLASH by DL function, as that consumes time and resources)?

  • Hi Goku,

    From my perspective, if you ask the variable not initialzed, this means you want to maintain the data.

    However, when I perform a hardware reset or other reset levels, the variable still gets reinitialized. 

    It requires a certain value when you fisrt tun the application. Or it will be a random value, which is not meaningful for your application.

    Maybe you can take a look into "c_int00" assembly code, I am not sure whether there is a method here to make it un-initialzed within BOR.

    Did I do it correctly, or is there a way to prevent the variable  re-initializing with any reset

    There does have 4bytes within MSPM0 device, which can maintained in BOR reset, which means it will not be initialized.

    For POR reset, I do think there any way to keep the varible maintained except the FLASH.

    B.R.

    Sal

  • Thank you very much Sal,
    In my project, I need a variable called 'volume_counter' to be continuously assigned the measured value from a sensor every second (for example, water usage).

    I cannot keep erasing and writing to FLASH and then reading it repeatedly for this variable because it is time-consuming and the number of FLASH write cycles is limited 1000000 times. Even worse, if the MCU resets before I can write to FLASH, the measurement could become inaccurate.

    Do you have any recommendations for the most suitable solution for this project?

    Thank you very much!

  • Hi Goku,

    Considering the POR reset, it requires a EEPROM solution here.

    It can maintain the data, and even if the reset happen in the FLASH writing, there will be maintain the last writing value as the correct one.

    You can find the implement demo project in SDK, and we provide the documents in the TI.com.

    it is time-consuming

    Writing flash is quick. Only concern is the erase operation when manage the flash address. 

    the number of FLASH write cycles is limited 1000000 times.

    When use EEPROM, the equivalent endurance will be increased to 1M times, or even higher (use more flash memory will increase it).

    B.R.

    Sal

  • Have a nice day Sal!
    I will try to save the variable using the EEPROM emulation type B design next.
    I will also continue to study the documentation more carefully and believe I can find a suitable solution.
    However, I still have two final concerns:

    1. When SRAM always has power (via a pin), it should behave almost like non-volatile memory. So why can't maintain the last value after a reset? The MSP430FR can do this (I have already tested saving a variable in the RAM in an OTA project). Is that correct?

    2. Another MCU, the STM32L151C8T, has a similar memory architecture but can easily achieve this by slightly modifying the SRAM configuration in the linker.

      Do you have any thoughts on these two issues?"

  • Hi Goku,

    When SRAM always has power (via a pin), it should behave almost like non-volatile memory. So why can't maintain the last value after a reset?

    Yes you are correct.

    Let me do some investigation on this topic.

    Another MCU, the STM32L151C8T, has a similar memory architecture but can easily achieve this by slightly modifying the SRAM configuration in the linker

    I am not familiar with this part. Do you have any reference how you modify the SRAM Linker?

    B.R.

    Sal

  • Have a nice day Sal,

    - I have thoroughly reviewed the documentation regarding the operation of various reset levels and the PMCU, and I have determined that Vcore is the power supply for the device memory. 
    - Therefore, any reset types that cause 'VCORE to be power cycled' will result in the SRAM losing its values and requiring reinitialization.
    * Do you know whether the "VCORE is power cycled" state is controlled by software (SW) when reset, or if it is automatically executed by hardware upon detecting a change in a specific bit? Furthermore, if it is software-controlled, would it be possible to modify the corresponding ISR reset?
    Best Regards,
     Son



  • Hi Son,

    if it is automatically executed by hardware upon detecting a change in a specific bit?

    No, it is hardware controlled. And I suppose this will be closed only in the VDD lost, or entry shuntdown mode.

    From my perspective, manually trigger POR/BOR usually will not reset Vcore, Vcore will be maintain exclude the VDD loss.

    B.R.

    Sal

  • Thanks Sal,

    - According to this table, I noticed that any reset causes corresponding to a reset level that results in the SRAM being marked with 'R' also affects Vcore and causes Vcore is power cycled (as mentioned in the documentation)

    - And since Vcore is affected, I believe that no matter how the variable is allocated, as long as it resides within the SRAM region, it will be reset and lost value.

    Do you agree with me?

    Best Regards.

    Son

  • Hi Son,

    Yes, I agree with you. I miss this information in TRM.

    While, only one things is that, the Vcore might not power cycles, only the PMU module is power cycled.

    And yes, all SRAM content will not maintianed due to this.

    B.R.

    Sal

  • Thank you very much Sal,

    While, only one things is that, the Vcore might not power cycles, only the PMU module is power cycled.

    I will review the TRM documentation again and base on the table provided to determine the most suitable method for the project!

    Thank you very much for your assistance in this topic for me!!

    Best Regards.

    Son

     

  • Hi Son,

    Thanks for feedback. I will close the thread, and feel free to file a new one if there has further questions.

    B.R.

    Sal