在代码中引用RAM中的部分,导致链接器错误[Lc036]



STM8,IAR编译器。

我试图将可更改中断向量表(IVT(放在RAM(ram_ivt_sectionRAM_IVT(中,从0x00地址开始声明。

Prereq:硬件入口点(base_ivt_sectionIVT_TO_RAM块(已被替换并重定向到此RAM地址。

所以,我有了下一个代码:

Header.h ===========================================
#define MCU_INTERRUPT_VECTORS_COUNT     (32)
typedef void (__interrupt *interrupt_handler_t)(void);
typedef struct {
int8_t value;
int8_t unused_byte;
interrupt_handler_t handler;
}interrupt_vector_t;
extern interrupt_vector_t ram_ivt[MCU_INTERRUPT_VECTORS_COUNT];
Source.c ===========================================
#include "header.h"
extern void __iar_program_start(void);
extern void __iar_unhandled_exception(void);
__interrupt void CallUnhandledException(void) { __iar_unhandled_exception(); }
__interrupt void CallResetHandler(void) { __iar_program_start(); }
interrupt_vector_t ram_ivt[MCU_INTERRUPT_VECTORS_COUNT] @".ram_ivt_sector" = {
{0x82, 0x00, CallResetHandler},
{0x82, 0x00, CallUnhandledException},
{0x82, 0x00, CallUnhandledException},
... repeats 32 times.
Main.c ===========================================
#include "header.h"
int main( void ) {
__enable_interrupt();
__trap();
}

它运行良好。在陷阱中,程序陷入未处理的异常。但是,当我试图修改或读取表时

Main.c ===========================================
#include "header.h"
int main( void ) {
volatile void* a = &ram_ivt[1].handler;
// Or
ram_ivt[1].handler = 0;
__enable_interrupt();
__trap();
}

项目停止在链接器阶段上生成,出现错误:

Error[Lc036]: no block or place matches the pattern "rw data section .ram_ivt_sector in ram_ivt.o symbols: [ram_ivt]" 

链接器文件://///////////////////////////////////////////////////////////////

define symbol __RAM_IVT__      = 0x000000;
//  Memory regions
define memory with size             = 16M;
define region TinyData              = [from 0x00 to 0xFF];
define region NearData              = [from 0x0000 to 0x0FFF];  
define region NearFuncCode          = [from 0x8000 to 0x9000];
define block CSTACK with size           = _CSTACK_SIZE  {};
define block HEAP  with size            = _HEAP_SIZE {};
define block IVT_TO_RAM with size       = 0x80, alignment = 1  { ro section .base_ivt_section };
define block RAM_IVT with size          = 0x80, alignment = 1  { rw section .ram_ivt_section };
define block INTVEC with size           = 0x80, alignment = 1  { ro section .intvec };
// Initialization
initialize by copy { rw section .iar.dynexit,
rw section .near.bss,
rw section .near.data,
rw section .near_func.textrw,
rw section .tiny.bss,
rw section .tiny.data,
ro section .tiny.rodata };
initialize by copy with packing = none { section __DLIB_PERTHREAD };
do not initialize  { rw section .near.noinit,
rw section .tiny.noinit,
rw section .vregs };
// Keep 
keep { rw section .ram_ivt_section };
// Placement
place at address mem: __RAM_IVT__       {   block RAM_IVT };
place in TinyData                       {   rw section .vregs,
rw section .tiny.bss,
rw section .tiny.data,
rw section .tiny.noinit,
rw section .tiny.rodata };
place in NearData                       {   block HEAP,
rw section __DLIB_PERTHREAD,
rw section .iar.dynexit,
rw section .near.bss,
rw section .near.data,
rw section .near.noinit,
rw section .near_func.textrw };                   
place at end of NearData                {   block CSTACK };

place at start of NearFuncCode          {   block IVT_TO_RAM };
place in NearFuncCode                   {   block INTVEC,
ro section __DLIB_PERTHREAD_init,       
ro section .iar.init_table,
ro section .init_array,
ro section .near.data_init,
ro section .near.rodata,
ro section .near_func.text,
ro section .near_func.textrw_init,
ro section .tiny.data_init,
ro section .tiny.rodata_init };

interrupt_vector_t ram_ivt[MCU_INTERRUPT_VECTORS_COUNT] @".ram_ivt_sector"ram_ivt_sector必须是ram_ivt_section

谢谢@KoynovStas。

最新更新