Cortex-M中断向量表原理及其重定向方法

2021/09/07 08:00

二、重定向中断向量表的方法

2.1 与中断向量表相关的文件

        THUMB        PUBWEAK Reset_Handler        SECTION .text:CODE:REORDER:NOROOT(2)Reset_Handler        CPSID   I               ; Mask interrupts        LDR     R0, =0xE000ED08      ; 即 SCB->VTOR        LDR     R1, =__vector_table  ; section .intvec 段首地址        STR     R1, [R0]        LDR     R2, [R1]        MSR     MSP, R2        LDR     R0, =SystemInit        BLX     R0        CPSIE   I               ; Unmask interrupts        LDR     R0, =__iar_program_start        BX      R0

define symbol m_interrupts_start       = 0x30002000;define symbol m_interrupts_end         = 0x300023FF;define exported symbol __VECTOR_TABLE          = m_interrupts_start;place at address mem: m_interrupts_start    { readonly section .intvec };

********************************************************************************** PLACEMENT SUMMARY***"A0":  place at address 0x3000'2000 { ro section .intvec };  Section              Kind         Address    Size  Object  -------              ----         -------    ----  ------"A0":                                         0x400  .intvec              ro code  0x3000'2000   0x400  startup_MIMXRT1176_cm7.o [1]                              - 0x3000'2400   0x400********************************************************************************** ENTRY LIST***Entry                       Address   Size  Type      Object  -----                       -------   ----  ----      ------SysTick_Handler         0x3000'5767   0x10  Code  Gb  led_blinky.o [1]__VECTOR_TABLE {Abs}    0x3000'2000         Data  Gb  <internal module>__Vectors               0x3000'2000          --   Gb  startup_MIMXRT1176_cm7.o [1]__Vectors_End           0x3000'2400         Data  Gb  startup_MIMXRT1176_cm7.o [1]__Vectors_Size {Abs}          0x400          --   Gb  startup_MIMXRT1176_cm7.o [1]__vector_table          0x3000'2000         Data  Gb  startup_MIMXRT1176_cm7.o [1]

2.2 中断重定向函数示例

__ramfunc void SysTick_Handler(void){    if (g_systickCounter != 0U)    {        g_systickCounter--;    }}
********************************************************************************** ENTRY LIST***Entry                       Address   Size  Type      Object  -----                       -------   ----  ----      ------SysTick_Handler                 0x1   0x14  Code  Gb  led_blinky.o [1]

extern uint32_t __VECTOR_TABLE[];void relocate_vector_table(void){    __disable_irq();    // 将 0x30002000 处的初始中断向量表拷贝到新地址 0x20000000    memcpy((void *)0x20000000, (void *)__VECTOR_TABLE, 0x400);    // 将 VTOR 指向 0x20000000    SCB->VTOR = 0x20000000;    __enable_irq();}int main(void){    relocate_vector_table()；    // 其余代码}

0 评论
0 收藏
0