interrupt test EXTI stm32 nucleo

Dependencies:   mbed

Revision:
2:70bfc841a60f
Parent:
1:d049e15030ca
--- a/main.cpp	Mon Oct 26 10:12:47 2015 +0000
+++ b/main.cpp	Tue Oct 27 04:47:07 2015 +0000
@@ -1,23 +1,31 @@
 #include "mbed.h"
+#include "stm32f4xx_hal.h"
 #include "stm32f4xx.h"
-#include "stm32f4xx_hal_tim_ex.h"
-#include "stm32f4xx_hal_conf.h"
- 
- 
- 
-int16_t count1 = 10; 
- 
- 
+#include "stm32f4xx_hal_gpio.h"
+
+
+static GPIO_InitTypeDef  GPIO_InitStruct;
+
+int16_t count1 = 1000; 
+
 void EXTI0_IRQHandler(void)
 {
-    HAL_NVIC_ClearPendingIRQ(EXTI0_IRQn);
-    HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
+  HAL_NVIC_ClearPendingIRQ(EXTI0_IRQn);
+  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
+  {
+  /* EXTI line interrupt detected */
+  if(__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_0) != RESET)
+  {
+    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
+    HAL_GPIO_EXTI_Callback(GPIO_PIN_0);
+  }
 }
- 
+}
+
 void HAL_GPIO_EXTI_Callback (uint16_t GPIO_Pin)
 {
     if (GPIO_Pin == GPIO_PIN_0) {
-        count1 = 0;
+        count1 = 100;
     }
 }
  
@@ -25,25 +33,33 @@
 {
     HAL_Init();
  
-    GPIO_InitTypeDef GPIO_InitStruct;
-    __GPIOA_CLK_ENABLE();
+    __HAL_RCC_GPIOA_CLK_ENABLE();
     GPIO_InitStruct.Pin = GPIO_PIN_0;  //PA0 as interrupt test
     GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
-    GPIO_InitStruct.Pull = GPIO_PULLDOWN;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
     GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 1);
+    HAL_NVIC_SetPriority(EXTI0_IRQn, 3, 0);
     HAL_NVIC_EnableIRQ(EXTI0_IRQn);
  
- 
+     /* -2- Configure PA05 IO in output push-pull mode to
+           drive external LED */
+    GPIO_InitStruct.Pin = GPIO_PIN_5;
+    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+    GPIO_InitStruct.Pull = GPIO_PULLUP;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+    
     while (1) {
- 
-        printf("loop%d\r\n", count1);
-        wait(1);
- 
+        HAL_NVIC_DisableIRQ(EXTI0_IRQn);
+        HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
+
+        /* Insert delay 100 ms */
+        HAL_Delay(count1);
+        HAL_NVIC_EnableIRQ(EXTI0_IRQn);
  
     }
  
 }
- 
- 
+
+