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.

CC2340R5: Saving 16 byte data in RAM that survives a reboot

Part Number: CC2340R5

Hi everyone,

I need to store some data (basically a super simple crash report) in RAM, that I can pick up on the following restart that the watchdog reset will cause.

Normally, I have done this many times with gcc tools (linkfile), but now I am struggling a bit with CCS and ticlang. Are there any examples or suggestions how to do this?

Thanks,

 Micael

  • Hi Micael,

    May I kindly ask what options you have explored so far?

    For example, may I ask if you have considered using a "NOINIT" section as described here? https://software-dl.ti.com/codegen/docs/tiarmclang/compiler_tools_user_guide/compiler_manual/linker_description/05_linker_command_files/special-section-types-dsect-copy-noload-and-noinit-stdz0756718.html

    Best regards,

  • Hi Clément,

    Well, I took some time to test this now as well (been testing so many ways now, that I wasn't sure if I had).

    So I did like this;

    In cc23x0_app_freertos.cmd, I added a line in SECTIONS (after .bootcause)

    .noinit         :   > SRAM, type = NOINIT

    then I declared my variable like this;

    __attribute__((noinit)) int reboot_test;

    If I then build, I get an warning saying

    "warning #10247-D: creating output section ".TI.noinit" without a SECTIONS specification"

    ..and it looks like the variable is put in a memory that is zeroed out, since I always get zero on each reboot. (I reboot by pressing the "Device Reset" button in CCS).

    So, just for fun, I changed the SECTIONS row into

    .TI.noinit         :   > SRAM, type = NOINIT

    Now I don't get any warning, but still, the variable is initialized into zero.

    (Out of curiosity, what is the section .bootcause? Sound useful, but I could not find any references to it.)

  • .. and I forgot, in the map file, with .TI.noinit, it looks like this;

    SEGMENT ALLOCATION MAP
    
    run origin  load origin   length   init length attrs members
    ----------  ----------- ---------- ----------- ----- -------
    00000000    00000000    0002ab34   0002ab34    r-x
      00000000    00000000    0000008c   0000008c    r-- .resetVecs
      00000090    00000090    0002aaa4   0002aaa4    r-x .text
    0002ab40    0002ab40    00006bbc   00006bbc    r--
      0002ab40    0002ab40    00006644   00006644    r-- .rodata
      00031184    00031184    00000578   00000578    r-- .cinit
    0007a000    0007a000    00001800   00000000    rw-
      0007a000    0007a000    00001800   00000000    rw- .TI.bound:flashBuf1
    0007c000    0007c000    00004000   00000000    rw-
      0007c000    0007c000    00004000   00000000    rw- .TI.bound:flashBuf0
    2000008c    2000008c    00000010   00000000    rw-
      2000008c    2000008c    00000010   00000000    rw- .TI.noinit
    20000400    20000400    00000010   00000000    rw-
      20000400    20000400    00000010   00000000    rw- .TI.bound:dmaChannel0ControlTableEntry
    20000410    20000410    00000010   00000000    rw-
      20000410    20000410    00000010   00000000    rw- .TI.bound:dmaChannel1ControlTableEntry
    20000420    20000420    00000010   00000000    rw-
      20000420    20000420    00000010   00000000    rw- .TI.bound:dmaChannel2ControlTableEntry
    20000430    20000430    00000010   00000000    rw-
      20000430    20000430    00000010   00000000    rw- .TI.bound:dmaChannel3ControlTableEntry
    20000440    20000440    00000010   00000000    rw-
      20000440    20000440    00000010   00000000    rw- .TI.bound:dmaChannel4ControlTableEntry
    20000450    20000450    00000010   00000000    rw-
      20000450    20000450    00000010   00000000    rw- .TI.bound:dmaChannel5ControlTableEntry
    20000480    20000480    00000010   00000000    rw-
      20000480    20000480    00000010   00000000    rw- .TI.bound:dmaChannel0AltControlTableEntry
    20000490    20000490    0000841d   00000000    rw-
      20000490    20000490    00000010   00000000    rw- .TI.bound:dmaChannel1AltControlTableEntry
      200004a0    200004a0    00007546   00000000    rw- .bss
      200079e8    200079e8    00000ec5   00000000    rw- .data
    20008ce0    20008ce0    00000320   00000000    rw-
      20008ce0    20008ce0    00000320   00000000    rw- .stack
    4e020000    4e020000    00000800   00000800    r--
      4e020000    4e020000    00000800   00000800    r-- .ccfg
    
    
    SECTION ALLOCATION MAP
    
     output                                  attributes/
    section   page    origin      length       input sections
    --------  ----  ----------  ----------   ----------------
    .resetVecs 
    *          0    00000000    0000008c     
                      00000000    0000008c     ti_freertos_config.o (.resetVecs)
    
    .cinit     0    00031184    00000578     
                      00031184    000004d1     (.cinit..data.load) [load image, compression = lzss]
                      00031655    00000003     --HOLE-- [fill = 0]
                      00031658    0000000c     (__TI_handler_table)
                      00031664    00000008     (.cinit..TI.bound:dmaChannel0AltControlTableEntry.load) [load image, compression = zero_init]
                      0003166c    00000008     (.cinit..TI.bound:dmaChannel0ControlTableEntry.load) [load image, compression = zero_init]
                      00031674    00000008     (.cinit..TI.bound:dmaChannel1AltControlTableEntry.load) [load image, compression = zero_init]
                      0003167c    00000008     (.cinit..TI.bound:dmaChannel1ControlTableEntry.load) [load image, compression = zero_init]
                      00031684    00000008     (.cinit..TI.bound:dmaChannel2ControlTableEntry.load) [load image, compression = zero_init]
                      0003168c    00000008     (.cinit..TI.bound:dmaChannel3ControlTableEntry.load) [load image, compression = zero_init]
                      00031694    00000008     (.cinit..TI.bound:dmaChannel4ControlTableEntry.load) [load image, compression = zero_init]
                      0003169c    00000008     (.cinit..TI.bound:dmaChannel5ControlTableEntry.load) [load image, compression = zero_init]
                      000316a4    00000008     (.cinit..bss.load) [load image, compression = zero_init]
                      000316ac    00000050     (__TI_cinit_table)
    
    .init_array 
    *          0    00000000    00000000     UNINITIALIZED
    
    .TI.bound:flashBuf1 
    *          0    0007a000    00001800     UNINITIALIZED
                      0007a000    00001800     ti_drivers_config.o (.TI.bound:flashBuf1)
    
    .TI.bound:flashBuf0 
    *          0    0007c000    00004000     UNINITIALIZED
                      0007c000    00004000     ti_drivers_config.o (.TI.bound:flashBuf0)
    
    .ramVecs   0    20000000    0000008c     NOLOAD SECTION
                      20000000    0000008c     driverlib.a : interrupt.c.obj (.ramVecs)
    
    .ccfg      0    4e020000    00000800     
                      4e020000    00000800     ti_devices_config.o (.ccfg)
    
    .TI.noinit 
    *          0    2000008c    00000010     UNINITIALIZED
                      2000008c    00000010     event_log.o (.TI.noinit)
    
    .bss       0    200004a0    00007546     UNINITIALIZED
                      200004a0    00003fff     ti_freertos_config.o (.bss.ucHeap)
                      2000449f    00001000     (.common:flash_temp_store)
                      2000549f    00000001     bleapputil_init.o (.bss.BLEAppUtilSelfEntity)

  • Hi Micael,

    Allow me a couple days to run this by the compiler team.

    We will comeback to you in a few days.

    Best regards,

  • Hi Micael,

    I wanted to update on the progress regarding your query.

    The relevant compiler documentation turned to be the one about the variable attribute noinit https://software-dl.ti.com/codegen/docs/tiarmclang/compiler_tools_user_guide/compiler_manual/c_cpp_language_implementation/attributes/variable_attributes.html#noinit

    In order to prevent the initialization of a variable,

    • The variable should be allocated in the section .TI.noinit
    • No entry should be made for this variable in the tables in .cinit section.  Which means the startup code does not touch it.

    Here, all of that is already happening, yet these variables still get initialized to 0. That must be caused by some other system configuration step that is wrong or missing.  

    I am working with other teams to understand this further.

    Appreciate your patience.

    Best regards,

  • Hi Clément, thank you for looking into this.

    Could it be that a reset from the debugger somehow is doing something behind the scenes? So maybe, "out in the wild" this code will work?

     - Micael

  • Hi Micael,

    [Clement has edited his message]

    Based on my tests, it looks like the debugger forces the memory to 0.

    When freely running, it looks like the variable is not initialized. I'll let you check this, for example by connecting the debugger to a running target (see here).

    Regards,

  • Hi Clément,

    This is so strange, the forum gives me two versions of your reply, when I reload the page. 

    But guess it is working running freely is the last edit, if not, holler.

    I will mark it as resolved, thanks for looking into this!

     - Micael

  • Hi Micael,

    I have an additional piece of information for you that comes confirm our observations.

    As stated in table 8-1 in the CC23xx SimpleLink Wireless MCU Technical Reference Manual, SRAM is not normally erased during boot. The contents of SRAM can remain across boots except for the range 0x20000000-0x20000447, which is modified during normal boot. If SACI [i.e. debug mode] is entered during boot the entire SRAM is cleared.

    I hope this will clear any final doubt (if any) :)

    Kind regards,