NVIC的向量表偏移寄存器设置问题(已解决)

2019-07-20 23:51发布

void MY_NVIC_SetVectorTable(u32 NVIC_VectTab, u32 Offset) 
{
   //检查参数合法性
 assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
 assert_param(IS_NVIC_OFFSET(Offset));   
 SCB->VTOR = NVIC_VectTab|(Offset & (u32)0x1FFFFF80);//设置NVIC的向量表偏移寄存器
 //用于标识向量表是在CODE区还是在RAM区
}

问个问题,为什么(Offset & (u32)0x1FFFFF80)  为什么使用0x1FFFFF80,0x1FFFFF80是怎样得来的呢?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
38条回答
kenluo
2019-07-21 23:24
Since the address 0x0 should be boot code, usually it will either be Flash memory or ROM
devices, and the value cannot be changed at run time. However, the vector table can be
relocated to other memory locations in the Code or RAM region where the RAM is so that we
can change the handlers during run time. This is done by setting a register in the NVIC called
the vector table offset register (address 0xE000ED08). The address offset should be aligned
to the vector table size, extended to the power of 2. For example, if there are 32 IRQ inputs,
the total number of exceptions will be 32  16 (system exceptions)  48. Extending it to the
power of 2 makes it 64. Multiplying it by 4 makes it 256 (0x100). Therefore, the vector table
offset can be programmed as 0x0, 0x100, 0x200, and so on. The vector table offset register
contains the items shown in Table 7.7.
In applications where you want to allow dynamic changing of exception handlers, in the
beginning of the boot image you need to have these (at a minimum):
? Initial Main Stack ointer value
? Reset vector
Figure 7.8 Defi nition of riority Fields in an 8-bit riority Level Register with riority
Group Set to 0
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Preempt priority Subpriority
Address Exception Number Value (Word Size)
0x00000000 – MSP initial value
0x00000004 1 Reset vector (program counter initial value)
0x00000008 2 NMI handler starting address
0x0000000C 3 Hard fault handler starting address
… … Other handler starting address
Table 7.6 Exception Vector Table After ower Up
Bits Name Type Reset Value Description
29 TBLBASE R/W 0 Table base in Code (0) or RAM (1)
28:7 TBLOFF R/W 0 Table offset value from Code region or RAM region

今天看到你的解释之后,看了一下英文版123页

一周热门 更多>