NVIC中断不在STM32F103上工作

时间:2017-03-13 18:19:57

标签: c arm stm32 interrupt-handling

我已经编写了以下代码来控制LED在B3上配置为AFIO连接的LED,但是看起来NVIC功能有问题,请问它们应该如何使用。

#include "stm32f10x.h"

void EXTI3_IRQHandler(void)
{

    //Check if EXTI_Line0 is asserted
    if(EXTI_GetITStatus(EXTI_Line3) != RESET)
    {
        GPIOA -> ODR=0X00F0;
    }
    //we need to clear line pending bit manually
    EXTI_ClearITPendingBit(EXTI_Line3);
}

int main()
{
    // ENABLING CORRESPONDING CLOCKS
    RCC->APB2ENR |= 0X000D;
    RCC->APB1ENR |= 0X0001;

    //CONFIGURING GPIO PORTS -- PIN 3 CONFIGURED AS AFIO PUSH/PULL AND PIN4 SET UP AS GPIO OUTPUT
    GPIOA->CRL = 0X00B3B000; 
    GPIOB->CRL = 0X0000B000;

    //PA6 IS SET AS EVENT OUTPUT PORT
    AFIO->EVCR |= 0X0086;

    //PB3 SET AS INPUT PORT AFIO_EXTICR1
    AFIO->EXTICR[1] |= 0X1000 ;

    //SELECTING RISING TRIGGERS
    EXTI->RTSR = 0X0008 ;

    // UNMASKING INTERRUPT SIGNAL AT EXTI3
    EXTI->IMR |= 0X0008 ;   

    // UNMASKING EVENT SIGNAL AT EXTI6
    EXTI->EMR |= 0X0040 ;   

    GPIOA -> ODR=0X0010;

    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; 
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 
    NVIC_Init(&NVIC_InitStructure);  
}

2 个答案:

答案 0 :(得分:1)

下面是一个使用硬件中断的完整无库示例,它是计时器而不是gpio,但你应该明白这个想法。有些人会发火焰/抨击,甚至可能会看到他们可以招募多少次投票。他们对事情的运作方式并不感兴趣只是想让其他人让他们为他们工作并继续前进。我很感激你想要了解并看到这些东西。 (您是否可以在ST文档中找到错误?或者可能是ST文档剪切并将其粘贴到文档中时出错?它与您的问题无关)

我将不得不再深入研究你的问题,看看有没有跳出来。我强烈建议您如下所示一步一步。在启用中断之前,使用轮询可以看到外设显示中断吗?然后你能看到NVIC中的中断未决(没有启用处理器中断)然后最后如果你启用中断到处理器,你知道它正在进入nvic,你可以清除它等等所以最后一步是你的函数被调用。如果你试图在一个实验中做所有这些事情,那就更难调试了。

flash.s

.cpu cortex-m0
.thumb

.thumb_func
.global _start
_start:
.word 0x20005000
.word reset
.word hang @ NMI
.word hang @ Hard Fault
.word hang @ MMU Fault
.word hang @ Bus Fault
.word hang @ Usage Fault
.word hang
.word hang
.word hang
.word hang
.word hang @ svcall
.word hang
.word hang
.word hang @ pendsv
.word hang @ systick

.word hang @ irq  0
.word hang @ irq  1
.word hang @ irq  2
.word hang @ irq  3
.word hang @ irq  4
.word hang @ irq  5
.word hang @ irq  6
.word hang @ irq  7
.word hang @ irq  8
.word hang @ irq  9
.word hang @ irq 10
.word hang @ irq 11
.word hang @ irq 12
.word hang @ irq 13
.word hang @ irq 14
.word hang @ irq 15
.word hang @ irq 16
.word hang @ irq 17
.word hang @ irq 18
.word hang @ irq 19
.word hang @ irq 20
.word hang @ irq 21
.word hang @ irq 22
.word hang @ irq 23
.word hang @ irq 24
.word tim1_handler @ irq 25
.word hang @ irq 26
.word hang @ irq 27
.word hang @ irq 28
.word hang @ irq 29

