0
votes

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.

1

1 Answers

1
votes

After a bit of studying on the code I found out what went wrong and would like to share with those who could face the same issue. I had several task being created inside an init task and listed before this one, lets say:

init_task() {
  id_tsk0 = os_tsk_create(task1, 50);
  id_tsk1 = os_tsk_create(task2, 40);
  id_tsk2 = os_tsk_create(task3, 30);
  //...and the task I want to call from interrupt..
  id_tskn = os_tsk_create(taskn, 254);
}

I moved taskN from the last place to the first one and..now it works!