Task periodicity

I have created a project with below tasks and tested the periodicity of each task which was as expected, but when I changed the stack size of the tasks as shown in second part I observed task is not executing with fixed period.

Can you please let me know the exact root cause of the behavior and its solution.

#if 0
 /* all task executes with configured period*/
         xTaskCreate(vEv_20ms1,"Test_20ms1", 1000, NULL, 23, NULL);
         xTaskCreate(vEv_50ms1,"Test_50ms1", 100, NULL, 28, NULL);
         xTaskCreate(vEv_50ms2,"Test_50ms2", 100, NULL, 25, NULL);
         xTaskCreate(vEv_100ms1,"Test_100ms1", 100, NULL, 1, NULL);
         xTaskCreate(vEv_100ms2,"Test_100ms2", 100, NULL, 1, NULL);
         xTaskCreate(vEv_100ms3,"Test_100ms3", 100, NULL, 1, NULL);
         xTaskCreate(vEv_100ms4,"Test_100ms4", 100, NULL, 1, NULL);
         xTaskCreate(vEv_100ms5,"Test_100ms5", 100, NULL, 1, NULL);
         xTaskCreate(vEv_100ms6,"Test_100ms6", 100, NULL, 1, NULL);
         xTaskCreate(vEv_500ms1,"Test_500ms1", 100, NULL, 1, NULL);
         xTaskCreate(vEv_500ms2,"Test_500ms2", 100, NULL, 1, NULL);
         xTaskCreate(vEv_500ms3,"Test_500ms3", 100, NULL, 1, NULL);
         xTaskCreate(vEv_500ms4,"Test_500ms4", 100, NULL, 1, NULL);
         xTaskCreate(vEv_1000ms1,"Test_1000ms1", 100, NULL, 1, NULL);
         xTaskCreate(vEv_1000ms2,"Test_1000ms2", 100, NULL, 1, NULL);
 #else
 /* Task lost its periodicity*/
         xTaskCreate(vEv_20ms1,"Test_20ms1", 4000, NULL, 23, NULL);
         xTaskCreate(vEv_50ms1,"Test_50ms1", 200, NULL, 27, NULL);
         xTaskCreate(vEv_50ms2,"Test_50ms2", 500, NULL, 25, NULL);
         xTaskCreate(vEv_100ms1,"Test_100ms1", 1000, NULL, 21, NULL);
         xTaskCreate(vEv_100ms2,"Test_100ms2", 1000, NULL, 18, NULL);
         xTaskCreate(vEv_100ms3,"Test_100ms3", 200, NULL, 17, NULL);
         xTaskCreate(vEv_100ms4,"Test_100ms4", 4000, NULL, 16, NULL);
         xTaskCreate(vEv_100ms5,"Test_100ms5", 500, NULL, 15, NULL);
         xTaskCreate(vEv_100ms6,"Test_100ms6", 1000, NULL, 14, NULL);
         xTaskCreate(vEv_500ms1,"Test_500ms1", 500, NULL, 12, NULL);
         xTaskCreate(vEv_500ms2,"Test_500ms2", 400, NULL, 10, NULL);
         xTaskCreate(vEv_500ms3,"Test_500ms3", 400, NULL, 8, NULL);
         xTaskCreate(vEv_500ms4,"Test_500ms4", 1000, NULL, 6, NULL);
         xTaskCreate(vEv_1000ms1,"Test_1000ms1", 1000, NULL, 4, NULL);
         xTaskCreate(vEv_1000ms2,"Test_1000ms2", 500,  NULL, 2, NULL);
#endif

FYI
FreeRTOSConfig.h is as below

#define configUSE_PREEMPTION		  1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION	1
#define configUSE_FPU							1
#define configUSE_IDLE_HOOK			  0
#define configUSE_TICK_HOOK			  0
#define configUSE_TRACE_FACILITY	  1
#define configUSE_16_BIT_TICKS		  0
#define configCPU_CLOCK_HZ			  ( ( unsigned portLONG ) 80000000 ) /* Timer clock. */
#define configTICK_RATE_HZ			  ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES		  ( 30 )
#define configMINIMAL_STACK_SIZE	  ( ( unsigned portSHORT ) 128 )
#define configTOTAL_HEAP_SIZE		  ( ( size_t ) 250000 )
#define configMAX_TASK_NAME_LEN		  ( 16 )
#define configIDLE_SHOULD_YIELD		  1
#define configGENERATE_RUN_TIME_STATS 1
#define configUSE_MALLOC_FAILED_HOOK  0

Thanks and advance,
Kishor

Hi @Kishor,
Seeing as the stack sizes are much higher in the second part, my initial guess is that some of these tasks may not be created due to lack of memory. Have you tried checking the returns of all of your xTaskCreate calls to make sure that they are succeeding?
Best,
Jason Carroll

Can you elaborate on what you mean by this and how do you measure this?

@jasonpcarroll sure I will check task creation return value, but the total stack is still less than heap configuration (250k). MCU has total 512k.

@aggarg I am testing periodic executions by switching GPIO and observed on logic analyzer.

Regards,
Kishor

I see that you are not only changing stack sizes but also priorities. Can you keep the priorities same and check?

As mentioned in query

Case 1: Working version maximum task almost with same stack and priority
Result: Works normally
Case 2: Changed stack and priority
Result: Works with abnormal period

Case3: Changed only stack size with respect to working version
Result: Get stuck at b dataEntry

Case4: Changed only priority with respect to working version
Result: executes with expected period, normal behaviour

If its due to data exception, can you please guide me how to fix it? Its debug procedure.

heap configured is more than the total stack configured by all task and there is no function in any task so stack usage is might be around 20 30 bytes.
How can I get max stack usage by each task?

Thank you very much
Kishor

That would depend on the hardware you are using and what information it provides on a crash. Which hardware are you using? Another way could be to disable/enable tasks one by one and try to determine the culprit one.

You can use the uxTaskGetStackHighWaterMark API.