Linker error: "bad address <value> for zero page symbol <name>"!

Linker error: "bad address <value> for zero page symbol <name>"!

我试图让 COSMIC 编译器在内存中的特定地址分配一个结构 (0x5420)。我在我的 C 代码中添加了以下行(其中 CAN_TypeDeftypedef struct):

#pragma section [mycan]
CAN_TypeDef CAN;
#pragma section []

在 IDE (STVD) 中,我创建了一个名为 Can 的新部分,在其中我创建了一个名为 .mycan.

的新部分

当我在 STVD 中构建代码时,出现链接器错误:

#error clnk Debug\can.lkf:1 bad address (0x5420) for zero page symbol _CAN

在上图中,很明显CanZero Page是两个不同的段。出现此错误的原因是什么?我该如何解决?

我不知道STM8,但我想我找到了。在 STVD documentation 我读到:

Global variables

When the category is set to General , you can use the Global Variables list box to specify the default location of global variables:

  • In Zero Page: This is the default option.
  • In Data: Specifies to place global variables in the first 64Kbytes of memory.

所以编译器假定所有全局数据都位于零页中,地址只有 8 位 宽。只有链接器会看到 .mycan 部分不在零页中,您会收到错误消息。我会尝试 @near CAN_TypeDef CAN; 或直接 extern CAN_TypeDef CAN @5420; 而无需创建您自己的部分。