Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

GCC/ARM_CM3 port locks up during init

Posted by Rod on March 27, 2012
I'm using the GCC/ARM_CM3 port of version 7.1.0. My startup code creates tasks and other FreeRTOS objects, and does much other initialization before calling vTaskStartScheduler. It's locking up during the init. I think the heap_2 memory allocation is attempting to invoke the scheduler before it starts. I believe it goes something like this:

I call xTaskCreate (or create a queue or whatever), which calls pvPortMalloc in heap_2.c. This calls xTaskResumeAll.

Because other tasks have already been created, xTaskResumeAll manages the ready/pending list and possibly sets xYieldRequired. I suspect it is then calling portYIELD_WITHIN_API, which calls vPortYieldFromISR and invokes a context switch before I've called vTaskStartScheduler. The application locks up.

I think it might work if I were to somehow make sure that interrupts can never be enabled before the scheduler starts. Instead, I worked around it by creating just one task, starting the scheduler, and doing the rest of my init within the task.

Is this "expected" behavior, or should I have been able to do all my initialization before the scheduler starts?

RE: GCC/ARM_CM3 port locks up during init

Posted by Richard on March 28, 2012
“I think the heap_2 memory allocation is attempting to invoke the scheduler before it starts. I believe it goes something like this:

I call xTaskCreate (or create a queue or whatever), which calls pvPortMalloc in heap_2.c. This calls xTaskResumeAll.”


xTaskResumeAll() will not attempt a context switch if the scheduler has not started. It will attempt a context switch only if either tick interrupts have been missed while the scheduler was suspended, or tasks were placed into the pending ready list while the scheduler was suspended - but there will be no ticks if the scheduler has not started, and kernel API functions that unblock a task should not be executed before the kernel is started, so neither of these conditions can be true.

However...if you have interrupts enabled at this point, and an interrupt executes, and the interrupt itself does something to the kernel, then you will definitely have problems.

The kernel itself will keep interrupts disabled from the point the first API call is made to the point that the scheduler is started. Are you manually enabling interrupts anywhere?

Regards.

RE: GCC/ARM_CM3 port locks up during init

Posted by Rod on April 3, 2012
Thank you for your response.

I am using interrupts before the scheduler starts, but I make sure that the interrupt handler does not call any rtos API before I start the scheduler. I overlooked the fact that the API calls to create tasks, etc. were themselves disabling interrupts and not reenabling them if the scheduler has not yet started. So my interrupts did not trigger, and that's why my app was locking up.

I explicitly reenabled interrupts after making API calls prior to starting the scheduler, and now my code works. However, I think it will make more sense to start the scheduler earlier and do most of my other initialization from a task, rather than trying to do things that require interrupts before I start the scheduler. Now that I see how it works, it makes sense to me.

Thanks for your assistance! :-)


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS