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.

MSPM0L1306: MSPM0L1306: EEPROM Emulation: Linker File seems to have no reserved space

Part Number: MSPM0L1306
Other Parts Discussed in Thread: SYSCONFIG

Hi,

I'm about to use the EEPROM Emulation type A and am referring to the example `mspm0_sdk_1_30_00_03\examples\nortos\LP_MSPM0L1306\eeprom\emulation_type_a\eeprom_emulation_type_a\`.

Now in the `mspm0l1306.cmd` I would expect some reserved space for the eeprom-emulation. At least origin and size of the flash should be

   FLASH           (RX)  : origin = 0x00000800, length = 0x0000F7F8
 

instead of

   FLASH           (RX)  : origin = 0x00000000, length = 0x0000FFF8

In the case of a 2sector eeprom emulation space.

Am I missing something (which usually is the case) or is the example missing that point in the hope of application-data never exceeding 0xF7F8 ?

Also, are there restrictions as to where to put the storage space? at the beginning or the end of flash? (0x1000 as in the example seems odd to me..)

Thank you!

  • Hi Joern,

    Looking at the example, it looks like the placement of the EEPROM emulated data is left up to the compiler/linker to determine where in memory it should reside.

    If you want to force the linker to place it in a specific region, you can modify the linker script to add a section and in your code specify the use that memory for EEPROM emulated data placement.

  • Hej Dennis,

    The linker does not do any automatic placement here. How could it?:
    in eeprom_emulation_type_a.h line 71, we are setting

    #define EEPROM_EMULATION_ADDRESS                                    (0x00001000)

    then, inside the c-file, the emulation code is writing DIRECTLY into the flash by first unlocking it and then writing into it. At least two sectors get overwritten no matter what is in there. So IMHO there ought to be something in the linker file of the example to at least hint the user to take care of that.

    Lazy as I am, I expected someone here to deliver the solution on a silver plate. Since noone did, here is my idea. Please add your thoughts, any of you.

    I disabled sysconfig to generate the linker file, moved the generated one to my project-root and modified it to look like that:

    ...
    
    MEMORY
    {
        FLASH           (RX)  : origin = 0x00000000, length = 0x0000F400
        FLASH_EEPROM    (RX)  : origin = 0x0000F400, length = 0x00000800
        FLASH_REST      (RX)  : origin = 0x0000FC00, length = 0x000003F8
        SRAM            (RWX) : origin = 0x20000000, length = 0x00001000
        BCR_CONFIG      (R)   : origin = 0x41C00000, length = 0x00000080
        BSL_CONFIG      (R)   : origin = 0x41C00100, length = 0x00000080
    }
    
    SECTIONS
    {
        .intvecs:   > 0x00000000
        .text   : palign(8) {} > FLASH | FLASH_REST
        .const  : palign(8) {} > FLASH | FLASH_REST
        .cinit  : palign(8) {} > FLASH | FLASH_REST
        .pinit  : palign(8) {} > FLASH | FLASH_REST
        .rodata : palign(8) {} > FLASH | FLASH_REST
        .ARM.exidx    : palign(8) {} > FLASH
        .init_array   : palign(8) {} > FLASH
        .binit        : palign(8) {} > FLASH
        .TI.ramfunc   : load = FLASH, palign(8), run=SRAM, table(BINIT)
    
        .vtable :   > SRAM
        .args   :   > SRAM
        .data   :   > SRAM
        .bss    :   > SRAM
        .sysmem :   > SRAM
        .stack  :   > SRAM (HIGH)
    
        .BCRConfig  : {} > BCR_CONFIG
        .BSLConfig  : {} > BSL_CONFIG
    
        .eeprom_data : {} > FLASH_EEPROM, type = NOINIT
    }
    

    FLASH_EEPROM is the place where I wanted to have my eeprom storage space. Those 2k I need. There are two things to note here:

    - FLASH_EEPROM must be sector-aligned and a multiple of 0x400 (the sector size on MSPM0)

    - You must not use the very last 8bytes in flash*

    So I have that FLASH_EEPROM at 0x0000F400 and a FLASH_REST which is 0x400-8 in length.

    In the SECTIONS I have added a section named eeprom_data that gets mapped into our new FLASH_EEPROM Memory.
    The NOINIT prevents initializing the section.

    You may want to make the space explicit in the c-code by adding

    __attribute__((used, section(".eeprom_data"))) \
        volatile uint32_t eeprom_placeholder[EEPROM_EMULATION_SECTOR_ACCOUNT * 256];

    The attribute used prevents clang to optimize the variable out, section makes the placement fixed to the newly created section.
    Note that we use the ..SECTOR_ACCOUNT. This is a guard to prevent expanding the numbes of sectors without adapting the linker file.

    At last, we need to set EEPROM_EMULATION_ADDRESS to 0x0000F400.
    Unfortunately, I have no Idea on how we could link this precompiler directive with the ORIGIN set in the linker file. That would be neat.

    Please tell me what you think about this solution.
    There might even be a more elegant way..

    Thank you.

    * as the datasheet for MSPM0L1306 (SLASEX0C) states on page 38: "CPU access to one of the last 8 bytes of a flash region will cause a hard fault. This occurs because the prefetch logic tries to read one
    flash word (64 bits) ahead, resulting in a read attempt to an invalid memory location."