.thumb_func
reset:
    bl notmain
    b hang
.thumb_func
hang:   b .

.end

putget.s

.cpu cortex-m0
.thumb

.thumb_func
.globl PUT16
PUT16:
    strh r1,[r0]
    bx lr

.thumb_func
.globl PUT32
PUT32:
    str r1,[r0]
    bx lr

.thumb_func
.globl GET32
GET32:
    ldr r0,[r0]
    bx lr

.thumb_func
.globl dummy
dummy:
    bx lr

.end

flash.ld

MEMORY
{
    rom : ORIGIN = 0x08000000, LENGTH = 0x1000
    ram : ORIGIN = 0x20000000, LENGTH = 0x5000
}

SECTIONS
{
    .text : { *(.text*) } > rom
    .rodata : { *(.rodata*) } > rom
    .bss : { *(.bss*) } > ram
}

notmain.c

//PA9  TX
//PA10 RX

void PUT32 ( unsigned int, unsigned int );
unsigned int GET32 ( unsigned int );
unsigned int GET16 ( unsigned int );
void dummy ( unsigned int );

#define USART1_BASE 0x40013800
#define USART1_SR   (USART1_BASE+0x00)
#define USART1_DR   (USART1_BASE+0x04)
#define USART1_BRR  (USART1_BASE+0x08)
#define USART1_CR1  (USART1_BASE+0x0C)
#define USART1_CR2  (USART1_BASE+0x10)
#define USART1_CR3  (USART1_BASE+0x14)
#define USART1_GTPR (USART1_BASE+0x18)

#define GPIOA_BASE 0x40010800
#define GPIOA_CRL  (GPIOA_BASE+0x00)
#define GPIOA_CRH  (GPIOA_BASE+0x04)
#define GPIOA_IDR  (GPIOA_BASE+0x08)
#define GPIOA_ODR  (GPIOA_BASE+0x0C)
#define GPIOA_BSRR (GPIOA_BASE+0x10)
#define GPIOA_BRR  (GPIOA_BASE+0x14)
#define GPIOA_LCKR (GPIOA_BASE+0x18)

#define RCC_BASE 0x40021000
#define RCC_APB2ENR (RCC_BASE+0x18)
#define RCC_CR      (RCC_BASE+0x00)
#define RCC_CFGR    (RCC_BASE+0x04)

#define GPIOBBASE 0x40010C00
#define RCCBASE 0x40021000

#define STK_CSR 0xE000E010
#define STK_RVR 0xE000E014
#define STK_CVR 0xE000E018
#define STK_MASK 0x00FFFFFF

#define PERIPH_BB_BASE 0x42000000

#define TIM1BASE    0x40012C00
#define TIM1_CR1    (TIM1BASE+0x00)
#define TIM1_DIER   (TIM1BASE+0x0C)
#define TIM1_SR     (TIM1BASE+0x10)

#define NVIC_BASE   0xE000E100
#define NVIC_ISER0  (NVIC_BASE+0x000)
#define NVIC_ISER1  (NVIC_BASE+0x004)
//...
#define NVIC_IPR18  (NVIC_BASE+0x348)
#define NVIC_IPR19  (NVIC_BASE+0x34C)
#define NVIC_IPR20  (NVIC_BASE+0x350)

#define NVIC_STIR   (NVIC_BASE+0xE00)

static void clock_init ( void )
{
    unsigned int ra;

    //enable the external clock
    ra=GET32(RCC_CR);
    ra=ra|1<<16; //HSEON
    PUT32(RCC_CR,ra);

    //wait for HSE to settle
    while(1) if(GET32(RCC_CR)&(1<<17)) break; //HSERDY



    //select HSE clock
    ra=GET32(RCC_CFGR);
    ra&=~(0x3<<0);
    ra|= (0x1<<0);
    PUT32(RCC_CFGR,ra);
    //wait for it
    while(1) if((GET32(RCC_CFGR)&0xF)==0x5) break;
    return;
}


static void uart_init ( void )
{
    //assuming 8MHz clock, 115200 8N1
    unsigned int ra;

    ra=GET32(RCC_APB2ENR);
    ra|=1<<2;   //GPIOA
    ra|=1<<14;  //USART1
    PUT32(RCC_APB2ENR,ra);

    //pa9 TX  alternate function output push-pull
    //pa10 RX configure as input floating
    ra=GET32(GPIOA_CRH);
    ra&=~(0xFF0);
    ra|=0x490;
    PUT32(GPIOA_CRH,ra);

    PUT32(USART1_CR1,0x2000);
    PUT32(USART1_CR2,0x0000);
    PUT32(USART1_CR3,0x0000);
    //8000000/16 = 500000
    //500000/115200 = 4.34
    //4 and 5/16 = 4.3125
    //4.3125 * 16 * 115200 = 7948800
    PUT32(USART1_BRR,0x0045);
    PUT32(USART1_CR1,0x200C);
}
static void uart_putc ( unsigned int c )
{
    while(1)
    {
        if(GET32(USART1_SR)&0x80) break;
    }
    PUT32(USART1_DR,c);
}
static void hexstrings ( unsigned int d )
{
    unsigned int rb;
    unsigned int rc;

    rb=32;
    while(1)
    {
        rb-=4;
        rc=(d>>rb)&0xF;
        if(rc>9) rc+=0x37; else rc+=0x30;
        uart_putc(rc);
        if(rb==0) break;
    }
    uart_putc(0x20);
}
static void hexstring ( unsigned int d )
{
    hexstrings(d);
    uart_putc(0x0D);
    uart_putc(0x0A);
}

volatile unsigned int counter;
void tim1_handler ( void )
{
    counter++;
    //uart_putc(0x55);
    PUT32(TIM1_SR,0);
}

int notmain ( void )
{
    unsigned int ra;
    unsigned int rb;
    unsigned int rc;

    clock_init();
    uart_init();
    hexstring(0x12345678);

    ra=GET32(RCC_APB2ENR);
    ra|=1<<11;  //TIM1
    PUT32(RCC_APB2ENR,ra);

if(0)
{
    PUT32(TIM1_CR1,0x00001);
    for(rc=0;;rc++)
    {
        hexstring(rc);
        for(ra=0;ra<1221;ra++)
        {
            while(1)
            {
                rb=GET32(TIM1_SR);
                if(rb) break;
            }
            PUT32(TIM1_SR,0);
        }
    }
}

if(0)
{
    PUT32(TIM1_CR1,0x00001);
    PUT32(TIM1_DIER,0x00001);
    while(1)
    {
        rb=GET32(TIM1_SR);
        if(rb) break;
    }
    hexstring(rb);
    hexstring(GET32(NVIC_ICPR0));
    hexstring(GET32(NVIC_ICPR1));
    hexstring(GET32(NVIC_ICPR2));
}

if(1)
{
    counter=0;
    PUT32(TIM1_CR1,0x00001);
    PUT32(TIM1_DIER,0x00001);
    PUT32(NVIC_ISER0,0x02000000);
    for(rc=0;rc<10;)
    {
        if(counter>=1221)
        {
            counter=0;
            hexstring(rc++);
        }
    }
    PUT32(TIM1_CR1,0x00000);
    PUT32(TIM1_DIER,0x00000);
}

    return(0);
}

构建,如果需要,可以将cortex-m0s更改为m3s,m3代码不是你遇到的问题

arm-none-eabi-as --warn --fatal-warnings -mcpu=cortex-m0 flash.s -o flash.o
arm-none-eabi-as --warn --fatal-warnings -mcpu=cortex-m0 putget.s -o putget.o
arm-none-eabi-gcc -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding -mcpu=cortex-m0 -march=armv6-m -mthumb -mcpu=cortex-m0 -march=armv6-m -c notmain.c -o notmain.o
arm-none-eabi-ld -T flash.ld flash.o putget.o notmain.o -o notmain.elf
arm-none-eabi-objdump -D notmain.elf > notmain.list
arm-none-eabi-objcopy notmain.elf notmain.bin -O binary

修改

这使用pb8作为输入而pb9作为输出,而不是可以反弹的开关,我正在驱动pb9来模拟(和控制)pb8上的状态变化。无法将pb3作为通用输入工作,只需创建一个循环查找pb3以直接更改led指示灯或使用uart打印某些内容,并将pb3排序到地面和/或3.3并查看是否获得GPIOB IDR以显示更改,我不能。所以切换到pb8。

notmain.c

//PA9  TX
//PA10 RX

void PUT32 ( unsigned int, unsigned int );
unsigned int GET32 ( unsigned int );
unsigned int GET16 ( unsigned int );
void dummy ( unsigned int );

#define USART1_BASE 0x40013800
#define USART1_SR   (USART1_BASE+0x00)
#define USART1_DR   (USART1_BASE+0x04)
#define USART1_BRR  (USART1_BASE+0x08)
#define USART1_CR1  (USART1_BASE+0x0C)
#define USART1_CR2  (USART1_BASE+0x10)
#define USART1_CR3  (USART1_BASE+0x14)
#define USART1_GTPR (USART1_BASE+0x18)

#define GPIOA_BASE 0x40010800
#define GPIOA_CRL  (GPIOA_BASE+0x00)
#define GPIOA_CRH  (GPIOA_BASE+0x04)
#define GPIOA_IDR  (GPIOA_BASE+0x08)
#define GPIOA_ODR  (GPIOA_BASE+0x0C)
#define GPIOA_BSRR (GPIOA_BASE+0x10)
#define GPIOA_BRR  (GPIOA_BASE+0x14)
#define GPIOA_LCKR (GPIOA_BASE+0x18)

#define GPIOB_BASE 0x40010C00
#define GPIOB_CRL  (GPIOB_BASE+0x00)
#define GPIOB_CRH  (GPIOB_BASE+0x04)
#define GPIOB_IDR  (GPIOB_BASE+0x08)
#define GPIOB_ODR  (GPIOB_BASE+0x0C)
#define GPIOB_BSRR (GPIOB_BASE+0x10)
#define GPIOB_BRR  (GPIOB_BASE+0x14)
#define GPIOB_LCKR (GPIOB_BASE+0x18)

#define RCC_BASE 0x40021000
#define RCC_APB2ENR (RCC_BASE+0x18)
#define RCC_CR      (RCC_BASE+0x00)
#define RCC_CFGR    (RCC_BASE+0x04)

#define GPIOBBASE 0x40010C00
#define RCCBASE 0x40021000

#define STK_CSR 0xE000E010
#define STK_RVR 0xE000E014
#define STK_CVR 0xE000E018
#define STK_MASK 0x00FFFFFF

#define PERIPH_BB_BASE 0x42000000

#define TIM1BASE    0x40012C00
#define TIM1_CR1    (TIM1BASE+0x00)
#define TIM1_DIER   (TIM1BASE+0x0C)
#define TIM1_SR     (TIM1BASE+0x10)

#define NVIC_BASE   0xE000E100
#define NVIC_ISER0  (NVIC_BASE+0x000)
#define NVIC_ISER1  (NVIC_BASE+0x004)
#define NVIC_ISER2  (NVIC_BASE+0x008)
#define NVIC_ICER0  (NVIC_BASE+0x080)
#define NVIC_ICER1  (NVIC_BASE+0x084)
#define NVIC_ICER2  (NVIC_BASE+0x088)
#define NVIC_ISPR0  (NVIC_BASE+0x100)
#define NVIC_ISPR1  (NVIC_BASE+0x104)
#define NVIC_ISPR2  (NVIC_BASE+0x108)
#define NVIC_ICPR0  (NVIC_BASE+0x180)
#define NVIC_ICPR1  (NVIC_BASE+0x184)
#define NVIC_ICPR2  (NVIC_BASE+0x188)
#define NVIC_IABR0  (NVIC_BASE+0x200)
#define NVIC_IABR1  (NVIC_BASE+0x204)
#define NVIC_IABR2  (NVIC_BASE+0x208)
#define NVIC_IPR00  (NVIC_BASE+0x300)
#define NVIC_IPR01  (NVIC_BASE+0x304)
#define NVIC_IPR02  (NVIC_BASE+0x308)
#define NVIC_IPR03  (NVIC_BASE+0x30C)
#define NVIC_IPR04  (NVIC_BASE+0x310)
#define NVIC_IPR05  (NVIC_BASE+0x314)
#define NVIC_IPR06  (NVIC_BASE+0x318)
#define NVIC_IPR07  (NVIC_BASE+0x31C)
#define NVIC_IPR08  (NVIC_BASE+0x320)
#define NVIC_IPR09  (NVIC_BASE+0x324)
#define NVIC_IPR10  (NVIC_BASE+0x328)
#define NVIC_IPR11  (NVIC_BASE+0x32C)
#define NVIC_IPR12  (NVIC_BASE+0x330)
#define NVIC_IPR13  (NVIC_BASE+0x334)
#define NVIC_IPR14  (NVIC_BASE+0x338)
#define NVIC_IPR15  (NVIC_BASE+0x33C)
#define NVIC_IPR16  (NVIC_BASE+0x340)
#define NVIC_IPR17  (NVIC_BASE+0x344)
#define NVIC_IPR18  (NVIC_BASE+0x348)
#define NVIC_IPR19  (NVIC_BASE+0x34C)
#define NVIC_IPR20  (NVIC_BASE+0x350)

#define NVIC_STIR   (NVIC_BASE+0xE00)


#define EXTI_BASE   0x40010400
#define EXTI_IMR    (EXTI_BASE+0x00)
#define EXTI_EMR    (EXTI_BASE+0x04)
#define EXTI_RTSR   (EXTI_BASE+0x08)
#define EXTI_FTSR   (EXTI_BASE+0x0C)
#define EXTI_SWIER  (EXTI_BASE+0x10)
#define EXTI_PR     (EXTI_BASE+0x14)


#define AFIO_BASE 0x40010000

#define AFIO_EXTICR1 (AFIO_BASE+0x08)
#define AFIO_EXTICR2 (AFIO_BASE+0x0C)
#define AFIO_EXTICR3 (AFIO_BASE+0x10)
#define AFIO_EXTICR4 (AFIO_BASE+0x14)










static void clock_init ( void )
{
    unsigned int ra;

    //enable the external clock
    ra=GET32(RCC_CR);
    ra=ra|1<<16; //HSEON
    PUT32(RCC_CR,ra);

    //wait for HSE to settle
    while(1) if(GET32(RCC_CR)&(1<<17)) break; //HSERDY



    //select HSE clock
    ra=GET32(RCC_CFGR);
    ra&=~(0x3<<0);
    ra|= (0x1<<0);
    PUT32(RCC_CFGR,ra);
    //wait for it
    while(1) if((GET32(RCC_CFGR)&0xF)==0x5) break;
    return;
}


static void uart_init ( void )
{
    //assuming 8MHz clock, 115200 8N1
    unsigned int ra;

    ra=GET32(RCC_APB2ENR);
    ra|=1<<2;   //GPIOA
    ra|=1<<14;  //USART1
    PUT32(RCC_APB2ENR,ra);

    //pa9 TX  alternate function output push-pull
    //pa10 RX configure as input floating
    ra=GET32(GPIOA_CRH);
    ra&=~(0xFF0);
    ra|=0x490;
    PUT32(GPIOA_CRH,ra);

    PUT32(USART1_CR1,0x2000);
    PUT32(USART1_CR2,0x0000);
    PUT32(USART1_CR3,0x0000);
    //8000000/16 = 500000
    //500000/115200 = 4.34
    //4 and 5/16 = 4.3125
    //4.3125 * 16 * 115200 = 7948800
    PUT32(USART1_BRR,0x0045);
    PUT32(USART1_CR1,0x200C);
}
static void uart_putc ( unsigned int c )
{
    while(1)
    {
        if(GET32(USART1_SR)&0x80) break;
    }
    PUT32(USART1_DR,c);
}
static void hexstrings ( unsigned int d )
{
    unsigned int rb;
    unsigned int rc;

    rb=32;
    while(1)
    {
        rb-=4;
        rc=(d>>rb)&0xF;
        if(rc>9) rc+=0x37; else rc+=0x30;
        uart_putc(rc);
        if(rb==0) break;
    }
    uart_putc(0x20);
}
static void hexstring ( unsigned int d )
{
    hexstrings(d);
    uart_putc(0x0D);
    uart_putc(0x0A);
}

void int_handler ( void )
{
    uart_putc(0x55);
    PUT32(EXTI_PR,1<<8);
    PUT32(NVIC_ICPR0,1<<23);
}

static int delay ( unsigned int n )
{
    unsigned int ra;

    while(n--)
    {
        while(1)
        {
            ra=GET32(STK_CSR);
            if(ra&(1<<16)) break;
        }
    }
    return(0);
}


int notmain ( void )
{
    unsigned int ra;
    //unsigned int rb;

    clock_init();
    uart_init();
    hexstring(0x11223344);

    ra=GET32(RCC_APB2ENR);
    ra|=1<<3;   //GPIOB
    ra|=1<<0;   //AFIO
    PUT32(RCC_APB2ENR,ra);
    hexstring(GET32(GPIOB_CRL));

if(0)
{
    //PB4 OUTPUT PB3 INPUT
    ra=GET32(GPIOB_CRH);
    ra&=~(0xF<<0); //PB8
    ra|= (0x4<<0); //PB8 input
    ra&=~(0xF<<4); //PB9
    ra|= (0x1<<4); //PB9 output
    PUT32(GPIOB_CRH,ra);

    hexstring(GET32(GPIOB_IDR));
    PUT32(GPIOB_BSRR,(1<<9)<< 0);
    hexstring(GET32(GPIOB_IDR));
    PUT32(GPIOB_BSRR,(1<<9)<<16);
    hexstring(GET32(GPIOB_IDR));
}
if(0)
{
    ra=GET32(GPIOB_CRH);
    ra&=~(0xF<<0); //PB8
    ra|= (0x4<<0); //PB8 input
    ra&=~(0xF<<4); //PB9
    ra|= (0x1<<4); //PB9 output
    PUT32(GPIOB_CRH,ra);

    hexstring(GET32(GPIOB_IDR)&(1<<8));
    PUT32(GPIOB_BSRR,(1<<9)<< 0);
    hexstring(GET32(GPIOB_IDR)&(1<<8));

    PUT32(AFIO_EXTICR3,1<<0);
    PUT32(EXTI_RTSR,1<<8);
    //PUT32(EXTI_FTSR,1<<8);
    //PUT32(EXTI_SWIER,1<<8);
    PUT32(EXTI_IMR,1<<8);
    //PUT32(EXTI_EMR,1<<8);

    PUT32(GPIOB_BSRR,(1<<9)<<16);
    hexstring(GET32(GPIOB_IDR)&(1<<8));
    PUT32(GPIOB_BSRR,(1<<9)<< 0);
    hexstring(GET32(GPIOB_IDR)&(1<<8));
    hexstring(0xaabbccde);
    //hexstring(GET32(EXTI_SWIER));
    hexstring(GET32(EXTI_PR));
    hexstring(GET32(NVIC_ICPR0));
    hexstring(GET32(NVIC_ICPR1));
    hexstring(GET32(NVIC_ICPR2));
    hexstring(0xaabbccdf);
    PUT32(EXTI_PR,1<<8);
    hexstring(GET32(EXTI_PR));
    hexstring(GET32(NVIC_ICPR0));
    hexstring(GET32(NVIC_ICPR1));
    hexstring(GET32(NVIC_ICPR2));
    hexstring(0xaabbccef);
    PUT32(NVIC_ICPR0,1<<23);
    hexstring(GET32(EXTI_PR));
    hexstring(GET32(NVIC_ICPR0));
    hexstring(GET32(NVIC_ICPR1));
    hexstring(GET32(NVIC_ICPR2));
}


    ra=GET32(GPIOB_CRH);
    ra&=~(0xF<<0); //PB8
    ra|= (0x4<<0); //PB8 input
    ra&=~(0xF<<4); //PB9
    ra|= (0x1<<4); //PB9 output
    PUT32(GPIOB_CRH,ra);

    //hexstring(GET32(GPIOB_IDR)&(1<<8));
    //PUT32(GPIOB_BSRR,(1<<9)<< 0);
    //hexstring(GET32(GPIOB_IDR)&(1<<8));

    PUT32(AFIO_EXTICR3,1<<0);
    PUT32(EXTI_RTSR,1<<8);
    //PUT32(EXTI_FTSR,1<<8);
    //PUT32(EXTI_SWIER,1<<8);
    PUT32(EXTI_IMR,1<<8);
    //PUT32(EXTI_EMR,1<<8);
    PUT32(NVIC_ISER0,0x00800000);

    PUT32(STK_CSR,4);
    PUT32(STK_RVR,1000000-1);
    PUT32(STK_CVR,0x00000000);
    PUT32(STK_CSR,5);

    while(1)
    {
        PUT32(GPIOB_BSRR,(1<<9)<<16);
        delay(8);
        PUT32(GPIOB_BSRR,(1<<9)<< 0);
        delay(8);
    }

    return(0);
}

我发现它使用了中断23.

 8000098:   080000bf 
 800009c:   0800014d  <- points at interrupt handler
 80000a0:   080000bf 

并且匹配EXTI第9行到第5行的文档(在向量表中搜索EXTI9_5和/或009C或0x0000_009C)。

似乎并不关心pb是否配置为AFIO输出(0xB)或浮动输入(0x4)。所以我不认为这是你的问题。

这个易失性指针数组甚至比使用volatile指针更糟糕:

AFIO->EXTICR[1]

我想知道是否真的使用EXTCR2 0x4001000C而不是EXTCR1,这就是你想要的0x40010008。我会做一个单行程序

AFIO->EXTICR[1]=7

然后反汇编它,看看他们是否正在生产一个商店到0x40010008,如果没有,那么就有你的问题。

从我看到你不需要乱用EMR,尽管有图纸(另一个文档错误?),你不需要设置SWIER以便让信号传递到PR。我只需要上面显示的寄存器来获得PR以反映输入上的边沿检测。从那里NVIC可以看到它然后我可以设置一个处理程序。

我使用systick定时器每秒驱动我的pb9输出,每隔一秒就会产生一次中断,因为我只是在看其中一条边。如果你有一个开关,你显然不需要任何一个。

答案 1 :(得分:1)

根据我的解释,您希望将引脚3作为中断线,但根据代码中的注释将其设置为OUTPUT Alt Function。要将引脚设置为exti线,需要将其设置为输入上拉/下拉,根据按钮的接线方式,需要设置上升沿触发或下降沿触发,并设置内部上拉/下拉电阻器使得实际的边缘变化。

示例:

PIN3 - &GT;按钮 - &GT;地面

将Pin3设置为ExtI3 通过上拉/下拉将NOT3设置为INPUT(NOT AFIO) 因为按下按钮时pin3变为低电平,然后将边沿触发设置为下降沿,ODR寄存器必须将其拉高 按下按钮。因此,将1写入相应的ODR位。 然后继续使用NVIC代码和IRQn等....