Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

using sprintf on LPC2468, possible stack overflow?

Posted by mrtheo on December 17, 2013

Hello

I'm want to use sprintf function in my task and I've got some problems with it. Here's the code:

void vMyTask(void *pvParameters)
{
while(1)
{
char mytext[50];
sprintf(mytext, "blah blah");
char *pointer = mytext;

xQueueSend(Global_Queue_Handle, &pointer, 1000);
vTaskDelay(5000);
}
}

So far, the sprintf function works, data is being sent to httpd-cgi and then to web interface, where it displays "blah blah" text just fine. But if I put some integer in the code, say:


char mytext[50];
int value=123;
sprintf(mytext, "%d blah blah", value);
char *pointer = mytext;

It doesn't work - code compiles fine, but the web interface doesn't even start. I did some searching and found, that this could be a problem with stack overflow, so I've increased the stack:


xTaskCreate(vMyTask, "MyTask", configMINIMAL_STACK_SIZE, NULL, 1, NULL ); //original
xTaskCreate(vMyTask, "MyTask", 50000, NULL, 1, NULL ); //modified

So now the web interface displays fine, but there is no expected "123 blah blah". And what's more, if I go back to simple "blah blah" (no integer), it doesn't display as well - I have to go back to configMINIMALSTACKSIZE in order for it to display.

And this is where I've got so far. What can I do in order to make it work? I've seen that there is a low memory cost implementation printf-stdarg. Do I use it? How do I use it? I'm fine with any solution that allows me to convert integers (no floats in my code) into chars.

I'm running the code on FreeRTOS v7.5.2 and LPC2468 - 16MB SDRAM seems plenty...

Regards, George


using sprintf on LPC2468, possible stack overflow?

Posted by rtel on December 17, 2013

code compiles fine, but the web interface doesn't even start.

If you view the contents of the mytext buffer in the debugger, does it contain the expected string?

did some searching and found, that this could be a problem with stack overflow

Enabling stack overflow protection would tell you if that was the case.

So now the web interface displays fine, but there is no expected "123 blah blah"

You have gone from a tiny stack to a massive stack in one step - is the task even being created? It won't be unless your heap is in the 16 meg external RAM as you are trying to allocate a 195K stack on a device that has 98K or internal RAM. Checking the return value of xTaskCreate() and defining a malloc failed hook function will help you.

To use printf-stdarg simply include the printf-stdarg C file in your build.

Regards.


using sprintf on LPC2468, possible stack overflow?

Posted by mrtheo on December 18, 2013

To use printf-stdarg simply include the printf-stdarg C file in your build.

Well, that was easy. I was expecting having to make some deep changes in the project, so that was why I was asking. Anyway, it works! It's not perfect, since I have to keep an eye on stack size, as it has a tendency to overflow, but it works!

Using printf-stdarg influenced my rtos stats, which are not displaying since the sprintf function has been modified. But I think I'll manage with restoring this functionality.

Thank you for your help :)


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists