Hello Forum,
I am trying go handle a receive Interrupt on STM32F411 Eval board using the FreeRTOS API. However,
xSemaphoreGiveFromISR
is the API that is causing the problem. When the interrut occurs, i.e when the Rx line receives a character from user, the program freezes, remains stuck until Reset. If i do not use the FreeRTOS APIs for ISR , the Rx Interrupt works, please see code below. So i know the Interrupt is working, when i turn
USE_FREERTOS_ISR_API
in my code off and i can see the received byte on my terminal program. Also i have referred to chapter 6 of the FreeRTOS handson guide manual regarding Interrupt management.
void USART2
IRQHandler(void)
{
#ifndef USEFREERTOS
ISRAPI
if (USART
GetITStatus(USART2, USARTIT
RXNE))
{
RxCplt
flag =1
Recvdword = USART
ReceiveData(USART2);
USARTClearITPendingBit(USART2, USART
ITRXNE);
}
#else /*Freertos APIS are used*/
static BaseType_t xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR( xBinarySemaphore, &xHigherPriorityTaskWoken );
//xSemaphoreGive(xBinarySemaphore);
taskENTER_CRITICAL() ;
if (USART_GetITStatus(USART2, USART_IT_RXNE))
{
Recvd_word = USART_ReceiveData(USART2);
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
}
if ( xHigherPriorityTaskWoken != pdFALSE )
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
taskEXIT_CRITICAL();
#endif
}
`
I have created two other tasks which are running fine. Here are my sample task functions,
~~~
int main(void)
{
SystemInit();
init_USART2();
init_led_gpios();
enable_usart2_irq();
xBinarySemaphore = xSemaphoreCreateBinary();
// Create a task
// Stack and TCB are placed in CCM of STM32F4
// The CCM block is connected directly to the core, which leads to zero wait states
if( xBinarySemaphore != NULL )
{
xTaskCreateStatic(vTask1_print, "task1_print", TASK1_STACK_SIZE, NULL, 5,
printTask1_Stack, &Task1Buff);
xTaskCreateStatic(vTask2_print, "task2_print", TASK2_STACK_SIZE, NULL, 1,
printTask2_Stack, &Task2Buff);
ifdef USEFREERTOSISR_API
xTaskCreateStatic(vTask_ISR_Handler, "task3_isr", TASK3_STACK_SIZE, NULL, 2,
printTask3_Stack, &Task3Buff);
endif
USART_TX_string("Starting scheduler...rn");
vTaskStartScheduler(); // should never return
}
while (1)
{}
}
void vTask1_print(void* p)
{
while (1)
{
USART_TX_string("Task1...rn");
ifndef USEFREERTOSISR_API
if (Rx_Cplt_flag == 1)
{
USART_TX_byte(Recvd_word);
Rx_Cplt_flag = 0;
}
endif
vTaskDelay(500);
}
vTaskDelete(NULL);
}
void vTask2_print(void* p)
{
while (1)
{
toggle_leds();
vTaskDelay(1000);
}
vTaskDelete(NULL);
}
void vTask
ISRHandler(void *p)
{
while(1)
{
xSemaphoreTake(xBinarySemaphore, 10000);
USART_TX_byte(Recvd_word);
vTaskDelay(5000);
}
}
~~~