Scheduler is started but tasks are not executing

Hello,

I have been having this issue for a little while now, and I am not sure how to fix it. I am using a Teensy 4.1 Board, with an ARM Cortex-M7.

I am also using PlatformIO in VSCode, and I have added all files necessary for building FreeRTOS, including the port specific files, which I used from the GCC/ARM_CM4F port, which I learned that it is also compatible with the Cortex-M7.

Now, everything builds perfectly fine, but I don’t get any output from my created task. I get Serial output throughout the entire setup() of the program, but once I start the scheduler, I get nothing outputted at all.

Here is the program:

#include <Arduino.h>

extern "C"
{
#include "FreeRTOS.h"
#include "task.h"
}

void vExampleTask(void *pvParameters)
{
  for (;;)
  {
    Serial.println("Hello from FreeRTOS!");
    vTaskDelay(pdMS_TO_TICKS(1000));
  }
}

void setup()
{
  Serial.begin(9600);
  Serial.println("Creating tasks.");
  BaseType_t result = xTaskCreate(
      vExampleTask,
      "ExampleTask",
      configMINIMAL_STACK_SIZE,
      NULL,
      1,
      NULL);

  Serial.println("Ensuring tasks were created successfully.");
  configASSERT(result == pdPASS);

  Serial.println("Starting scheduler...");
  vTaskStartScheduler();
}

void loop()
{
}

And here is the FreeRTOSConfig.h:

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#include <stdint.h>

/*-----------------------------------------------------------
 * Application specific definitions.
 *
 * See http://www.freertos.org/a00110.html for configuration details.
 *----------------------------------------------------------*/

/*-----------------------------------------------------------
 * Hardware specifics.
 *----------------------------------------------------------*/
#define configCPU_CLOCK_HZ (600000000UL) /* 600 MHz for Teensy 4.1 */

/*-----------------------------------------------------------
 * Tick rate configuration.
 *----------------------------------------------------------*/
#define configTICK_RATE_HZ (100) /* 100 ticks per second = 10ms tick period */

/*-----------------------------------------------------------
 * Tick type settings.
 *----------------------------------------------------------
 * Use a 32-bit tick type by setting configUSE_16_BIT_TICKS to 0.
 * Do not define configTICK_TYPE_WIDTH_IN_BITS when using configUSE_16_BIT_TICKS.
 *----------------------------------------------------------*/
#define configUSE_16_BIT_TICKS 0

/*-----------------------------------------------------------
 * Memory allocation related definitions.
 *----------------------------------------------------------*/
#define configMINIMAL_STACK_SIZE (128)
#define configTOTAL_HEAP_SIZE ((size_t)(32 * 1024)) /* 32 KB heap */

/*-----------------------------------------------------------
 * Scheduler related definitions.
 *----------------------------------------------------------*/
#define configMAX_PRIORITIES (5)
#define configIDLE_SHOULD_YIELD 1
#define configUSE_PREEMPTION 1
#define configUSE_TIME_SLICING 1

/*-----------------------------------------------------------
 * Hook function related definitions.
 *----------------------------------------------------------*/
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0

/*-----------------------------------------------------------
 * Software timer definitions.
 *----------------------------------------------------------*/
#define configUSE_TIMERS 0

/*-----------------------------------------------------------
 * Co-routine definitions.
 *----------------------------------------------------------*/
#define configUSE_CO_ROUTINES 0

/*-----------------------------------------------------------
 * Optional functions.
 *----------------------------------------------------------*/
#define INCLUDE_vTaskDelay 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1

/*-----------------------------------------------------------
 * Cortex-M specific definitions.
 *----------------------------------------------------------*/
#ifdef __NVIC_PRIO_BITS
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 4 /* default value */
#endif

/* The lowest interrupt priority that can be used in a call to a "safe" FreeRTOS API function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15

/* The highest interrupt priority from which FreeRTOS API functions can be called (lower numbers = higher priority). */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5

/* These definitions are required to set the correct priority for the RTOS kernel and
   interrupts. */
#define configKERNEL_INTERRUPT_PRIORITY (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))
#define configMAX_SYSCALL_INTERRUPT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))

#endif /* FREERTOS_CONFIG_H */

I also tried removing the Serial print statements from the task, and just blinking the builtin LED, but that didn’t work either, so it isn’t a problem with the Serial command.

Do you have any ideas as to what could have caused this?

Thanks.

@kmfvkljsadf

Can you try increasing the stack size of the ExampleTask? For example:

  BaseType_t result = xTaskCreate(
      vExampleTask,
      "ExampleTask",
      (4 * configMINIMAL_STACK_SIZE),
      NULL,
      1,
      NULL);

@tony-josi-aws
Thanks for the response, unfortunately, no luck. Just tried and it produced the same output as before.

Instead of using serial library, can you udate the task code to maybe blink an LED?

  pinMode(LED_BUILTIN, OUTPUT);
  for (;;)
  {
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    vTaskDelay(pdMS_TO_TICKS(1000));
  }

Update LED_BUILTIN your board LED pin.

@tony-josi-aws
This didn’t provide anything either unfortunately.

Are you able to get the LED blink without using FreeRTOS?

@tony-josi-aws

Yes, I just tried to blink the LED in the setup() function of the program using the digitalWrite() function and Arduino’s delay() function, and it worked fine. This is the same program with the task that doesn’t run.

If you have a debugger attached, try to pause the execution to see what’s happening or where the code is stuck.

@tony-josi-aws

I did try this, but the PlatformIO debugger doesn’t seem to be cooperating. It doesn’t stop execution at any of my specified breakpoints, so I’m not sure how to get that working. Do you have any other ideas as to where or what could be causing this issue?

Can you just try to get a prefabbed app for the Teensy to work and work your way up from there?

@RAc

What do you mean? Just a simple app without FreeRTOS involved? Thanks.

no, that would be pointless. I was thinking about something like this here: freertos-teensy/example/blink at master · tsandmann/freertos-teensy · GitHub , assuming that it works.

@RAc
I was actually looking at this today, but there really isn’t much documentation, which is what turned me off to it. It says that it needs a custom PlatformIO framework, yet doesn’t work when implemented and there isn’t any troubleshooting or documentation resources.

Should I still try and deal with this, or is there something else you could recommend to try and fix this?

I have this strange feeling it could be something in my FreeRTOSConfig.h, how does that look to you?

You can take a look at this FreeRTOSConfig.h: iot-reference-nxp-rt1060/examples/evkbmimxrt1060/pubsub/include/FreeRTOSConfig.h at main · FreeRTOS/iot-reference-nxp-rt1060 · GitHub

The Teensy 4.1 uses the RT1060 variant (MIMXRT1062DVJ6B).

One possibility is that SysTick and PendSV handlers are not correctly installed. You can try to use the latest FreeRTOS from main which has asserts to catch such errors. Also, can you share your complete code?

Hello,

I think, you can add to freertosconfig.h configassert from Customization - FreeRTOS™. It can help you to find problem:

/* Define configASSERT() to disable interrupts and sit in a loop. */
#define configASSERT ( x )     if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }

and check in your code:

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler