pic32 8字节上的静态变量

发布于 2025-01-25 18:44:42 字数 980 浏览 3 评论 0原文

由于某种原因,当我将这两个变量提供“使用”属性时,编译器使它们长8个字节。没有它,编译器将它们优化,因为我不使用它们(尚未使用)。有人知道为什么这是吗?并且有任何已知的解决方法吗?

__attribute__ ((used,section(".booter_version"))) static uint32_t BooterVersion = 2;
__attribute__ ((used,section(".hardware_version"))) static uint32_t HardwareVersion = 3;

包含这些部分的LinkerScript部分:

 /* booter version number is placed at the second last 4 bytes of program mem for the booter*/
 .BooterVersion _BOOTER_VERSION_ADDRESS :
 {
    KEEP (*(.booter_version))
  } >kseg0_program_mem
 /* hardware version number is placed at the end of program mem for the booter */
 .HardwareVersion _HARDWARE_VERSION_ADDRESS :
 {
   KEEP (*(.hardware_version))
 } >kseg0_program_mem

编译后的内存图中的图像(在程序MEM中,您会看到最后两行):

“

For some reason, when I give these two variables the "used" attribute, the compiler makes them 8 bytes long. Without it, the compiler optimizes them away as I don't use them (yet). Anyone knows why this is? And are any workarounds for this known?

__attribute__ ((used,section(".booter_version"))) static uint32_t BooterVersion = 2;
__attribute__ ((used,section(".hardware_version"))) static uint32_t HardwareVersion = 3;

Linkerscript part with these sections:

 /* booter version number is placed at the second last 4 bytes of program mem for the booter*/
 .BooterVersion _BOOTER_VERSION_ADDRESS :
 {
    KEEP (*(.booter_version))
  } >kseg0_program_mem
 /* hardware version number is placed at the end of program mem for the booter */
 .HardwareVersion _HARDWARE_VERSION_ADDRESS :
 {
   KEEP (*(.hardware_version))
 } >kseg0_program_mem

Image from the memory map after compiling (in program mem, you see the last two lines for these):

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文