FreeRTOS implementation strategy

Hello, I have recently started working with SAM4S Xplained board and now would like to start with FreeRTOS on this board. What I need to do now is rather than using ASF wizard to port FreeRTOS I want to include all the necessary FreeRTOS files from the latest v8.0.1 downloaded directory to my project in Atmel Studio and remove any and all dependencies on ASF so to have much more understanding of the whole system and flexibility. I want to know what would be the best starting point for this task should I start with a basic FreeRTOS example available in Atmel Studio or should I directly start looking into FreeRTOS directory? Thank you for any help and guidance.

FreeRTOS implementation strategy

The following page describes how to create a FreeRTOS FreeRTOS project from scratch: http://www.freertos.org/Creating-a-new-FreeRTOS-project.html Also, there are several FreeRTOS projects for Atmel Studio in the FreeRTOS download. I don’t think any of them use the ASF for anything other than peripheral drivers. Older Atmel Studio projects use a batch file to copy the FreeRTOS files from their normal place in the FreeRTOS directory structure into the local project folder – if you run one of those batch files you will see exactly which FreeRTOS related files are copied and you can use that exact structure in your project. If you look through the Atmel projects ( http://www.freertos.org/a00090.html#ATMEL ) you will see the ones using Atmel Studio, then view the build instructions for the projects to see if they are using a batch file to copy the files or not. Then just go an run one of the batch file (or look at what the batch file is doing). Newer Atmel Studio projects select the files to build using virtual links to the files in Atmel Studio, rather than copying the files locally, so they will be less useful for you purposes. Regards, Richard Barry.

FreeRTOS implementation strategy

Thank you for your quick response Richard, I was going through the source files of FreeRTOS and the only ASF include I found was in port.c where the architecture specific sysclk.h file was included. I believe this is used to configure the timer interrupt to generate ticks. By the way I am using SAM4S and out of the FreeRTOS download I have used the demo project available for SAM4E-EK board with minor tweeks in the pin assignment I was able to run the blinky program on SAM4S Xplained. I will try to make a new project and include all the FreeRTOS files by making directories manually and see if it runs without errors.

FreeRTOS implementation strategy

The parts you are using have a Cortex-M3 (or M4F) core, and the FreeRTOS port for these cores will run on any Cortex-M3 (or M4F) microcontroller from any manufacturer. It sets up the clock used to generate the tick interrupt internally within the port.c file without any reliance on any third party code. The only thing you need to know is whether to use the M3 or M4F port layer. If the part has a Cortex-M3 core, or a Cortex-M4 core without FPU (or if you are leaving the FPU turned off) then use the port files from the Source/portable/GCC/ARM_CM3 directory. If the part has a Cortex-M4 core with and FPU and you are turning the FPU on (which I think FreeRTOS will do anyway) then use the files from the Source/portable/GCC/ARM_CM4F directory. Regards, Richard Barry.

FreeRTOS implementation strategy

Thank you Richard, I am exactly following the same procedure and I am using SAM4S without FPU so I have used the ARMCM3 port files. I have successfully build my first FreeRTOS example on SAM4S Xplained. I used only an ASF board project and then populated the directory with FreeRTOS source files and ran a simple task. What I need to do next is to get rid of the sysclkinit() and board_init() and generate the clock for SAM4S and ticker manually for FreeRTOS. I have noticed that in port.c the vPortSetupTimerInterrupt() initializes the ticker if I need to do it manually what shall be the process? The main goal here is to finally be able to make a custom SAM4S board and start with just a GCC C Executable Project instead of GCC ASF Board Project. Regards, Owais.

FreeRTOS implementation strategy

Why do you want to set up the tick interrupt manually? The code in port.c will work on any Cortex chip. It is possible to override the code but the only reason to do that would be if you had to use a different clock source. Normally that is only done when a low power clock is used if the chip will spend a long time asleep (see the tickless mode examples).

FreeRTOS implementation strategy

It is not necessary just want to make sure there are no bounds in terms of the development environment so if in future I need to run a custom makefile operation everything can compile properly. So you mean that if I create a GCC C Executable Project and let the ticker initialization as it is there wont be compile errors right?

FreeRTOS implementation strategy

