Configuring EXTI

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

synth002
Posts: 3
Joined: Mon Nov 16, 2015 4:38 pm

Configuring EXTI

Postby synth002 » Mon Nov 16, 2015 4:51 pm

Hello to all, im looking for a small bit of tuition in order to overcome a problem of mine.

Im currently using an STM32F407 Discovery board, and presently attempting to set PIN4 of PORTC to trigger an interrupt routine when either a rising or falling edge is detected. I've been through the reference manual and as far as I can see I have everything setup correctly, yet the interrupt isn't triggered when I apply +3V to the pin.

My code setting up the EXTI on PORTC Pin4, and interrupt routine is as follows, my thinking is that this should be a very simple problem fix for someone in the know. Unfortunately I am not able to use the libraries as I am need to become intimately familiar with the device (college). Thank you very much for any help offered.


Code: Select all


        RCC->AHB1ENR |=(1<<2);                   //Enable PORTC Clock
   GPIOC->OSPEEDR |=(1<<9);                //Enable high speed for pin 4
   GPIOC->PUPDR |=(1<<9);            //Pull down resistor for pin 4
   
   SYSCFG->EXTICR[2] |=(0x02);         //Enable EXTI on PORTC Pin4
   EXTI->IMR |=(1<<4);               
   EXTI->RTSR |=(1<<4);                               
   EXTI->FTSR |=(1<<4);
   NVIC_EnableIRQ(EXTI4_IRQn);


        void EXTI4_IRQHandler(void)
        {
   while(1)
   {
   printf("sucess!!");
   }
   EXTI->PR|=0x010;
        }






User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Configuring EXTI

Postby Giovanni » Mon Nov 16, 2015 5:13 pm

Hi,

ChibiOS includes an EXT driver that does what you want to do. You may study its code, look under /os/hal/ports/STM32/LLD/EXTIv1. It is not complex code.

Even if you cannot use the driver, you could try the ChibiOS EXT demo for the F4 and see how the driver works, then do the same.

Note1, where do you assign priority to the EXTI IRQ?
Note2, how printf() is supposed to work from an ISR?

Giovanni

synth002
Posts: 3
Joined: Mon Nov 16, 2015 4:38 pm

Re: Configuring EXTI

Postby synth002 » Mon Nov 16, 2015 7:34 pm

Code: Select all

ChibiOS includes an EXT driver that does what you want to do. You may study its code, look under /os/hal/ports/STM32/LLD/EXTIv1. It is not complex code.

Even if you cannot use the driver, you could try the ChibiOS EXT demo for the F4 and see how the driver works, then do the same.

Note1, where do you assign priority to the EXTI IRQ?
Note2, how printf() is supposed to work from an ISR?

Giovanni


Thanks for the reply, I will take a look at that and try and make something of it now. I have not assigned a priority to the interrupt, I'm very new to all this.. I have had other interrupts working without such a step, but I will look at doing that now as I do need this to be close to real time as possible. Can I not call a function from within an interrupt? removing that is not a problem, but I hadn't read that functions within interrupts is a no no.

Cheers.

synth002
Posts: 3
Joined: Mon Nov 16, 2015 4:38 pm

Re: Configuring EXTI

Postby synth002 » Mon Nov 16, 2015 10:00 pm

Got the thing working, as it may help someone else along when used in conjunction with the reference manual here's steps to enable an external interrupt, by setting the bits manually (for the most part).

Enable the port clock in register: RCC->AHB1ENR
Enable the SYSCFG clock in register: RCC->APB2ENR

Enable EXTI on the port/pin combination desired using register: SYSCFG->EXTICR[n]
where n is given by,
EXTICR1 n=0
EXTICR2 n=1
ect..

To enable interrupt on a pin set the corresponding bit in register: EXTI->IMR
To enable rising edge trigger use register: EXTI->RTSR
To enable falling edge trigger use register: EXTI->FTSR
(select both if required).

Set interrupt priority using CMSIS command: NVIC_SetPriority(EXTI[n]_IRQn, integer value)
Enable interrupt in nested interrupt vector using CMSIS commad: NVIC_EnableIRQ(EXTI[n]_IRQn);
In order to break out of interrupt, write 1 to appropriate bit within routine using register: EXTI->PR
Write the interrupt function routine.



Cheers, Synth002.

leon_titan
Posts: 24
Joined: Sun Jan 12, 2020 2:11 pm
Has thanked: 4 times

Re: Configuring EXTI

Postby leon_titan » Sun May 22, 2022 9:54 am

Even if you cannot use the driver, you could try the ChibiOS EXT demo for the F4 and see how the driver works, then do the same.

Where should I find this demo please?

In my application, I need to check the IOs FALLING EDGE, and react as fast as posibble(in μs). And wonder to know that which way is better, use EXT driver or use EVENT api?
I have readed the chibios event api in this blog: https://www.playembedded.org/blog/buttons-stm32/.

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Configuring EXTI

Postby Giovanni » Sun May 22, 2022 1:14 pm

Hi,

Look into the PAL driver (and demo), EXTI callbacks are handled there now.

Giovanni

leon_titan
Posts: 24
Joined: Sun Jan 12, 2020 2:11 pm
Has thanked: 4 times

Re: Configuring EXTI

Postby leon_titan » Mon May 23, 2022 12:45 am

Found it, thx.


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 54 guests