[英]Refering in code to section placed in RAM, cause linker error [Lc036]
STM8,IAR 編譯器。
我試圖將可變中斷向量表(IVT)放在 RAM( ram_ivt_section
或RAM_IVT
)中,從 0x00 地址開始。
先決條件:硬件入口點( base_ivt_section
或IVT_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();
}
項目在 linker 階段停止構建,但出現錯誤:
Error[Lc036]: no block or place matches the pattern "rw data section .ram_ivt_sector in ram_ivt.o symbols: [ram_ivt]"
Linker 文件://////////////////////////////////////// /////////////////
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。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.