Quality RTOS & Embedded Software

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


How to write Port.c in FreeRTOS

Posted by jj1010 on October 11, 2014

I create a new project use port.c file which in the Demo project, and run sucessful with STM32 microcontroller. Now I want to write port.c file, how can I get technical support about writting port.c file, or which tutorial can help me. I find nothing in FreeRTOS website, only simply descriptioins. http://www.freertos.org/FreeRTOS-porting-guide.html.

Hope you help! Thanks.

How to write Port.c in FreeRTOS

Posted by rtel on October 11, 2014

Which target do you want to create the port for?


How to write Port.c in FreeRTOS

Posted by jj1010 on October 12, 2014

ARM Cortex-M3 architecture. I know there preparation of a good port.c in Demo Project.

If there is a language to express the meaning is not clear, ask me. My mother tongue is not English.

How to write Port.c in FreeRTOS

Posted by rtel on October 12, 2014

The Cortex-M3 port will run on all Cortex-M3 device, from all manufacturers - you do not need to write a port.c if you want to run on a Cortex-M3.

To use a Cortex-M3 or a Cortex-M4 without FPU use the files in: FreeRTOS/Source/portable/[compiler]/ARM_CM3

To use a Cortex-M4 with an FPU use the files in: FreeRTOS/Source/portable/[compiler]/ARM_CM4F


How to write Port.c in FreeRTOS

Posted by jj1010 on October 13, 2014

But I really would like to write port.c file.

And if I use a new architecture microcontroller which FreeRTOS does not support, how can I do?

How to write Port.c in FreeRTOS

Posted by davedoors on October 13, 2014

Look in portable.h, the functions that are defined in there need to be implemented in port. There are lots of port.c files you can use as examples.

The first thing you will need to do is work out what makes up the architecture context. List out the registers, and decide how they will be placed on the stack. The architecture will dictate some of that if some registers are pushed on to the stack manually.

Once you have a function that creates the starting stack for a task, create a function that starts the first task. Again there are lots of examples, and how it can be done is dictated by the architecture. Sometimes a simple function call is all that is needed, but sometimes a software trap is needed. The function moves the stack pointer to the start of the stack created for the task, then pops the registers off the stack into the architecture registers until finally it pops the program counter. The program counter will hold the address of the task function, so popping that address into the program counter will result in a jump to the start of the task.

Then you need to work out how you are going to switch between tasks. But one thing at a time.

There are some old pages here http://www.freertos.org/implementation/main.html

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

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

Latest News

Version 10.1.0 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.


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


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