We'll continue this F4 assembler series with a short  Interrupt assembly routine to read the state of the Blue push button on the Stm32 F4 Discovery.

I know, I've already promised, that I would eventually write a simple routine almost wholly in assembler to garner some practice with the NVIC Interrupt structure.

But it proved much more difficult to keep this promise than I thought it would. Compared to the AVR interrupt structure, the ARM NVIC structure is really complicated, at

least at first :-( So, to cut a long story short, let's just firstly step through the attached code in Start: We begin, as usual,  with the initialisation of the clocks for all the

needed peripherals, in this case GPIOA, where the Blue push button is connected to Bit_0  and GPIOD, where the 4-onboard leds are to be be found. Immediately

following, we set the clock for the System Configuration Controller, SysCfg. This register is mainly used to remap the memory accessible in the code area, select 

the Ethernet PHY interface and manage the external interrupt line connection to the GPIOs. Since we're only interested in hooking up the external interrupt to GPIOA_0,

we can take advantage of the reset condition of all the SysCfg registers, which are already correctly "configured" for our needs :-)

Moving along smartly to the External interrupt/event controller (EXTI), we note, that bit GPIOA_0 is routed out to EXTI_0 and all we have to do is to set it up correctly.




   We firstly unmask the MR0_bit in the Interrupt mask register (EXTI_IMR) by setting it to a logic "1". Then we select the Falling Trigger Enable enable facility

for the same bit in the Falling trigger selection register (EXTI_FTSR). The EXTI Line0 interrupt is then activated in the NVIC Interrupt Set-Enable Register 0 and

all we have to do now is to write a simple and short Interrupt Handler, in bare-metal C. It's easier to use the inbuilt Keil C compiler's interrupt handling routines, than

to write one's own. Why bother to reinvent the wheel? The C handler routine is as follows: EXTI0_IRQHandler() {(*((unsigned int*)0x40013c14))=0x01;}. And this handler

simply resets the Pr0_Bit in the Interrupt Pending register (EXTI_PR).

   In the Interrupt Processing Routine, at IntPro, we use the WFI (Wait for Interrupt) instructon to set the Stm32 F4 into a light sleep in which it waits for the EXT1_0  

signal from our C handler. On arrival of the Interrupt signal, the routine simply toggles the 4 leds on and off at each consecutive release of the Blue push button. The 

mechanical bounce of the Blue push button is damped using a simple, non-politically-correct , 50mS software debounce delay and the routine loops back to "waiting" 

for the next falling edge. And that's all there is to it, folks ;-)

   " I'm the urban spaceman baby, and ... here comes the twist, ...  I don't exist. " Paul MacCartney.