Port to PIC18F8722 (extended mode)

nobody wrote on Wednesday, July 13, 2005:

Having issues porting the FreeRTOS (v3.2.0) to run on a 128k device – ie. a pic running in extended mode.  Has anyone done this and can pass on any tips?  (running latest MPLAB and mcc18)

I’ve sucessfully ported to a PIC18F8680 with no problems.



hermarcel wrote on Wednesday, July 13, 2005:

What do you mean by "extended mode"?
What problems do you have?

nobody wrote on Wednesday, July 13, 2005:

The idea is to get FreeRTOS to run on a PIC with more than 64k of flash.  I seem to have it running in non-extened mode, but this means I can’t use the extra 64k of flash for code.

The build option for the C18 compiler:
Set to "Large code model (>64k bytes)
Extended mode flag set

MPASM compiler:
extended mode flag set

The linker file (with RTOS mods):

Configuration bits:
Extended CPU enable: Enabled
Address Bus Width: 20 bit

if it’s worth anything when debugging it repeatedly executes the portSAVE_CONTEXT call.

void vPortYield( void )
    /* This can get called with interrupts either enabled or disabled.  We
    will save the INTCON register with the interrupt enable bits unmodified. */

hermarcel wrote on Wednesday, July 13, 2005:

For a moment, you got me doubting myself here :slight_smile:

I believe the word "extended" is misinterpreted here:

A device with more than 64kB flash is not a extended device in Microchip jargon. It’s just a device with more than 64 kB flash :slight_smile: . Because pointers need to extend beyond the default 16bits, the compiler needs to know this. I have briefly looked at port.c for MPLAB and it seems to be ok for these larger pointers. You should set the large memory model to use this additional flash (as you already did).

The word “extended” applies to the instruction set. By setting the “extended instruction set” fuse (XINST), a few new instructions become available. More important is that a new addressing mode is enabled, too. Because of this new addressing mode, a lot of standard instructions function in a different way, so the compiler should know this (extended mode flag). The current FreeRTOS MPLAB port will definitely not run with this changed behaviour. The best way (I think) to look at this changed behaviour is to think of the pic in extended mode as an entirely new processor. When you look at the runtime routines that are delivered with the compiler in source, you’ll find two sets of them: one for the normal pic18 and one for the extended pic18. To adapt FreeRTOS to the extended mode pic18, a new port is needed.

- Set "large memory model" to use the flash above 64kB.
- Do NOT set extended mode and do NOT set the XINST fuse. The current port does not support the changed instruction set behaviour.



ps. I did not write the MPLAB port. I did, however, write the wizC/PIC18 port.

rtel wrote on Wednesday, July 13, 2005:

Thanks Marcel for your very informative reply.  I have definitely learned something today!


hermarcel wrote on Wednesday, July 13, 2005:

Let’s hope this helps the TS :slight_smile:

nobody wrote on Wednesday, July 13, 2005:


Thanks for the info –  made the changes and it works fine!


hermarcel wrote on Wednesday, July 13, 2005:

According to Microchip, using the extended mode results in tighter and faster code. Perhaps someone can do a new port for this mode. It cannot be me as I don’t have the time and have never used MPLAB or C18…

Glad things work now! Thanks for the feedback!