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

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 ]    [ 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