Quality RTOS & Embedded Software

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


Loading

PIC32 FreeRTOS Bus Error(IFETCH)

Posted by Andrew P. Lentvorski, Jr. on January 31, 2010
I'm using FreeRTOS 6.0.2, the PIC32 USB Starter board, MPLAB 8.43, and C32 1.10.

Execution is fine up through the call to vTaskStartScheduler(). The tasks all run just fine.

However, if all of the FreeRTOS tasks terminate, the system throws a Bus Error(IFETCH) exception. Sadly, no exception address is given.

vTaskStartScheduler() sits in an infinite loop if you never give it any tasks at all, so I presume this is something chasing a NULL (or misaligned) pointer after things get deleted from some internal queue.

RE: PIC32 FreeRTOS Bus Error(IFETCH)

Posted by Dave on January 31, 2010
Can you explain what you are doing in more detail? Why would the tasks terminate? Why would you call vTaskStartScheduler() without creating at least one task first?

RE: PIC32 FreeRTOS Bus Error(IFETCH)

Posted by Andrew P. Lentvorski, Jr. on February 8, 2010
Taking these in reverse order:
“Why would you call vTaskStartScheduler() without creating at least one task first? ”


This was just to see what vTaskStartScheduler would do when faced with no tasks. I was looking to see if the exception would fire even with no tasks. It does not, so the data structures are consistent even with no tasks initially. And vTaskStartScheduler() sits in an infinite loop. I am a bit surprised by that--I would have expected it to simply return.

Why would the tasks terminate?


In my case, it was not intentional. I had a bug in my tasks that was causing them to terminate. The *PROBLEM* was that I couldn't diagnose that my tasks were terminating because FreeRTOS caused that BUS ERROR(IFETCH) exception which smashed any useful diagnostic information.

Presumably, something doesn't clean up properly when all tasks terminate. I suspect that there is an old stack lying around or a NULL pointer in some scheduling queue that gets followed.

This gives me some concern because I am going to want to be able to use a bootloader to overwrite the flash on this at some point. It would be nice to have a clean way of shutting down FreeRTOS, moving back to a small bootloader, updating the flash, and then reactivating FreeRTOS.


RE: PIC32 FreeRTOS Bus Error(IFETCH)

Posted by Richard on February 8, 2010
“This was just to see what vTaskStartScheduler would do when faced with no tasks. I was looking to see if the exception would fire even with no tasks. It does not, so the data structures are consistent even with no tasks initially. And vTaskStartScheduler() sits in an infinite loop. I am a bit surprised by that--I would have expected it to simply return.”



The scheduler will create the idle task, then run the idle task. I presume the infinite loop you mention is in fact the idle task.


“In my case, it was not intentional. I had a bug in my tasks that was causing them to terminate. The *PROBLEM* was that I couldn't diagnose that my tasks were terminating because FreeRTOS caused that BUS ERROR(IFETCH) exception which smashed any useful diagnostic information.”


...and it was FreeRTOS that was causing that, right? Not the bugs in your tasks.


“Presumably, something doesn't clean up properly when all tasks terminate. I suspect that there is an old stack lying around or a NULL pointer in some scheduling queue that gets followed.”


Terminate how? The only was to terminate a task is by calling vTaskDelete(), in which case things are cleaned up. If you crash tasks and trash data structures in a system that is not using an MMU or MPU then there is no magic the kernel can do to carry on regardless.


Regards.

RE: PIC32 FreeRTOS Bus Error(IFETCH)

Posted by Andrew P. Lentvorski, Jr. on February 12, 2010
“...and it was FreeRTOS that was causing that, right? Not the bugs in your tasks.”


Yes. Nothing in the tasks were throwing an exception. They simply exited their infinite loop and returned.

“Terminate how? The only was to terminate a task is by calling vTaskDelete(), in which case things are cleaned up. If you crash tasks and trash data structures in a system that is not using an MMU or MPU then there is no magic the kernel can do to carry on regardless.”


The tasks didn't "crash". They just exited. Basically I had three tasks like this:


void task(void *pvParameters) {
int flg;

while (flg) {
flg = FALSE; // Unintentionally
}
}


Once all the tasks returned, the IFETCH got thrown.

Continuing to run the idle task is acceptable behavior as I could have queried things about the tasks and discovered that they were not running. Returning cleanly from vTaskStartScheduler() would also be acceptable as I would have wondered how execution got there and could have checked what was going on.

Getting into a state where *FreeRTOS* throws an IFETCH and blows away all of my diagnostic information is not useful behavior.


RE: PIC32 FreeRTOS Bus Error(IFETCH)

Posted by Dave on February 12, 2010
“The only was to terminate a task is by calling vTaskDelete()”


This is the important line in Richards post. Take note of it and your application will not crash, ignore it and it will. If you want tasks to simply exit their infinite loop then you must put a vTaskDelete(NULL) at the end of the function that implements a task.


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


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

Xilinx Microblaze and Zynq partner