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: Using #pragma and section data for MSPM0

Part Number: MSPM0G3507

Tool/software:

I'm trying too section off some section of Flash specifically for some constants with the MSPM0G3507 and TI Clang compiler.

I have the following lines of code:

#pragma clang section data=".CRC"
uint32_t crc_start_addr = FLASH_ORIGIN_CRC;
uint32_t crc_length = FLASH_LENGTH_CRC;
uint32_t crc_crc = 0;
uint16_t crc_version = 0x1234;
uint16_t crc_part_number = 0x5678;
#pragma clang section data=""

Then in the linker, I have:

MEMORY

{

FLASH (RX) : origin = 0x00000000, length = 0x0001FFF0
FLASH_CRC (RX) : origin = 0x0001FFF0, length = 0x00000010
SRAM (RWX) : origin = 0x20200000, length = 0x00008000

...

}

SECTIONS

{

...

.CRC : > FLASH_CRC

...

}

I see the variables in the right place in memory, but I do not see them with the correct initial values. All the bits are just 1s.

  • Hi Tomas,

    Please check the TI ARM CLANG compiler user guide: https://software-dl.ti.com/codegen/docs/tiarmclang/compiler_tools_user_guide/ 

    We ues the attribute instead.

    B.R.

    Sal

  • I tried that with the following lines instead of #pragma:

    uint32_t crc_start_addr __attribute__((section(".CRC"))) = FLASH_ORIGIN_CRC;
    uint32_t crc_length __attribute__((section(".CRC"))) = FLASH_LENGTH_CRC;
    uint32_t crc_crc __attribute__((section(".CRC"))) = 0;
    uint16_t crc_version __attribute__((section(".CRC"))) = 0x1234;
    uint16_t crc_part_number __attribute__((section(".CRC"))) = 0x5678;

    also tried:

    const uint32_t crc_start_addr __attribute__((section(".CRC"))) = FLASH_ORIGIN_CRC;
    const uint32_t crc_length __attribute__((section(".CRC"))) = FLASH_LENGTH_CRC;
    const uint32_t crc_crc __attribute__((section(".CRC"))) = 0;
    const uint16_t crc_version __attribute__((section(".CRC"))) = 0x1234;
    const uint16_t crc_part_number __attribute__((section(".CRC"))) = 0x5678;

    In the first case, I see the variables initialized at the correct memory space, they just don't have the correct values.

    In the second case, they were not initialized at the correct memory space, and also did not have the correct values. 

    I got this from the following example at this link: 

    int my_var __attribute__((section("my_sect"))) = 5;

    https://software-dl.ti.com/codegen/docs/tiarmclang/compiler_tools_user_guide/compiler_manual/c_cpp_language_implementation/attributes/attribute_syntax.html 

  • Hi Tomas,

    I see you put the CRC section into FLASH address, then it requires const property additionally.

    const uint32_t crc_start_addr __attribute__((section(".CRC"))) = FLASH_ORIGIN_CRC;

    This one is correct if the variable requries store in flash area.

    What issues here?

    B.R.

    Sal

  • The issue with "const uint32_t crc_start_addr __attribute__((section(".CRC"))) = FLASH_ORIGIN_CRC;" is that it is not allocating the variables to the correct place in memory, or with the right value. In my linker file, I have:

    MEMORY

    {

    FLASH (RX) : origin = 0x00000000, length = 0x0001FFF0
    FLASH_CRC (RX) : origin = 0x0001FFF0, length = 0x00000010
    SRAM (RWX) : origin = 0x20200000, length = 0x00008000

    ...

    }

    SECTIONS

    {

    ...

    .CRC : > FLASH_CRC

    ...

    }

    That should mean that the variables crc_start_addr, crc_length, etc. are placed between 0x0001 FFF0 and 0x0002 0000. Looking at the debugger's memory browser and expressions window, they are not:

  • Hi Tomas,

    I think it related to that the crc_start_addr is not called in code and compiler optimize it. Add additional attribute of "used" for the variable and check. You can find it also in the user guide.

    By the way, the screenshot you shared below looks like incorrect, normally the 0x0 is located with interrupt vector table, not for the variables:

    B.R.

    Sal