嵌入式

STM32触发PendSV中断

  1. 设置PendSV优先级
    PendSV.png

NVIC_SYSPRI14 EQU 0xE000ED22

NVIC_PENDSV_PRI EQU 0xFF

LDR R0, =NVIC_SYSPRI14 LDR R1, =NVIC_PENDSV_PRI

STRB R1, [R0]

  1. 触发PendSV异常

PendSV_2.png

往ICSR第28位写1,即可将PendSV异常挂起。若是当前没有高优先级中断产生,那么程序将会进入PendSV handler

NVIC_INT_CTRL EQU 0xE000ED04

NVIC_PENDSVSET EQU 0x10000000

LDR R0, =NVIC_INT_CTRL

LDR R1, =NVIC_PENDSVSET

STR R1, [R0]

/**
 * @file    pendSV.c
 * @author  tymaker
 * @version V1.0.0
 * @date    2018-10-13 2018
 * @brief   GUI TrackBar module
 */
/* Includes ------------------------------------------------------------------*/
/********************************End of File************************************/
#include "pendSV.h"
__asm void SetPendSV(void) {
NVIC_SYSPRI14 EQU 0xE000ED22 
NVIC_PENDSV_PRI EQU 0xFF
    LDR R1, =NVIC_PENDSV_PRI

    LDR R0, =NVIC_SYSPRI14

    STRB R1, [R0]

    BX LR

    NOP
}


__asm void TriggerPendSV(void) {

NVIC_INT_CTRL EQU 0xE000ED04

NVIC_PENDSVSET EQU 0x10000000

    LDR R0, = NVIC_INT_CTRL

    LDR R1, =NVIC_PENDSVSET

    STR R1, [R0]

    BX LR

    NOP
}


/**
 * @file    pendSV.h
 * @author  tymaker
 * @version V1.0.0
 * @date    2018-10-13 2018
 * @brief   GUI TrackBar module
 */

/* Includes ------------------------------------------------------------------*/
#ifndef __PEND_S_V_H_
#define __PEND_S_V_H_

#include <stdio.h>

#include "stm32f10x_conf.h"

__asm void SetPendSV(void);

__asm void TriggerPendSV(void);

#endif



/********************************End of File************************************/

回复

This is just a placeholder img.