I'm working on a project on a STM32F1x board with RTX RTOS and I need some external interrupt to work with some user input. For this reason I enabled an external interrupt to work with an input on pin A.0.
/* Handle PA0 interrupt: user input */
__irq void EXTI0_IRQHandler(void) {
/* Make sure that interrupt flag is set */
if (EXTI_GetITStatus(EXTI_Line0) != RESET) {
isr_evt_set(0x0003, task1);
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
__task void task1(void) {
OS_RESULT result;
unsigned int i;
while(1) {
result = os_evt_wait_or(0x0003, 0xFFFF);
if (result == OS_R_TMO)
{
// event not received
counter--; // variable used for debugging purposes
}
else
{
// event received
counter++;
}
}
However, whenever I give input to the GPIOA.0 pin I get a strange behaviour that can be seen in the logic analyzer (all the other periodic tasks stop executing and go flatline). EDIT: To give further informations: This code works with LED toggling code put inside the handler.
Here's my GPIO/EXTI configuration
void Configure_PA0(void) {
/* PA0 */
GPIO_InitTypeDef GPIO_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
/* Enable clock for GPIOA */
/* Enable clock for GPIO */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* Set pin 0 as input */
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Tell system that you will use PDn for EXTI_Line n */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource);
/* PA0 is connected to EXTI_Line0 */
EXTI_InitStruct.EXTI_Line = EXTI_Line0;
/* Enable interrupt */
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
/* Interrupt mode */
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
/* Triggers on rising and falling edge */
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
/* Add to EXTI */
EXTI_Init(&EXTI_InitStruct);
/* Add IRQ vector to NVIC */
/* PA0 is connected to EXTI_Line0, which has EXTI0_IRQn vector */
NVIC_InitStruct.NVIC_IRQChannel = EXTI0_IRQn;
/* Set priority */
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x00;
/* Set sub priority */
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x00;
/* Enable interrupt */
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
/* Add to NVIC */
NVIC_Init(&NVIC_InitStruct);
}
What I'm doing wrong? Thanks to whoever is going to help me with this.