STM32:未初始化的变量?

发布于 2024-12-19 09:43:32 字数 342 浏览 4 评论 0原文

使用uvision IDE进行STM32开发,我想要一些定时器变量在启动时不初始化。我已经尝试过:

volatile unsigned int system_time __attribute__((section(".noinit")));

__attribute__((zero_init)) volatile int system_timer;

似乎没有任何效果。按照其他地方的提示,我还检查了 options/target/IRAM1 中的 NoInit。 尽管如此,重置后变量仍设置为零。

有人可以帮忙吗?

using the uvision IDE for STM32 development, I want to have some timer variables not initialized at startup. I have tried:

volatile unsigned int system_time __attribute__((section(".noinit")));

and

__attribute__((zero_init)) volatile int system_timer;

but nothing seems to work. Following the hints from elswhere, I have additionally checked NoInit at options/target/IRAM1.
Still, the variables are set to zero after reset.

Can anybody help?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别忘他 2024-12-26 09:43:32

您需要按照以下步骤操作。
如下声明变量:

volatile unsigned int system_time __attribute__((section(".noinit"),zero_init));

然后,您必须使用分散文件来声明具有 NOINIT 属性的执行部分,并将其与链接器一起使用。
分散文件示例:

LR_IROM1 0x08000000 0x00080000  {    ; load region size_region
   ER_IROM1 0x08000000 0x00080000  {  ; load address = execution address
      *.o (RESET, +First)
      *(InRoot$Sections)
      .ANY (+RO)
   }
   RW_IRAM1 0x20000000 UNINIT 0x00000100  { ;no init section
      *(.noinit)
   }
   RW_IRAM2 0x20000100 0x0000FFF0  {                ;all other rw data
      .ANY(+RW +ZI)
   }
}

You need to follow these steps.
declare your variable as follows:

volatile unsigned int system_time __attribute__((section(".noinit"),zero_init));

Then you have to use a scatter file to declare the execution section with the NOINIT attribute and use it with the linker.
example scatter file:

LR_IROM1 0x08000000 0x00080000  {    ; load region size_region
   ER_IROM1 0x08000000 0x00080000  {  ; load address = execution address
      *.o (RESET, +First)
      *(InRoot$Sections)
      .ANY (+RO)
   }
   RW_IRAM1 0x20000000 UNINIT 0x00000100  { ;no init section
      *(.noinit)
   }
   RW_IRAM2 0x20000100 0x0000FFF0  {                ;all other rw data
      .ANY(+RW +ZI)
   }
}
如果没结果 2024-12-26 09:43:32

您必须从 .MAP 文件中检查该变量的地址,并使用 at 关键字

允许您指定 C 源文件中未初始化变量的地址。 下面的例子

演示了如何使用at关键字来定位几种不同的变量类型。例如……

struct link  {
  struct link idata *next;
  char        code  *test;
};

struct link idata list _at_ 0x40;     /* list at idata 0x40 */
char xdata text[256]   _at_ 0xE000;   /* array at xdata 0xE000 */
int xdata i1           _at_ 0x8000;   /* int at xdata 0x8000 */
char far ftext[256]    _at_ 0x02E000; /* array at xdata 0x03E000 */

void main ( void ) {
  link.next = (void *) 0;
  i1        = 0x1234;
  text [0]  = 'a';
  ftext[0]  = 'f';
}

希望对解决您的问题有所帮助。

You have to check the address of that variable from .MAP file and use the The at keyword

allows you to specify the address for uninitialized variables in your C source files. The

following example demonstrates how to locate several different variable types using the at keyword.for example......

struct link  {
  struct link idata *next;
  char        code  *test;
};

struct link idata list _at_ 0x40;     /* list at idata 0x40 */
char xdata text[256]   _at_ 0xE000;   /* array at xdata 0xE000 */
int xdata i1           _at_ 0x8000;   /* int at xdata 0x8000 */
char far ftext[256]    _at_ 0x02E000; /* array at xdata 0x03E000 */

void main ( void ) {
  link.next = (void *) 0;
  i1        = 0x1234;
  text [0]  = 'a';
  ftext[0]  = 'f';
}

I hope it helps for solving your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文