2012-11-02 03:24 PM
Hello,
I use this example code below to get an ISR from GPIO PA0. My hardware is the STM32L152 at board STM32L152D-EVAL.
(
http://www.st.com/internet/evalboard/product/2517jsp
)So I have only one task and before I run in infinity loop, I initialise the push_button (
BUTTON_KEY
= pin PA0) with interrupt mode exti0.
Without pushing the button, I always run in the ISR again and again. Only if I push the button than does not enter the ISR more than one time.Can anybody hint me what is my mistake please?
int
main(
void
)
{
/* Ensure that all 4 interrupt priority bits are used as the pre-emption
priority. */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
/* Enable the SYSCFG module clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Create the led flash task, as described at the top of this file. */
xTaskCreate(hwCntrlTask, (
signed
char
*)
''hw_cntrl''
, mainHW_CNTRL_TASK_STACK_SIZE,
NULL, mainHW_CNTRL_PRIORITY | portPRIVILEGE_BIT, &handleHwCntrlTask);
/* Start the scheduler. */
vTaskStartScheduler();
for
(;;);
return
0;
}
typedef
enum
{
BUTTON_MODE_GPIO = 0,
BUTTON_MODE_EXTI = 1
} ButtonMode_TypeDef;
typedef
enum
{
BUTTON_KEY = 0,
BUTTON_RIGHT = 1,
BUTTON_LEFT = 2,
BUTTON_UP = 3,
BUTTON_DOWN = 4,
BUTTON_SEL = 5
} Button_TypeDef;
#define BUTTONn 6
/* On STM32L152-EVAL board, the KEY button is connected to PA.00 and it can
be use as Wakeup pin button. */
/**
* @brief Key push-button
*/
#define KEY_BUTTON_PIN GPIO_Pin_0
#define KEY_BUTTON_GPIO_PORT GPIOA
#define KEY_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOA
#define KEY_BUTTON_EXTI_LINE EXTI_Line0
#define KEY_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOA
#define KEY_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource0
#define KEY_BUTTON_EXTI_IRQn EXTI0_IRQn
/**
* @brief Joystick Right push-button
*/
#define RIGHT_BUTTON_PIN GPIO_Pin_11
#define RIGHT_BUTTON_GPIO_PORT GPIOE
#define RIGHT_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOE
#define RIGHT_BUTTON_EXTI_LINE EXTI_Line11
#define RIGHT_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
#define RIGHT_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource11
#define RIGHT_BUTTON_EXTI_IRQn EXTI15_10_IRQn
/**
* @brief Joystick Left push-button
*/
#define LEFT_BUTTON_PIN GPIO_Pin_12
#define LEFT_BUTTON_GPIO_PORT GPIOE
#define LEFT_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOE
#define LEFT_BUTTON_EXTI_LINE EXTI_Line12
#define LEFT_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
#define LEFT_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource12
#define LEFT_BUTTON_EXTI_IRQn EXTI15_10_IRQn
/**
* @brief Joystick Up push-button
*/
#define UP_BUTTON_PIN GPIO_Pin_9
#define UP_BUTTON_GPIO_PORT GPIOE
#define UP_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOE
#define UP_BUTTON_EXTI_LINE EXTI_Line9
#define UP_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
#define UP_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource9
#define UP_BUTTON_EXTI_IRQn EXTI9_5_IRQn
/**
* @brief Joystick Down push-button
*/
#define DOWN_BUTTON_PIN GPIO_Pin_10
#define DOWN_BUTTON_GPIO_PORT GPIOE
#define DOWN_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOE
#define DOWN_BUTTON_EXTI_LINE EXTI_Line10
#define DOWN_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
#define DOWN_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource10
#define DOWN_BUTTON_EXTI_IRQn EXTI15_10_IRQn
/**
* @brief Joystick Sel push-button
*/
#define SEL_BUTTON_PIN GPIO_Pin_8
#define SEL_BUTTON_GPIO_PORT GPIOE
#define SEL_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOE
#define SEL_BUTTON_EXTI_LINE EXTI_Line8
#define SEL_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
#define SEL_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource8
#define SEL_BUTTON_EXTI_IRQn EXTI9_5_IRQn
const
uint32_t BUTTON_CLK[BUTTONn] = {KEY_BUTTON_GPIO_CLK, RIGHT_BUTTON_GPIO_CLK,
LEFT_BUTTON_GPIO_CLK, UP_BUTTON_GPIO_CLK,
DOWN_BUTTON_GPIO_CLK, SEL_BUTTON_GPIO_CLK};
const
uint16_t BUTTON_PIN[BUTTONn] = {KEY_BUTTON_PIN, RIGHT_BUTTON_PIN,
LEFT_BUTTON_PIN, UP_BUTTON_PIN,
DOWN_BUTTON_PIN, SEL_BUTTON_PIN};
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {KEY_BUTTON_GPIO_PORT, RIGHT_BUTTON_GPIO_PORT,
LEFT_BUTTON_GPIO_PORT, UP_BUTTON_GPIO_PORT,
DOWN_BUTTON_GPIO_PORT, SEL_BUTTON_GPIO_PORT};
const
uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {KEY_BUTTON_EXTI_PORT_SOURCE,
RIGHT_BUTTON_EXTI_PORT_SOURCE,
LEFT_BUTTON_EXTI_PORT_SOURCE,
UP_BUTTON_EXTI_PORT_SOURCE,
DOWN_BUTTON_EXTI_PORT_SOURCE,
SEL_BUTTON_EXTI_PORT_SOURCE};
const
uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {KEY_BUTTON_EXTI_PIN_SOURCE,
RIGHT_BUTTON_EXTI_PIN_SOURCE,
LEFT_BUTTON_EXTI_PIN_SOURCE,
UP_BUTTON_EXTI_PIN_SOURCE,
DOWN_BUTTON_EXTI_PIN_SOURCE,
SEL_BUTTON_EXTI_PIN_SOURCE};
const
uint16_t BUTTON_EXTI_LINE[BUTTONn] = {KEY_BUTTON_EXTI_LINE,
RIGHT_BUTTON_EXTI_LINE,
LEFT_BUTTON_EXTI_LINE,
UP_BUTTON_EXTI_LINE,
DOWN_BUTTON_EXTI_LINE,
SEL_BUTTON_EXTI_LINE};
const
uint16_t BUTTON_IRQn[BUTTONn] = {KEY_BUTTON_EXTI_IRQn, RIGHT_BUTTON_EXTI_IRQn,
LEFT_BUTTON_EXTI_IRQn, UP_BUTTON_EXTI_IRQn,
DOWN_BUTTON_EXTI_IRQn, SEL_BUTTON_EXTI_IRQn};
/**
* @brief Configures Button GPIO and EXTI Line.
* @param Button: Specifies the Button to be configured.
* This parameter can be one of following parameters:
* @arg BUTTON_KEY: Key Push Button
* @arg BUTTON_RIGHT: Joystick Right Push Button
* @arg BUTTON_LEFT: Joystick Left Push Button
* @arg BUTTON_UP: Joystick Up Push Button
* @arg BUTTON_DOWN: Joystick Down Push Button
* @arg BUTTON_SEL: Joystick Sel Push Button
* @param Button_Mode: Specifies Button mode.
* This parameter can be one of following parameters:
* @arg BUTTON_MODE_GPIO: Button will be used as simple IO
* @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
* generation capability
* @retval None
*/
void
STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* There is no Wakeup and Tamper buttons on STM32L152-EVAL. */
/* Enable the BUTTON Clock */
RCC_AHBPeriphClockCmd(BUTTON_CLK[Button], ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Configure Button pin as input */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
if
(Button_Mode == BUTTON_MODE_EXTI)
{
/* Connect Button EXTI Line to Button GPIO Pin */
SYSCFG_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
/* Configure Button EXTI line */
EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
if
(Button != BUTTON_KEY)
{
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
}
else
{
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
}
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
4
4
4
4
/* Enable and set Button EXTI Interrupt to the lowest priority */
4
4
NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
4
4
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
4
4
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
4
4
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
4
4
4
4
NVIC_Init(&NVIC_InitStructure);
4
4
}
4
4
}
4
4
4
4
//! My task:
4
4
void
hwCntrlTask(
void
*pvParameters)
4
4
{
4
4
STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
4
4
while
(1)
4
4
{
4
4
vTaskDelay( 100 / portTICK_RATE_MS);
//! block for 100 ms
4
4
}
4
4
}
4
4
4
4
void
EXTI0_IRQHandler(
void
)
4
4
{
4
4
//Check if EXTI_Line0 is asserted
4
4
if
(EXTI_GetITStatus(EXTI_Line0) != RESET)
4
4
{
4
4
}
4
4
//we need to clear line pending bit manually
4
4
EXTI_ClearITPendingBit(EXTI_Line0);
4
4
}