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


PIC18F Fixes for heap, context bugs

Posted by Dennis Lambe Jr. on April 3, 2012
The PIC18F port in FreeRTOS has long had two bugs that make it unfit for reliable production use. One is a linker script which permits sections containing C variables to cross bank boundaries. The other is the built-in assumption that the .tmpdata and MATH_DATA sections won't change size, which they do often both as a project evolves and between compiler versions.

This patch, made against FreeRTOSV7.1.0, contains both of my fixes.


A complete write-up of the issues involved and how my patch fixes them can be read here:


This patch also contains a small fix for the PIC18F demo projects because they do not compile cleanly since V7.0.0.

Since V7, FreeRTOS and C18 both define a header named "timers.h". The PIC18F ports.c includes "timers.h" from the Microchip libraries for the OpenTimer1 function and associated definitions. Because of this, the FreeRTOS PIC18F demos don't compile in FreeRTOS V7 as the Microchip "timers.h" is shadowed by the FreeRTOS header.

In order to make sure the demos compile, I have changed the order of the include paths in their Project Build Options to prioritize Microchip's headers above FreeRTOS's. This is sufficient to compile the demos, but in order to compile projects that use the FreeRTOS timers module a more complete solution will have to be devised.

RE: PIC18F Fixes for heap, context bugs

Posted by Richard on April 3, 2012
Thank you for your input. I will take a look at your files.

[The PIC18 port has long been noted as, and de-emphasised because, it has these issues. I think the issues have been documented, but not changed in the main line code. This will change soon because of other developments that use this port, and the desire to add in a PIC18 extended mode demo. Generally though, the PIC18 is not a good architecture for a pre-emptive kernel]


RE: PIC18F Fixes for heap, context bugs

Posted by Dennis Lambe Jr. on April 3, 2012
Thanks for taking a look at my code. I hope it proves useful.

PIC18 wasn't the ideal platform for implementing a FreeRTOS project, and I wouldn't have used it if we didn't already have an existing FreeRTOS project that needed to be ported to PIC18. That being said, for our application it wound up working well and reliably once these fixes were in place.

I have a small patch that makes the interrupt vector easier to extend without modifying port.c. If it has a shot at inclusion I'd be happy to upload that as well.

RE: PIC18F Fixes for heap, context bugs

Posted by Richard on April 4, 2012
Yes I would be interested in that too. I would be grateful if you could post both pieces of code to the FreeRTOS Interactive site. There is a Microchip page here:


RE: PIC18F Fixes for heap, context bugs

Posted by Dennis Lambe Jr. on April 4, 2012

This patch adds a configuration define, configPORT_USER_ISR_VECTOR, that can be set to the name of a function that handles vectoring to non-OS interrupts.

This function (interrupts.c:vUserInterruptVector in the Demo projects) is limited in what instructions it can execute, since it cannot alter the values of any registers. As long as the pattern established in the Demo example is followed, this is an easy requirement to satisfy.

This patch is independent of my other, but doesn't quite apply cleanly on top of it. So I've also made a single patch file that combines both:


I'll post the combined patch to Interactive as well.

RE: PIC18F Fixes for heap, context bugs

Posted by Dennis Lambe Jr. on April 4, 2012
Posted to FreeRTOS Interactive: http://interactive.freertos.org/entries/21224772-pic18f-heap-and-context-fixes-modular-interrupt-handling

[ 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