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:对 MSPM0使用#pragma 和段数据

Guru**** 2394305 points
Other Parts Discussed in Thread: MSPM0G3507

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1502210/mspm0g3507-using-pragma-and-section-data-for-mspm0

器件型号:MSPM0G3507

工具/软件:

我也尝试切断闪存的某些部分、专门用于 MSPM0G3507和 TI Clang 编译器的一些常量。

我有以下代码行:

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=""

然后在链接器中可以看到:

移动数据

闪存(RX):origin = 0x00000000、length = 0x0001FFF0
FLASH_CRC (RX):origin = 0x0001FFF0、长度= 0x00000010
SRAM (rwx):origin = 0x20200000、长度= 0x00008000

...

}

很重要

...

.crc :> flash_crc

...

}

我在内存中的正确位置看到了变量、但我没有看到它们具有正确的初始值。 所有位都只是1。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Tomas:

    请查看 TI ARM CLANG 编译器用户指南: https://software-dl.ti.com/codegen/docs/tiarmclang/compiler_tools_user_guide/ 

    而是对属性进行处理。

    B.R.

    Sal

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我使用以下行而不是#pragma 尝试了该操作:

    uint32_t CRC_START_addr _attribute__((section (".ccrc")))= flash_origin_crc;
    uint32_t CRC_LENGTH ___attribute__((section (".ccrc"))= flash_length_crc;
    uint32_t CRC_CRC __attribute__((section (".crc")))= 0;
    uint16_t CRC_VERSION __attribute__((section (".ccrc"))= 0x1234;
    uint16_t CRC_PART_NUMBER __attribute__((section (".ccrc"))= 0x5678;

    还尝试了:

    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;

    在第一种情况下、我看到在正确的内存空间初始化变量、它们只是没有正确的值。

    在第二种情况下、它们未在正确的存储器空间初始化、也没有正确的值。  

    我通过此链接的以下示例获得了此信息:  

    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 

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Tomas:

    我看到您将 CRC 段放入闪存地址中、那么它还需要 const 属性。

    const uint32_t crc_start_addr __attribute__((section (".ccrc")))= flash_origin_crc;

    如果变量需要存储在闪存区域中、则这个是正确的。

    这里有什么问题?

    B.R.

    Sal

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    "const uint32_t CRC_START_addr _attribute__((section (".crc")))= flash_origin_crc;" 的问题是没有将变量分配到存储器中的正确位置或正确的值。 在链接器文件中、我具有:

    移动数据

    闪存(RX):origin = 0x00000000、length = 0x0001FFF0
    FLASH_CRC (RX):origin = 0x0001FFF0、长度= 0x00000010
    SRAM (rwx):origin = 0x20200000、长度= 0x00008000

    ...

    }

    很重要

    ...

    .crc :> flash_crc

    ...

    }

    这应该意味着变量 CRC_START_addr、CRC_LENGTH 等位于0x0001 FFF0和0x0002 0000之间。 查看调试器的存储器浏览器和表达式窗口时、它们不是:

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Tomas:

    我认为  crc_start_addr 未在代码中调用、编译器优化了它。   为变量添加"已使用"的附加属性并进行检查。 您也可以在用户指南中找到它。

    顺便说一下、您在下面分享的屏幕截图看起来不正确、通常0x0位于中断矢量表中、而不是变量:

    [报价 userid="613887" url="~/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1502210/mspm0g3507-using-pragma-and-section-data-for-mspm0/5775560 #5775560"]

    [/报价]

    B.R.

    Sal