S32K312 with FreeRTOS can't run normally when the task use vTaskDelay()

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K312 with FreeRTOS can't run normally when the task use vTaskDelay()

656 Views
AmyHuang666
Contributor II

Hi  team,

I've follow the user guide to add FreeRTOS to my project, but I found it couldn't run normally when the task use  vTaskDelay() to deay. But when I use PIT_Delay_Ms(), it runs ok.

The main.c is attached below. Could you please help chek why? Thank you so much~

Tags (1)
0 Kudos
Reply
3 Replies

640 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

the FreeRTOS demo example (FreeRTOS_Toggle_Led_Example_S32K312) is running normally using vTaskDelay().
Try to compare coding and setting with your project.

BR, Petr

0 Kudos
Reply

599 Views
AmyHuang666
Contributor II

Hi PetrS,

Thank you so much for your reply.

I've compared the the FreeRTOS demo example (FreeRTOS_Toggle_Led_Example_S32K312)  with my code. I found that when I create a task inside another task, than the sub-task calls vTaskDelay(), the system may crash. And when I just create a task in main without father or sub task,than calls vTaskDelay(), it will run normally. Is it a reasonable situation? 

When I use STM32 chip, this situation won't appear.

 

0 Kudos
Reply

576 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

below are possible reasons why creating a Task inside another task can cause Issues
- Stack Overflow: Each task in FreeRTOS has its own stack. If you create a task inside another task and the parent task has a small stack size, the creation process (which involves memory allocation and setup) might overflow the parent task’s stack.

- Scheduler State: If the scheduler is already running (vTaskStartScheduler() has been called), creating tasks dynamically is allowed. But if the task creation logic is flawed (e.g., creating tasks repeatedly without checking if they already exist), it can lead to memory exhaustion or undefined behavior.

- Priority and Timing: If the newly created task has a higher priority and immediately calls vTaskDelay(), it might cause a context switch that leads to unexpected behavior if the system isn't ready for it.

BR, Petr

%3CLINGO-SUB%20id%3D%22lingo-sub-2140454%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32K312%20with%20FreeRTOS%20can't%20run%20normally%20when%20the%20task%20use%20vTaskDelay()%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2140454%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%20team%2C%3C%2FP%3E%3CP%3EI've%20follow%20the%20user%20guide%20to%20add%20FreeRTOS%20to%20my%20project%2C%20but%20I%20found%20it%20couldn't%20run%20normally%20when%20the%20task%20use%26nbsp%3B%20vTaskDelay()%20to%20deay.%20But%20when%20I%20use%20PIT_Delay_Ms()%2C%20it%20runs%20ok.%3C%2FP%3E%3CP%3EThe%20main.c%20is%20attached%20below.%20Could%20you%20please%20help%20chek%20why%3F%20Thank%20you%20so%20much~%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2142583%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K312%20with%20FreeRTOS%20can't%20run%20normally%20when%20the%20task%20use%20vTaskDelay()%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2142583%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3Ebelow%20are%20possible%20reasons%20why%20creating%20a%20Task%20inside%20another%20task%20can%20cause%20Issues%3CBR%20%2F%3E-%20Stack%20Overflow%3A%26nbsp%3BEach%20task%20in%20FreeRTOS%20has%20its%20own%20stack.%20If%20you%20create%20a%20task%20inside%20another%20task%20and%20the%20parent%20task%20has%20a%20small%20stack%20size%2C%20the%20creation%20process%20(which%20involves%20memory%20allocation%20and%20setup)%20might%20overflow%20the%20parent%20task%E2%80%99s%20stack.%3C%2FP%3E%0A%3CP%3E-%20Scheduler%20State%3A%20If%20the%20scheduler%20is%20already%20running%20(vTaskStartScheduler()%20has%20been%20called)%2C%20creating%20tasks%20dynamically%20is%20allowed.%20But%20if%20the%20task%20creation%20logic%20is%20flawed%20(e.g.%2C%20creating%20tasks%20repeatedly%20without%20checking%20if%20they%20already%20exist)%2C%20it%20can%20lead%20to%20memory%20exhaustion%20or%20undefined%20behavior.%3C%2FP%3E%0A%3CP%3E-%20Priority%20and%20Timing%3A%20If%20the%20newly%20created%20task%20has%20a%20higher%20priority%20and%20immediately%20calls%20vTaskDelay()%2C%20it%20might%20cause%20a%20context%20switch%20that%20leads%20to%20unexpected%20behavior%20if%20the%20system%20isn't%20ready%20for%20it.%3C%2FP%3E%0A%3CP%3EBR%2C%20Petr%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2141280%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K312%20with%20FreeRTOS%20can't%20run%20normally%20when%20the%20task%20use%20vTaskDelay()%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2141280%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20PetrS%2C%3C%2FP%3E%3CP%3EThank%20you%20so%20much%20for%20your%20reply.%3C%2FP%3E%3CP%3EI've%20compared%20the%26nbsp%3B%3CSPAN%3Ethe%20FreeRTOS%20demo%20example%20(FreeRTOS_Toggle_Led_Example_S32K312)%26nbsp%3B%20with%20my%20code.%20I%20found%20that%20when%20I%20create%20a%20task%20inside%20another%20task%2C%20than%20the%20sub-task%20calls%20vTaskDelay()%2C%20the%20system%20may%20crash.%20And%20when%20I%20just%20create%20a%20task%20in%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3Bmain%20without%20father%20or%20sub%20task%2Cthan%20calls%20vTaskDelay()%2C%20it%20will%20run%20normally.%26nbsp%3BIs%20it%20a%20reasonable%20situation%3F%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EWhen%20I%20use%20STM32%20chip%2C%20this%20situation%20won't%20appear.%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2140614%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K312%20with%20FreeRTOS%20can't%20run%20normally%20when%20the%20task%20use%20vTaskDelay()%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2140614%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3Ethe%20FreeRTOS%20demo%20example%20(FreeRTOS_Toggle_Led_Example_S32K312)%20is%20running%20normally%20using%20vTaskDelay().%3CBR%20%2F%3ETry%20to%20compare%20coding%20and%20setting%20with%20your%20project.%3C%2FP%3E%0A%3CP%3EBR%2C%20Petr%3C%2FP%3E%3C%2FLINGO-BODY%3E