FreeRTOS in Harmony project on PIC32MZEF crashes when multitasking started

racarter wrote on Tuesday, June 06, 2017:

My dev system:
PIC32MZ2048EFM064 processor on Microchip IoT eval board
MpLab X v3.60
XC C compiler v1.43
MPLab Harmony v2.03b

I have a small project which requires Ethernet and UART interfaces with TCP/IP stack.

I’ve created a project using Harmony and configured it as I think looks reasonable.
I’ve increased the total heap available to the RTOS to 200Kb and allocated 4kb to the interrupt stack.
The system task stack has 8k words allocated, the main app task stack 4K words, the TCP/IP task stack 2K words.

I’ve generated code using MHC and added no user code to the project to keep things simple.
I have 1 main app task and a second (currently empty) app task, driver libraries for USART, Ethernet and system timers in the system task, and a seperate task for TCP/IP stack. The system task is set as the highest priority (6), TCP/IP is 3 and the main app task is 2.

Every time I run the code it crashes according to the call stack at the start of _SYS_Tasks() with a run time exception when run under the debugger.

To attempt to catch the cause I’ve added the configASSERT macro to FreeRTOSConfig.h and enabled the MallocFailed and CheckForStackOverfow hooks, but none of these traps the crash in the debugger.

I assume the problem must be caused by some sort of stack/ memory usage problem, but the exact cause is not obvious and I can’t trace the call sequence to the crash other than by single stepping to find that the initialisation completes, and as soon as multitasking starts the exception occurs.

Is there something obvious that I’ve configured incorrectly?

Are there any other tricks I can use to catch the cause of the problem?

My FreeRTOSConfig.h config below:

#define configUSE_PREEMPTION                    1
#define configUSE_TICKLESS_IDLE                 0
#define configCPU_CLOCK_HZ                      ( 200000000UL )
#define configPERIPHERAL_CLOCK_HZ               ( 100000000UL )
#define configTICK_RATE_HZ                      ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES                    ( 10UL )
#define configMINIMAL_STACK_SIZE                ( 512 )
#define configISR_STACK_SIZE                    ( 2048 )
#define configSUPPORT_DYNAMIC_ALLOCATION        1
#define configSUPPORT_STATIC_ALLOCATION         0
#define configTOTAL_HEAP_SIZE                   ( ( size_t ) 204800 )
#define configMAX_TASK_NAME_LEN                 ( 16 )
#define configUSE_16_BIT_TICKS                  0
#define configIDLE_SHOULD_YIELD                 1
#define configUSE_MUTEXES                       1
#define configUSE_RECURSIVE_MUTEXES             0
#define configUSE_COUNTING_SEMAPHORES           1
#define configUSE_TASK_NOTIFICATIONS            1
#define configQUEUE_REGISTRY_SIZE               0
#define configUSE_QUEUE_SETS                    0
#define configUSE_TIME_SLICING                  0
#define configUSE_NEWLIB_REENTRANT              0
#define configUSE_TASK_FPU_SUPPORT              0

/* Hook function related definitions. */
#define configUSE_IDLE_HOOK                     0
#define configUSE_TICK_HOOK                     0
#define configCHECK_FOR_STACK_OVERFLOW          2
#define configUSE_MALLOC_FAILED_HOOK            1

/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS           0
#define configUSE_TRACE_FACILITY                0

/* Co-routine related definitions. */
#define configUSE_CO_ROUTINES                   0
#define configMAX_CO_ROUTINE_PRIORITIES         2

/* Software timer related definitions. */
#define configUSE_TIMERS                        0
#define configTIMER_TASK_PRIORITY               
#define configTIMER_QUEUE_LENGTH                
#define configTIMER_TASK_STACK_DEPTH            
#define configUSE_DAEMON_TASK_STARTUP_HOOK      0

/* Misc */
#define configUSE_APPLICATION_TASK_TAG          0

/* Interrupt nesting behaviour configuration. */

/* The priority at which the tick interrupt runs.  This should probably be kept at 1. */
#define configKERNEL_INTERRUPT_PRIORITY         1

/* The maximum interrupt priority from which API functions can be called.  
Only API functions that end in ...FromISR() can be used within interrupts. */

/* Define configASSERT() to disable interrupts and sit in a loop. */
#define configASSERT( x )     if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }

rtel wrote on Tuesday, June 06, 2017:

I’m afraid I’m not familiar enough with the code generated by Harmony.
If you have done nothing other than use Harmony to create a project that
has not been edited, and that project is failing, then you might be best
posting to the Microchip support forum as others may have seen the issue
before. If on the other hand you have added your own interrupt service
routines, or application code, then perhaps posting some of that code
would help identify the issue.