I've been using FreeRTOS for a while now on my project and I have to say I love it.
Tough i'm facing a bug which is killing me.
My code contains a large amount of code, about 80 files and use several microchip stack and run about 10 tasks.
The problem is that about 2-3 times a day, the chip will go into an address error interrupt and I haven't really been able to find out what was the source of the problem.
I believe that this error occur at the moment of an interrupt because I've been able to reduce the occurrence of the crash be using DMA transfer in one UART which reduce the interruption by a factor of 80.
I've been reading a lot of example and and forum thread about it, but it seem to always have different approach about how to handle interrupt, whether use or not the taskYield, specifically on the PIC24EP.
An other point is the interrupt nesting. It is currently enabled and I haven't tested disabled. I've seen some thread about it without really an answer whether it should be kept enable or not.
This is the way I'm currently handling my DMA interrupt. I use a queue instead of a semaphore for previous code compatibility bot it does the same job.
void attribute((interrupt, auto_psv)) _DMA1Interrupt(void)
{
char val = 55;
IFS0bits.DMA1IF = 0; // Clear the DMA1 Interrupt Flag
xQueueSendFromISR( RS485_Queue, &val, NULL );
}
Some example from the RTOS library shows no task yield after the interrupt.
Shall I add the yield into each interrupt ?
void attribute((interrupt, auto_psv)) _DMA1Interrupt(void) { char val = 55; portBASE_TYPE xTaskWoken; IFS0bits.DMA1IF = 0; // Clear the DMA1 Interrupt Flag xQueueSendFromISR( RS485_Queue, &val, &xTaskWoken); if( xTaskWoken ) taskYIELD(); }
Shall I disable Nested interrupt ?
Shall I add more stack space in my tasks ?
I'm not a specialist of processor stack and the way RTOS works at the stack level. If two interrupt happens at the same time then the current running task would need bigger stack size ? Might my problem be related of having two interrupt (or more) at the same time and having nested interrupt use more task space than it is actually defined ?
Thanks!
Edit: Problem solved, and seem actually I'm not the only one to have gone into that problem as unfortunately it doesn't seem to appear on the documentation or the code example but only in some webpage of freertos that needs to be dug up. The interrupt using FreeRTOS Kernel should not have a priority higher than the configKERNEL_INTERRUPT_PRIORITY which has default value of 1, while interrupt on microchip have default value of 3. This means using interrupt at their default priority level will lead to sporadic trap error.