Page 1 of 1

Help working with Interrupts....

Posted: Thu Jan 24, 2013 5:58 am
by Rick Burnett
Okay, my last big hurdle I think of working with the STM32F4. I've looked through the documents talking about callbacks that get called from an interrupt, and the different ways you can implement them to get different behavior.

What I do not understand is how I associate a digital IO with an interrupt, if I can set some sort of priorities, and how I set what conditions of the Digital IO will fire the interrupt. I've no problem reading more in the user guide for the STM32F4, that said, the reason I ask here is I want to do it properly with how it's expected withing the ChibiOS framework.

To give even a further example of what I am doing, I have a digital encoder attached to 2 inputs. Turning the knob generates two bit grey codes and I'd like a change on EITHER channel to trigger an interrupt so that I can take action based on the current state of both ports.

Any pointers would be greatly appreciated!

Thanks,
Rick

Re: Help working with Interrupts....

Posted: Thu Jan 24, 2013 8:02 am
by Giovanni
Hi,

What you are looking for is the EXTI unit of the STM32, this unit is supported in ChibiOS by the EXT driver, you can find an example under ./testhal/STM32F4xx/EXT. Basically it gives you callbacks on pins state changes. The driver allows to monitor up to 16 distinct pins plus several other internal sources.

Giovanni

Re: Help working with Interrupts....

Posted: Thu Jan 24, 2013 4:59 pm
by Rick Burnett
That's what I was looking for, thanks! I did read through the documentation to make sure I understood how it worked (From the STM32F4 level) but wasn't sure where to look for the ChibiOS level. Of course, looking in the driver section should have been my first instinct! Haha.

Thanks!
Rick

Re: Help working with Interrupts....

Posted: Fri Jan 25, 2013 4:50 am
by Rick Burnett
An additional question, looking at this post:

viewtopic.php?f=2&t=455&p=4087&hilit=EXT_MODE_GPIOA#p4087

The last comment says (if I am reading it correctly) if I turn on multiple ports for an EXT line, like so:

{EXT_CH_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOB | EXT_MODE_GPIOD,extcb2}

That in this case, since this is EXT2, if B2 or D2 changed, it would fire the callback. I'd just have to determine in the callback which one it was by keeping the previous values around and seeing who changed.

Is this assumption correct?

Rick

Re: Help working with Interrupts....

Posted: Fri Jan 25, 2013 8:27 am
by Giovanni
Careful, the EXTI only allows a certain bit to be mapped on a single port, so if you use the line EXTI 2 on GPIOB you cannot use the same line on GPIOD too, you have to use another bit number.

See the RM for details, the drivers abstract a lot but the underlying hardware cannot be ignored.

Giovanni

Re: Help working with Interrupts....

Posted: Fri Jan 25, 2013 9:05 pm
by Rick Burnett
Yeah, it definitely does not work. I tried mapping bit 2 of B and D to EXT2 and it did not work. I looked through all the ST documentation and I don't see anything that says the EXTI lines are or'd together. I've reworked my code to use individual EXT ports for only specific bit/channel as you are saying.