I’m trying to modify FreeRTOS for Microchip PIC18F family to work with PIC18F4550 microcontroller, I got error message concerning udata_heap_1.o file, seems to me the error in the linker script that the heap is too large and can’t fit within the memory allocated to in the PIC18F4550, please if anyone faced similar problem and was able to solve it let me know.
Thanks
Actually no, I moved to another RTOS called PICos18, there is a port of it for the PIC18F4550.
However I will be interested to know how did you solve the FreeRTOS issue with the PIC18F4550.
The heap_1.c, heap_2.c, etc. files have a statically defined variable called xHeap with a big portCHAR array in them. This is where the “heap” is located. The size of the portCHAR array is determined by the configTOTAL_HEAP_SIZE (plus 4 or 8 based on portBYTE_ALIGNMENT). The static variable xHeap will be located somewhere in RAM by the linker, and must be small enough to fit in the available ram on the PIC.
The PIC18F4550 has 2048 bytes of RAM. Assuming you want to reserve bank zero for fast-access variables, Bank 1 for your stack and Bank 2 for global variables, this would leave 1280 bytes for “heap” (probably less because the PicKIT2 probably wants 10 bytes for debugging). So your configTOTAL_HEAP_SIZE should be something like 1260 or less (or much less if you have a lot of global variables).
I typically copy the default linker script (18f4550_e.lkr, etc.) into my project directory and make custom modifications to control the link process. I create a DATABANK NAME=freertos_heap and give it a specific RAM range in the linker script. Then in the heap_2.c file, just before the static declaration of xHeap, I add a line like: #pragma udata freertos_heap = 0x300 (or whatever).
I don’t see any reason why it wouldn’t. As I mentioned, I have it running on a PIC18F4682 which is fairly similar to the 4550 (which I have also used recently with no RTOS). The biggest differences with the 4682 are the increased RAM & FLASH and the substitution of the USB controller in favor of a CAN controller. Otherwise, the peripherals are basically the same, at least any that would affect the operation of FreeRTOS.
Well your linker script will depend heavily on your application. Are you using USB? If so, how much RAM does your USB solution require? The default PIC18F4550 linker script uses RAM from 0x400 - 0x7FF for USB, but you may not require this much. So you need to remove some of the DATABANK declarations to free up space for your heap. Keep as much for USB, global variables, etc as needed, then assign the rest of RAM to FreeRTOS, something like:
In this example, the FreeRTOS heap and it’s control variables occupy 0x200-0x5FF = 1K RAM. Next you need to link in one of the heap source files (heap1.c, heap2.c or heap3.c depending on your need to free memory dynamically). In the selected heap#.c file, before the declaration of xHeap, add a pragma line telling the linker to locate the variables in the freertos_heap section like so:
Next set the configTOTAL_HEAP_SIZE value in your FreeRTOSConfig.h file so it is 8 bytes less than the memory allocation size (1K in this case). It must be 8 bytes less than 1K because of the heap management variables. Of course you need to specify the actual RAM addresses (0x200 vs 0x300, etc.) and assign the memory in case you need more or less than 1K.