首页 > 解决方案 > arm-none-eabi-gcc(错误:初始化元素不是常数)

问题描述

我正在阅读Daniele Lacamera的《嵌入式系统架构》一书。在第 4 章,启动过程中,我们创建了中断向量表(对于 ARM Cortex M4),如下所示:

__attribute__ ((section(".isr_vector"))) void (* const ivt[])(void) =
{
    (void (*)(void))END_STACK,
    isr_reset,
    // Other ISRs
};

没有显示如何END_STACK编辑extern,所以我这样做了:

extern uint32_t END_STACK;

链接描述文件类似于以下内容:

MEMORY
{
    FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K
    RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 48K
}

END_STACK = ORIGIN(RAM) + LENGTH(RAM)

我收到以下错误:

arm-none-eabi-gcc -c main.c interrupt_vector.c -O0 -g -mthumb -mcpu=cortex-m4 -ffreestanding
interrupt_vector.c:14:5: error: initializer element is not constant
     (void (*)(void))END_STACK,
     ^

处理此问题的正确方法是什么?是否可以将其转换为函数的地址,或者我应该仅为堆栈指针创建一个新部分?

我试过洒constexternand cast 上,但无法解决错误。

标签: clinuxcortex-marm-none-eabi-gcc

解决方案


推荐阅读