2016-04-23 02:16 PM
Good day,
If anyone tried to use FreeRTOS I have one question, why my task is not finished, and another task is started? Here is my code and log.code:void vDebug1(void *pvParameters){ vTaskDelay( 100 / portTICK_RATE_MS ); printf(''\nstart debug task1!''); for(;;) { printf(''\nDebug task1''); vTaskDelay( 250 / portTICK_RATE_MS ); }}void vDebug2(void *pvParameters){ vTaskDelay( 200 / portTICK_RATE_MS ); printf(''\nstart debug task2!''); for(;;) { printf(''\nDebug task2''); vTaskDelay( 250 / portTICK_RATE_MS ); }}void vLedBlinkBlue(void *pvParameters){ vTaskDelay( 300 / portTICK_RATE_MS ); printf(''\nvLedBlinkBlue task!''); for(;;) { STM_EVAL_LEDToggle(LED3); vTaskDelay( 1000 / portTICK_RATE_MS ); printf(''\nSTM_EVAL_LEDToggle LED1!''); }}void vLedBlinkRed(void *pvParameters){ vTaskDelay( 400 / portTICK_RATE_MS ); printf(''\nvLedBlinkRed task!''); for(;;) { STM_EVAL_LEDToggle(LED4); vTaskDelay( 500 / portTICK_RATE_MS ); printf(''\nSTM_EVAL_LEDToggle LED2!''); }}void vLedBlinkGreen(void *pvParameters){ vTaskDelay( 500 / portTICK_RATE_MS ); printf(''\nvLedBlinkGreen task!''); for(;;) { STM_EVAL_LEDToggle(LED5); vTaskDelay( 125 / portTICK_RATE_MS ); printf(''\nSTM_EVAL_LEDToggle LED3!''); }}void vLedBlinkOrange(void *pvParameters){ vTaskDelay( 600 / portTICK_RATE_MS ); printf(''\nvLedBlinkOrange task!''); for(;;) { STM_EVAL_LEDToggle(LED6); vTaskDelay( 250 / portTICK_RATE_MS ); printf(''\nSTM_EVAL_LEDToggle LED4!''); }}Debug log: Debug task1STM_EVAL_LEDToggle LED4!Debug task2STM_EVAL_LEDToggle LED3!STM_EVAL_LEDToggle LED1!STM_EVAL_LEDToggle LED3!Debug task1STM_EVAL_LEDToggle LED4!STM_EVAL_LEDToggle LED2!Debug task2STM_EVAL_LEDToggle LED3!STM_EVAL_LEDToggle LED3!Debug task1STM_EVAL_LEDToggle LED4!Debug task2STM_EVAL_LEDToggle LED3!STM_EVAL_LEDToggle LDebug task1
ED3!STM_EVAL_LEDToggle LED4!STM_EVAL_LEDToggle LED2!Debug task2STM_EVAL_LEDToggle LED3!Debug task1STM_EVAL_LEDToggle LED3!STM_EVAL_LEDToggle LED4!Debug task2STM_EVAL_LEDToggle LED3!2016-04-23 06:09 PM
FreeRTOS does (by default) pre-emptive multi-tasking.
The highest-priority active task always runs. If there are multiple active tasks of the same (highest) priority then they all take turns running, with each task running for a finite amount of time before the RTOS pauses the current task and restarts the next task from wherever it was when it was paused. This is exactly what you're seeing with the interleaved outputs of your tasks.2016-04-23 09:43 PM
Is it possible somehow to fix that?
I want that my task should be finished.2016-04-23 11:17 PM
That would not be called ''fix'': that is the way it is supposed to work.
To program what you want, you can start a task and then wait for the first task to finish before starting the next task. Or you use a semaphore. Signal the semaphore at the end of the first task wait for it in the beginning of the second task. But easiest: Just combine the code of the two tasks into one. People use tasks for things that need to run in parallel. In the simplest case, you might have a blinking led and need to handle bytes from a serial port. So you create a task for the blinking led which is very simple (toggle led, wait, repeat), while the led code would be complicated (keep time, when time to toggle the led has elapsed toggle the led. But then when your serial input requests an action that is longer, the led will stop blinking. Complicated code. This is simplified by using tasks).2016-04-24 03:14 AM
wolff.roger, turner.mark.003
Thank you for your answers.Its only an example, I wanted to play with MicroSD card, like writing 2 files at once.So i could not understand why this is happening. I will try to use semaphore. Will write about results.2016-04-25 03:33 AM
Hi
kovaliov.nikolaj
, You can manage that by usingosSignalWait()
osSignalWait() is called to wait for one or more signal flags to become signaled (set) for the current running thread. Refer to the ''FreeRTOS_signal example in thehttp://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/LN1897/PF261909
in this path :STM32Cube_FW_F7_V1.3.0\Projects\STM32756G_EVAL\Applications\FreeRTOS\FreeRTOS_Signal
-Hannibal-