# Task always Blocked

**URL:** <https://forums.freertos.org/t/task-always-blocked/9024>\
**Category:** Kernel\
**Created:** [February 20, 2020, 4:56am UTC](https://forums.freertos.org/t/task-always-blocked/9024 "2020-02-20T04:56:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fahrul](https://avatars.discourse-cdn.com/v4/letter/f/cc9497/32.png) [@fahrul](https://forums.freertos.org/u/fahrul)\
**Post date:** [February 20, 2020, 4:56am UTC](https://forums.freertos.org/t/task-always-blocked/9024/1 "2020-02-20T04:56:20Z")

</div>

Hello, I have a problem about my FreeRTOS on STM32L476RG. I created two tasks, after I run this task, it is only run once, and then this task blocked. After I print from vTaskList I get return data like this,

* * *

Task State Prio Stack Num

* * *

IDLE X 0 8 3  
base1 B 2 86 2  
base2 B 1 102 1  
Tmr Svc B 2 221 4

* * *

So, where it is wrong?  
Thank you.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 20, 2020, 6:08am UTC](https://forums.freertos.org/t/task-always-blocked/9024/2 "2020-02-20T06:08:03Z")

</div>

Please post the task code. Thanks.

---

<div class="post-metadata">

**Author:** ![fahrul](https://avatars.discourse-cdn.com/v4/letter/f/cc9497/32.png) [@fahrul](https://forums.freertos.org/u/fahrul)\
**Post date:** [February 20, 2020, 7:58am UTC](https://forums.freertos.org/t/task-always-blocked/9024/3 "2020-02-20T07:58:37Z")

</div>

```auto
#define EXTERNAL_CLOCK
#include "main.h"
TaskHandle_t pMyTask ;
char ptrTaskList[250];
static void p1 (void *pvParameters ){
  while(1){

    if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )

    {

    SerialUSB.println("W");

    xSemaphoreGive( xSerialSemaphore );

    }

    vTaskDelay(1);

  }

}

static void p2 (void *pvParameters ){

  while(1){

   if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )

    {

    SerialUSB.println("S");

    xSemaphoreGive( xSerialSemaphore );

    }

    vTaskDelay(1);

  }

}

void setup() 

{

  base_core::setup();

  interface::setup();

  

  // Now set up two Tasks to run independently.

  if ( xSerialSemaphore == NULL ) // Check to confirm that the Serial Semaphore has not already been created.

  {

    xSerialSemaphore = xSemaphoreCreateMutex(); // Create a mutex semaphore we will use to manage the Serial Port

    if ( ( xSerialSemaphore ) != NULL )

      xSemaphoreGive( ( xSerialSemaphore ) ); // Make the Serial Port available for use, by "Giving" the Semaphore.

  }

  

   xTaskCreate(

    p1

    , (const portCHAR *)"base2" // A name just for humans

    , 128 //configMINIMAL_STACK_SIZE // This stack size can be checked & adjusted by reading the Stack Highwater

    , NULL

    , 1 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.

    , NULL );

    xTaskCreate(

    p2

    , (const portCHAR *)"base1" // A name just for humans

    , 128 //configMINIMAL_STACK_SIZE // This stack size can be checked & adjusted by reading the Stack Highwater

    , NULL

    , 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.

    , &pMyTask );

  vTaskList(ptrTaskList);

    Serial.println(F("Task State Prio Stack Num")); 

    Serial.print(ptrTaskList);

  SerialUSB.flush();

  // start scheduler

  vTaskStartScheduler();

  while(1);
}

void loop() 
{
  vTaskList(ptrTaskList);
  Serial.println(F("Task State Prio Stack Num"));
  Serial.print(ptrTaskList);
  SerialUSB.flush();
  delay(2000);
}

```

This is my code to test task. but this task only run once and then i check task state is blocked. Thank you

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 20, 2020, 3:24pm UTC](https://forums.freertos.org/t/task-always-blocked/9024/4 "2020-02-20T15:24:46Z")

</div>

Everything looks as expected until the loop() function at the bottom. What is that?  
Have you tried without the USB output - do the tasks continue to run then?  
Do you have configCHECK\_FOR\_STACK\_OVERFLOW set to 2, as recommended during development and debug here: [https://www.freertos.org/FAQHelp.html](https://www.freertos.org/FAQHelp.html)
