写入NVIC寄存器时ARM Cortex M3硬故障

时间:2014-12-30 13:58:49

标签: c arm cortex-m3

每当我写入Cortex-M3中断控制器的寄存器时,都会产生硬故障中断。

我认为它与未配置的MPU有关。 我正在使用Cortex-M3的启动代码进行基本的金属演示。 以下是MPU的配置方式以及我在末尾添加的位

  /* Configure region 1 to cover VECTORS and CODE (Executable, Read-only) */
/* Start address, Region field valid, Region number */
SCS.MPU.RegionBaseAddr = ((unsigned int) &Image$$VECTORS$$Base) | REGION_VALID | 1;
/* Access control bits, Size, Enable */
SCS.MPU.RegionAttrSize = RO | CACHEABLE | BUFFERABLE | REGION_16K | REGION_ENABLED;

/* Configure a region to cover DATA in RAM (Executable, Read-Write) */
SCS.MPU.RegionBaseAddr = ((unsigned int) &Image$$DATA$$Base) | REGION_VALID | 2;
SCS.MPU.RegionAttrSize = FULL_ACCESS | CACHEABLE | BUFFERABLE | REGION_8K | REGION_ENABLED;

/* Configure a region to cover Heap and Main Stack (Not Executable, Read-Write) */
SCS.MPU.RegionBaseAddr = ((unsigned int) &Image$$ARM_LIB_STACKHEAP$$Base) | REGION_VALID | 3;
SCS.MPU.RegionAttrSize = NOT_EXEC | FULL_ACCESS | CACHEABLE | BUFFERABLE | REGION_4K | REGION_ENABLED;

/* Configure a region to cover Process Stack (Not Executable, Read-Write) */
SCS.MPU.RegionBaseAddr = ((unsigned int) &Image$$PROCESS_STACK$$ZI$$Base) | REGION_VALID | 4;
SCS.MPU.RegionAttrSize = NOT_EXEC | FULL_ACCESS | CACHEABLE | BUFFERABLE | REGION_4K | REGION_ENABLED;

SCS.MPU.RegionBaseAddr = ((unsigned int)0x40000000) | REGION_VALID | 5;
SCS.MPU.RegionAttrSize = NOT_EXEC | FULL_ACCESS | REGION_512K | REGION_ENABLED;

SCS.MPU.RegionBaseAddr = ((unsigned int)0xE000E000) | REGION_VALID | 6;
SCS.MPU.RegionAttrSize = NOT_EXEC | P_RW_U_NA  | REGION_4K | REGION_ENABLED;

我添加了底部2个区域。倒数第二个用于外设地址空间,这允许我写入这些寄存器而不会导致错误。 最后一个区域是我为读取和写入NVIC控制器而添加的区域。

这是导致崩溃的确切行。

pNVIC->SETEN=0x10;//enables UART int2010                       
movs    r0,#0x10
mov     r1,#-0x1FFF2000 // R1 has the base address of NVIC 0xE000E000
str     r0,[r1,#0x100] //the SETEN register has an offset of 256 bytes

一旦调试器执行最后一条STR指令,就会发生异常

有人可以帮我配置MPU写入M3的NVIC寄存器吗?

以下是我的分散文件的外观。

LOAD_REGION 0x00000000 0x00005000
; for Keil MCBSTM32 use : LOAD_REGION 0x20000000 0x00005000
{
VECTORS +0 0x400    ; maximum of 256 exceptions (256*4 bytes == 0x400)
{
exceptions.o (vectors, +FIRST)     ; from exceptions.c
}

; Code is placed immediately (+0) after the previous root region
; (so code region will also be a root region)
CODE +0 0x4000-0x400
{
* (+RO)           ; All program code, including library code
}

DATA 0x20004000 0x2000
{
* (+RW, +ZI)      ; All RW and ZI data
}

; Heap grows upwards from start of this region and
; Stack grows downwards from end of this region
; The Main Stack Pointer is initialized on reset to the top addresses of this region
ARM_LIB_STACKHEAP 0x20006000 EMPTY 0x1000
{
}


PROCESS_STACK 0x20007000 EMPTY 0x1000
{
}

; System Control Space registers
SCS_REGION 0xE000E000 UNINIT 0x1000
{
scs.o(scs_registers)
}
}

0 个答案:

没有答案