li junhao
li junhao

Reputation: 1

STM32CubeMX xTaskCreate() not scheduling on STM32F030

I have used STM32CubeMX to create a FreeRTOS task on the STM32F030 development board using the CMSIS-RTOS v2 interface, but the task I created using xTaskCreate() is not scheduling correctly, and the one I created using osTreadNew is working fine,Why is this happening?

I created two tasks using xTaskCreat()

xTaskCreate(
        LibmodbusServerTask,
        "LibmodbusServerTask",
        512,
        NULL,
        osPriorityNormal,
        NULL
    );
xTaskCreate(
        AHT20Task,
        "AHT20Task",
        512,
        NULL,
        osPriorityNormal,
        NULL
    );

There's also a default task

osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
  .name = "defaultTask",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);

Here's the simplified code for the three tasks

void AHT20Task(void *pvParameters)
{
    while (1)
    {
            //ledTask
            vTaskDelay(100);
    }   
}
void LibmodbusServerTask( void *pvParameters )
{
    //Variables, initialization, connection to modbus
    for (;;) {
        do {
            rc = modbus_receive(ctx, query);
        } while (rc == 0);
        /* The connection is not closed on errors which require on reply such as
           bad CRC in RTU. */
        if (rc == -1 && errno != EMBBADCRC) {
            /* Quit */
            continue;
        }
        rc = modbus_reply(ctx, query, rc, mb_mapping);
        if (rc == -1) {
            //break;
        }

    }
        //close modbus
    vTaskDelete(NULL);
}
void StartDefaultTask(void *argument)
{
  /* USER CODE BEGIN StartDefaultTask */
    /* Infinite loop */
    for(;;)
    {   
        vTaskDelay(500);
    }
  /* USER CODE END StartDefaultTask */
}

I'm debugging code on an STM32F030 development board. The code only enters the StartDefaultTask once at startup and then continuously runs the LibmodbusServerTask. The AHT20Task has never been entered. Next, I simply switched the task creation method and used osThreadNew() to create the task.The program now switches correctly between the LibmodbusServerTask and the AHT20Task.Here is the code to create the task

    osThreadId_t libmodbusTaskHandle;
const osThreadAttr_t libmodbusTask_attributes = {
  .name = "libmodbusTask",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
  osThreadId_t aht20TaskHandle;
const osThreadAttr_t aht20Task_attributes = {
  .name = "aht20HandleTask",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
        libmodbusTaskHandle = osThreadNew(LibmodbusServerTask, NULL, &libmodbusTask_attributes);
    aht20TaskHandle = osThreadNew(AHT20Task, NULL, &aht20Task_attributes);

This is part of my STM32CubeMX configuration. STM32CubeMX configuration sys timer

Upvotes: 0

Views: 39

Answers (0)

Related Questions