The tick is generated from the SysTick timer, which is part of the Cortex-M core (not a separate peripheral). The registers used to configure the SysTick timer are at a fixed location on every Cortex-M device – and are accessed directly by the FreeRTOS code, not through libraries, so as already mentioned above the Cortex-M port layer has no dependencies on any third party libraries and will always compile. Regards, Richard Barry.

FreeRTOS implementation strategy

Thank you Richard once more for clarifying. Regards, Owais.

FreeRTOS implementation strategy

Hello. Excuse me for posting on an old thread but the question is regarding the same matter so I thought it is better not to create another topic. Moving on, I am working with Atmel Studio, as mentioned in the earlier posts, I have created a new project (GCC C Executable Project) and I have included the necessary files for FreeRTOS under the same directory structure as in FreeRTOS download and everything is working fine. Now I need to use classes in my project so I once again create a new project but this time GCC C++ Executable Project in Atmel Studio and include the same FreeRTOS files under the same directory structure as earlier but this time the Studio gives me errors undefined reference to ‘vAppliocationTickHook’ and undefined reference to ‘vApplicationStackOverflowHook’. I must point out that I have already declared these two functions in the main file and have implemented them as well but still the error persists. Does anyone here have experience as to what is causing this error? I am afraid that it might be related to the compiler but I have no idea how to remove it, if anyone has experience with this please do share. Regards, Owais

FreeRTOS implementation strategy

You are probably building the FreeRTOS code as C code, not C++ code, so the hook functions will also have to be compiled as C code so they can be called from FreeRTOS. That is achieved using extern “C” qualifier. That is normally done as
#ifdef __cplusplus
extern "C" {
#endif
then
#ifdef __cplusplus
}
#endif
http://stackoverflow.com/questions/1041866/in-c-source-what-is-the-effect-of-extern-c

FreeRTOS implementation strategy

Thank you Dave, The error is now gone. However, I am also having some errors while make the same project those are as follows: undefined reference to ‘exit’ undefined reference to ‘write’ undefined reference to ‘kill’ undefined reference to ‘sbrk’ undefined reference to ‘getpid’ undefined reference to ‘close’ undefined reference to ‘fstat’ undefined reference to ‘isatty’ undefined reference to ‘lseek’ undefined reference to ‘read’ I am using printf_stdarg.c file in my project as well as HSMCI.c files from one of the Atmel Studio example projects. The errors seems to be coming from files that I have never seen such as abort.c sbrkr.c signalr.c writer.c closer.c fstatr.c isattyr.c lseekr.c readr.c If there is something that I am missing please let me know. Regards, Owais

FreeRTOS implementation strategy

They are the newlib functions that must be provided for linkage when newlib is used. If you are using printfstdarg.c (there is a new version of that which implements snprintf() by the way…), and you are using a heapn.c file, then those functions would not be required if FreeRTOS was built by itself, so something else in the project must be bringing them in. In either case, projects created by Atmel studio have a syscalls.c file in which you will find stubs for these that will keep the linker happy. Regards.

FreeRTOS implementation strategy

Thank you for the prompt response. Can you please elaborate on the syscalls.c file and where exactly can I find it in Atmel Studio project. For clarity I am not using any example projects instead I am creating an empty project with the chip defined which in my case is SAM4S16C this only creates a main file and two source files named systemsam4s.c and startupsam4s.c besides these there are no files in the project except those that I include such as for FreeRTOS. Regards, Owais

FreeRTOS implementation strategy

See here: http://sourceforge.net/p/freertos/code/HEAD/tree/trunk/FreeRTOS/Demo/CORTEXM4ATSAM4EAtmelStudio/src/ASF/sam/utils/syscalls/gcc/ Regards.

FreeRTOS implementation strategy

Thank you once again that solved many of the errors, still however ‘write’ and ‘read’ are remaining any idea where I can find these ? Regards, Owais

FreeRTOS implementation strategy

You will probably have to provide your own stubs. Search for the functions in: http://sourceforge.net/p/freertos/code/HEAD/tree/trunk/FreeRTOS/Demo/CORTEXM4ATSAM4EAtmelStudio/src/main.c Regards.

FreeRTOS implementation strategy

Found it, included it and solved it. Thank you very much. Regards, Owais