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

Upgrading from 5.2.0 to 6.0.0 breaks sprintf

Posted by Stephen Osborn on October 28, 2009
I decided to make the upgrade to FreeRTOS 6.0.0 from FreeRTOS 5.2.0. I have been using sprintf to display floating point values to the serial port. Changing to 6.0.0 I cannot get sprintf to display anything other than zero. The format string works properly, but I only see zeros on the display.

With 5.2.0 I had to play around with stack sizes to get sprintf to work properly, and to make the stack smaller, only one task, the serial port gatekeeper task, is allowed to use sprintf. With 6.0.0, adjusting the stack size makes no difference in the output. I get no error messages from sprintf.

The only difference between the working and the non-working versions are the versions of FreeRTOS. Everything else is the same.

Anybody have any suggestions? (besides "Don't use sprintf.")

CPU is STM32F103 (Cortex-M3)
Board is custom.

RE: Upgrading from 5.2.0 to 6.0.0 breaks sprintf

Posted by Samuel Tardieu on October 28, 2009
Which libc are you using?

RE: Upgrading from 5.2.0 to 6.0.0 breaks sprintf

Posted by Richard on October 28, 2009
One of the differences between V5.x.x and V6.x.x is the stack byte alignment used on ARM ports. Previously it was set to 4 as this was good enough for everything except some operations on 8 byte data types (like using %f with sprintf). Now it is set to 8 and all 8 byte data type problems should be fixed (?) so it is odd that you report it working before but not now.

Can you look at the stack pointer in the debugger and check that it is indeed 8 byte aligned.

Also, do you have stack overflow detection turned on? Maybe you are simply overflowing a stack.

You could try setting portBYTE_ALIGNMENT to 4 (its old value) in portmacro.h to see if that makes it work again. As 8 is a multiple of 4 I would not have thought it would make any difference, unless I have made a mistake somewhere else.

Regards.

RE: Upgrading from 5.2.0 to 6.0.0 breaks sprintf

Posted by Stephen Osborn on October 28, 2009
Samuel, I am using newlib.

Richard,
I had forgotten to mention that I had changed the stack alignment in 5.2.0 to 8

Stack overflow detection is enabled and no stacks are overflowing.

The stack pointer value I looked at is 0x200027B4, which looks like a 4 byte aligned address. I will dig into this.

Thanks.

RE: Upgrading from 5.2.0 to 6.0.0 breaks sprintf

Posted by Stephen Osborn on October 29, 2009
I set a break point on the sprintf line that writes a floating point value. GDB reports that the SP = 0x20002794.

At the start of the program I printed these values:

portBYTE_ALIGNMENT = 8

portBYTE_ALIGNMENT_MASK = 7

Suggestions?

RE: Upgrading from 5.2.0 to 6.0.0 breaks sprintf

Posted by Richard on October 30, 2009
Could you try setting a break point on the very first line of the task that calls sprintf(). Depending on the debugger being used that will often be on the opening bracket of the function. For example:

void vATaskFunction( void *pv )
{ /* Place break point here, before variable definitions. */
int x, y, etc;

Alternatively view the code in assembly, and add a break point on the first assembly line. The important thing is that the break point is hit before the function prologue that sets up the stack and frame pointers is executed.

What is the stack pointer value when that break point is hit?

Which compiler are you using?

Regards.

RE: Upgrading from 5.2.0 to 6.0.0 breaks sprintf

Posted by Richard on October 30, 2009
Hi again. It looks like I might have messed up because of the 'decrement before' behaviour. I would be grateful if you could try the following:

<ol>
<li> Open up port.c from the Source/portable/[compiler]/CM3 directory.
<li> Add the line "pxTopOfStack--;" to the top of the function pxPortInitialiseStack().
</ol>

Let me know if that fixes the problem.

Thanks and regards.

RE: Upgrading from 5.2.0 to 6.0.0 breaks sprintf

Posted by Richard on October 30, 2009
Using markdown syntax in the reply is fine when viewed in the preview window, but does not work when viewed in the forum or in the emails of posts I received. This forum seems totally screwy at the moment.

Regards.

RE: Upgrading from 5.2.0 to 6.0.0 breaks sprintf

Posted by Stephen Osborn on October 30, 2009
Richard,

The stack pointer at the beginning of the function, before any other operations occur is 0x200027AC.

I put the "pxTopOfStack--;" as the first line of code in pxPortInitialiseStack() and now it is working.

Thank You!!!!

RE: Upgrading from 5.2.0 to 6.0.0 breaks sprintf

Posted by francis wang on November 7, 2009
Where exactly should the "pxTopOfStack--;" be put?
I checked the code in pxPortInitialiseStack, but in different versions they are the same?

RE: Upgrading from 5.2.0 to 6.0.0 breaks sprintf

Posted by Richard on November 7, 2009
As already said - the first line in the function. Code in that function has not changed, but code elsewhere has.

Regards.


[ 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