Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists