Multiple Tasks with UART ISR

My program has 3 tasks with the RTOS set in co-operative mode on an STM32 device. Also I have a UART interrupt callback that handles buffering incoming UART packets. My program works when only one thread is active, but when I include all three threads the program hangs in vPortRaiseBASEPRI trying to set ulNewBASEPRI. My program looks like so, removing any non-RTOS related segments:

// ------------ START CODE -----------------
osThreadId defaultTaskHandle;
osThreadId Task1Handle;
osThreadId Task2Handle;

static void MX_USART1_UART_Init(void);

void StartDefaultTask(void const * argument);
void Task1(void const * argument);
void Task2(void const * argument);

int main(void) {


osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

osThreadDef(Task1_1, Task1, osPriorityNormal, 1,512);
Task1Handle = osThreadCreate(osThread(Task1_1), NULL);
Task2Handle = osThreadCreate(osThread(Task2_1),NULL);

HAL_UART_Receive_IT(&huart2,(uint8_t *) Rx_buff2,6);


while(1) {};

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { 
// does something 

void Task1(void const * arguments) {
for(;;) {
// does something else
void Task2(void const * arguments) {
for(;;) {
// does something else
void StartDefaultTask(void const * argument) {
for (;;) {
// does something else

// ------------ END CODE -----------------

I’ve attempted to trace failed assertions, however no filename nor line number where given when the assert_failed function is reached.

Also, I’ve noticed that the program will actually kind of run when the StartDefaultTask main thread creates the other two threads itself instead of creating them in the main function. When I have it set up that way, the UART interrupts work and the main thread works, but the other two tasks never start.

Please let me know what horrible RTOS atrocities I’ve committed with my code.


Which I’m going to guess is an assertion failure.

Seems my guess was right :wink:

If you are failing an assertion in this function it is likely because the interrupt priorities are not configured correctly. The newer the version of FreeRTOS the more information you will get about failed assertions.

You can defined configASSERT() to give you a line number - see the documentation here:

Setting interrupt priorities on Cortex-M is quite complex:

On STM32 there is an additional requirements as noted by the red text on the above linked page.

Oh excellent! I followed the link you included to enable configASSERT. I found out that FreeRTOS didn’t not have enough heap allocated for my threads. I increased both the minimum heap size of the STM32 board and the FreeRTOS heap and that solved the problem!

Thanks so much for the help!