Task always Blocked

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.

Please post the task code. Thanks.

#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

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