提升PendSV中断的优先级




设置外设的中断优先级可以用STM32提供的库。

 如:

NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);


但对于系统内部异常的优先级的设置,我还没有找到相应的库函数。

但是,在《Cortex M3技术参考》文档中找到相关的寄存器。

8.2.2 NVIC register descriptions

    System Handler Priority Registers , Address  0xE000ED18, 0xE000ED1C , 0xE000ED20

Use the three System Handler Priority Registers to prioritize the following system handlers :

  • memory manage
  • bus fault
  • usage fault
  • debug monitor
  • SVC
  • SysTick
  • PendSV

在uCOS在STM32的移植文件中 os_cpu_asm.asm 用到对该寄存器的操作。

 

NVIC_INT_CTRL   EQU     0xE000ED04    ; Interrupt control state register.
NVIC_SYSPRI14   EQU     0xE000ED22    ; System priority register (priority 14).
NVIC_PENDSV_PRI EQU           0xFF    ; PendSV priority value (lowest).
NVIC_PENDSVSET  EQU     0x10000000    ; Value to trigger PendSV exception.

OSStartHighRdy
    LDR     R0, =NVIC_SYSPRI14        ; Set the PendSV exception priority
    LDR     R1, =NVIC_PENDSV_PRI
    STRB    R1, [R0]

    MOVS    R0, #0                    ; Set the PSP to 0 for initial context switch call
    MSR     PSP, R0

    LDR     R0, =OSRunning            ; OSRunning = TRUE
    MOVS    R1, #1
    STRB    R1, [R0]

    LDR     R0, =NVIC_INT_CTRL        ; Trigger the PendSV exception (causes context switch)
    LDR     R1, =NVIC_PENDSVSET
    STR     R1, [R0]

    CPSIE   I                         ; Enable interrupts at processor level

OSStartHang
    B       OSStartHang               ; Should never get here

将:
    NVIC_PENDSV_PRI EQU 0xFF
替换为:
    NVIC_PENDSV_PRI EQU 0x00

 

你可能感兴趣的:(提升PendSV中断的优先级)