c_welch wrote on Saturday, September 27, 2014:
I’m having problems with FreeRTOS periodically reseting for no apparent reason. Even running the demo project contained in the FreeRTOS distribution shows the same problem. It will run for an hour or two and then the debugger halts showing “No user code at 0x0”
I’m using MPLAB X IDE v2.15, xc16-gcc v1.21 and ICD 3 with a dsPIC33FJ256GP710A on the Microchip Explorer 16 board. FreeRTOS version is 8.1.2.
I picked up the documentation package and ported the very simple two task example from the “Using the FreeRTOS Real Time Kernel - A Practical Guide” PIC32 edition and it shows the same reset problem after running for a while.
I’ve identified that it isn’t my hardware or MPLAB environment as the Microchip Explorer 16 demo ran for close to a day without a reset.
I added the interrupt trap file from the Explorer 16 demo which has system interrupt traps with infinite while loops for the things that cause a processor reset (E.g. address, stack, math errors) but none of the interrupts are entered when the FreeRTOS application halts.
I’ve ensured the project has the MPLAB_DSPIC_PORT definition defined in the pre processing and messages “Define C macrons” option as I saw a post that indicated the author’s resets were due to the lack of this definition.
The problem can be replicated by simply running the FreeRTOS dsPIC demo application for a while with the debugger on. You’ll find eventually the session halts.
Here is the configuration and source for the simple ported FreeRTOS that is the simplest I’ve been able to setup to replicate the problem based on the initial task logic from the FreeRTOS documentation.
Start this up with the debugger and after a few hours you’ll find the session halted and a message indicating no source code at PC 0x0:
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 0
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
#define configCPU_CLOCK_HZ ( ( unsigned long ) 25000000 ) /* Fosc / 2 */
#define configMAX_PRIORITIES ( 4 )
#define configMINIMAL_STACK_SIZE ( 240 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) 10240 )
#define configMAX_TASK_NAME_LEN ( 5 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 1
#define configIDLE_SHOULD_YIELD 1
#define configCHECK_FOR_STACK_OVERFLOW 1
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 0
#define INCLUDE_vTaskDelete 0
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define configKERNEL_INTERRUPT_PRIORITY 0x01
and the main.c:
/*
* File: main.c
* Author: cwelch
*
* Created on September 24, 2014, 9:55 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include "FreeRTOS.h"
#include "task.h"
#define mainDELAY_LOOP_COUNT (0xfffff)
/*-----------------------------------------------------------*/
void vApplicationIdleHook( void )
{
;
}
/*-----------------------------------------------------------*/
void vTask1(void *pvParameter)
{
// const char *pcTaskName = "Task 2 is running\n";
volatile unsigned long ul;
while(1)
{
for (ul = 0; ul < mainDELAY_LOOP_COUNT; ul++)
{
;
}
}
}
void vTask2(void *pvParameter)
{
// const char *pcTaskName = "Task 2 is running\n";
volatile unsigned long ul;
while(1)
{
for (ul = 0; ul < mainDELAY_LOOP_COUNT; ul++)
{
;
}
}
}
/*
*
*/
int main(int argc, char** argv)
{
//vTask1();
xTaskCreate(vTask1, "TSK1", 240, NULL, 1, NULL);
xTaskCreate(vTask2, "TSK2", 240, NULL, 1, NULL);
// Should run for ever after this
vTaskStartScheduler();
// Will only reach here if there is insufficient heap available to start the scheduler.
return (EXIT_FAILURE);
}
I have most of my application now working under FreeRTOS, but need to address this last problem of stability. It is an engine controller and I can’t have it spontaneously resetting.
Thanks in advance for your assistance!
Chris