alexgamo wrote on Monday, June 08, 2015:
Dear all,
I’m trying to use FreeRTOS 6.0.4 on an STM32F3 Discovery Board,
but I encounter some problems.
I want to give a mutex by ISR when I receive a CAN bus message, to wake up another task.
I have a second task which permit a LED to blink.
My problem is before the CAN trame is received, the program runs normally, and I see the LED blinks.
But when a CAN trame arrives, the ISR wakes up and the program blocks in it.
Tasks are stop running, and the LED stops to blink.
Sending and receiving CAN trames are working without use of ISR, only problem is when I try to use ISR.
I thought the problem is because of I set wrong priorities but it seems OK for me…
Here’s a part of code in FreeRTOSConfig.h :
:::C
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( ( unsigned long ) 72000000 )
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 10 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 128 )
#define configMAXIMAL_STACK_SIZE ( ( unsigned short ) 8192)
#define configTOTAL_HEAP_SIZE ( 30000 )
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
...
#define configKERNEL_INTERRUPT_PRIORITY 255 // 15
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 191 // 11
The function below is used to configure ISR parameters :
:::C
void CAN_init_IT(void){
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 13;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
}
The ISR and the associated task, and the main function, are here :
:::C
xSemaphoreHandle ACK_message_CAN;
xSemaphoreHandle message_CAN;
void USB_LP_CAN1_RX0_IRQHandler(void) {
long yield = 0;
xSemaphoreGiveFromISR(message_CAN, &yield);
// Only use to debug
/*GPIO_SetBits(GPIOE, GPIO_Pin_11 | GPIO_Pin_10 | GPIO_Pin_9 | GPIO_Pin_8);
vTaskDelay(250);
GPIO_ResetBits(GPIOE, GPIO_Pin_11 | GPIO_Pin_10 | GPIO_Pin_9 | GPIO_Pin_8);
vTaskDelay(250);*/
portEND_SWITCHING_ISR(yield);
}
void RX_CAN(void *p)
{
CAN_init();
CAN_init_IT();
CanRxMsg RxMessage;
RxMessage.Data[0] = 0;
while(1)
{
if(xSemaphoreTake(message_CAN, (portTickType)0 ))
{
CAN_Receive(CAN1, CAN_FIFO0, &RxMessage);
if(RxMessage.Data[0] == 0x05)
{
...
}
}
}
}
int main()
{
SystemInit();
SystemCoreClockUpdate();
// SysTick end of count event each 1ms
RCC_ClocksTypeDef RCC_Clocks;
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
...
vSemaphoreCreateBinary(message_CAN); // Create the semaphore
xSemaphoreTake(message_CAN, 0); // Take semaphore after creating it.
xTaskCreate(RX_CAN,(signed char *) "receive_CAN_task", 20*configMINIMAL_STACK_SIZE, NULL, 1, NULL);
xTaskCreate(Blink, (signed char *) "blink", 20*configMINIMAL_STACK_SIZE, NULL, 1, NULL);
vTaskStartScheduler();
while(1); // the program should never comes here
return -1;
}
Maybe I forgot something ?
I searched in this forum before to post but I didn’t find anything.
Sorry for this long post and my bad English, I’m a french student.
Thanks for your help.