Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 1 month ago.
STM32 F4 401RE - interrupt EXTI same code: MBED stop, coide working!
mbed EXTI not working and then i try coide for compare and finding problem
test make blink led more fast when detect interrupt:
- with mbed when interrupt is detect blink led is stop
- with coide when interrupt is detect led blink fast with no problem
Note
- SystemClock_Config(); not working with mbed
COIDE CODE:
COIDE CODE:
#include "stm32f4xx_hal.h" #include "stm32f4xx_nucleo.h" static GPIO_InitTypeDef GPIO_InitStruct; static void SystemClock_Config(void); static void Error_Handler(void); int16_t count1 = 1000; void EXTI0_IRQHandler(void) { 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 = 100; } } int main() { HAL_Init(); SystemClock_Config(); __HAL_RCC_GPIOA_CLK_ENABLE(); //__GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_0; //PA0 as interrupt test GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FAST; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 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) { HAL_NVIC_DisableIRQ(EXTI0_IRQn); HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); HAL_Delay(count1); HAL_NVIC_EnableIRQ(EXTI0_IRQn); } } static void SystemClock_Config(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; /* Enable Power Control clock */ /* Enable HSI Oscillator and activate PLL with HSI as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = 0x10; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLM = 16; RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; RCC_OscInitStruct.PLL.PLLQ = 7; if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } } static void Error_Handler(void) { while(1) { } }
--------------------
MBED CODE
MBED CODE
#include "mbed.h" #include "stm32f4xx_hal.h" #include "stm32f4xx.h" #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); { /* 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 = 100; } } int main() { HAL_Init(); __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_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FAST; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 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) { HAL_NVIC_DisableIRQ(EXTI0_IRQn); HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); HAL_Delay(count1); HAL_NVIC_EnableIRQ(EXTI0_IRQn); } }