Quality RTOS & Embedded Software

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



Posted by jordiblasi on July 28, 2016

I am using Freertos on a Intel Galileo Gen 2 board and I am trying to copy and compare some strings but i am having some trouble. As I see I have available on the libraries distribbuted the strlen, strcpy, memcpy and memcmp. What I am seeing is that both strlen and strcpy don't work. They are even commented as "Extremely crude implementations" in the code. In fact, strlen seems not be be even implemented. memcpy and memcmp seem to do the job, but they ask for the memory string size to work with. As I am not able to use strlen, I have been defining a maximun string size to perform this operations. I understand that this is not optimal, but at least it works for copying. My problem is that if I compare two strings, one static value and the other as an entry to a function I get values that don't fit what I was expecting.


define VARSIZE 50

static char reference[VARSIZE];

int locate(char id[] ) { ... r = memcmp(conTab[a].reference,id,VARSIZE); ... } ~~~

When I set both values to "refe03" (so comparison result should be 0) I get as a result value 43. If I set other values (f.e. "refe04" for id) I get 45 as a result. Am I doing something wrong? How can I solve this?



Posted by rtel on July 28, 2016

It might be that GCC is using a builtin version of the function. Try adding -fno-builtin-strlen to the command line to see if that fixes the strlen() problem. Also, the source code for the function is there and is very short, so you can step through it easily enough to see what it is doing to check it is correct.

The crude implementations of the functions are only provided because the demo as downloaded makes no assumptions as to the C libraries that are available with the compiler. Ideally link to a suitable GCC unhosted C library, then use the functions provided by the C library.


Posted by jordiblasi on July 28, 2016

Running the gcc command with -fno-builtin-strlen changes nothing in the response. I get this error:

undefined reference to 'strlen'

I have tried to remove the string.h and freestanding_functions.c files to force it to use the standard libraries but it looks like it is not able to find them. I have included the cygwin libraries I have in my computer (by adding C:cygwin64usrinclude to the eclipse include folders) but it does not use them.

Where can I get a valid library set to use?




Posted by jordiblasi on August 11, 2016

For anyone wondering, I have succesfully used this simple method for implementing strlen:

sizet strlen(const char *s) { sizet i; for (i = 0; s[i] != '0'; i++) ; return i; }

It can be incorporated to the freestanding_functions.c file and it works perfectly.

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

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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 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