machine resetting with two tasks PIC24 family

xintersecty wrote on Sunday, November 08, 2009:

I have been having problems with scheduler running properly. 

If I have one task (flash the led) it runs fine.  But if I add two tasks (led and uart) the machine resets at PC zero.   I set a breakpoint in the function void vTaskIncrementTick( void ) and watch the xTickCount variable.

What happens, I start the machine running it increments the xTickCount to 2 and then resets the PC down to zero and starts all over again. 

I took the standard project got it running on the demo board and stripped it down the simplest form: (croutine.c, heap_1.c, list.c, port.c, portasm_PIC24.S, queue.c, tasks.c, FreeRTOSConfig.h) I have added two additional files main.c and uart.c.

So there is something I missing in my setup to get the scheduler to run properly and being able to switch between tasks. 

I have disable the watchdog timers and brown-out resets.

Suggestions on where to look?

Here is my config info:

    #define configUSE_PREEMPTION 1
    #define configUSE_IDLE_HOOK 1
    #define configUSE_TICK_HOOK 0
    #define configTICK_RATE_HZ ( ( portTickType ) 1000 )
    #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 16000000 )  /* Fosc / 2 */
    #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 4 )
    #define configMINIMAL_STACK_SIZE ( 24 )
    #define configTOTAL_HEAP_SIZE ( ( size_t ) 512 )
    #define configMAX_TASK_NAME_LEN ( 4 )
    #define configUSE_TRACE_FACILITY 0
    #define configUSE_16_BIT_TICKS 1
    #define configIDLE_SHOULD_YIELD 1

davedoors wrote on Monday, November 09, 2009:

Is the UART interrupt priority equal to or below configKERNEL_INTERRUPT_PRIORITY?

aviasaf wrote on Monday, November 09, 2009:

try to work only with the uart task and if its also happened, its because of corruption of the uart task

and not because of 2 task that are running simultaneously   

xintersecty wrote on Monday, November 09, 2009:

At the suggestion of the UART I went and disable the UART code.  It’s really a loop to dump a character to the UART to test that the port is writing and I had not enabled the interrupts.    So I changed the task code to turn on the LED in my UART task and turn off the LED in the led Flash task. I am not addressing the UART port at all this code.

When I run two tasks, the machine does reset and the PC does reset to zero.  I am using a PIC24F16KA102.  I had a similar post that the task counter was not incrementing. 

I have gone back in the code I can see TMR1 being set as the TASK interrupt.

I think in moving the code over for this chip, I don’t have everything configured correctly so the task management is not working correctly.  Any other ideas?

xintersecty wrote on Monday, November 09, 2009:

I went and removed all my UART related code, then I added a second LED to flash in my 2nd flash task.  I built the code using one task switching between the two tasks and both versions work correctly.  The LED flash delay is different in the two tasks. 

I enable both tasks at the same time, neither one works correctly together. 

Now I have configured the task to use a small stack:
    #define configMINIMAL_STACK_SIZE ( 24 )
So it must be the way the machine is setup in the config or the port.

rtel wrote on Monday, November 09, 2009:

I’ve just looked at the demo for the PIC24 and configMINIMAL_STACK_SIZE is set to 115.  I should not set it lower than that.  I would expect and almost immediate crash with it set to 24 (unless you have stack checking switched on, in which case I would expect the stack check to almost immediately flag an error).


xintersecty wrote on Monday, November 09, 2009:

Richard and All,  I appreciate the help.  The stack size was too small.  I moved it back to the original  115 ( I had moved it smaller because of a compile issue) and my heap back to 1024.  It works correctly.  This is also the same root cause of why I was not getting the DelayUntil function working.