bugAVR C Runtime Library - Bugs: bug #25062, sprintf_P and family problem on...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #25062: sprintf_P and family problem on ATXMega128a1

Submitter:  Sebastian Schocke <sschocke>
Submitted:  Wed 10 Dec 2008 01:22:32 PM UTC
Votes: 10
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Invalid Assigned to:  None
Percent Complete:  0% Open/Closed:  Closed
Release:  1.6.4 Fixed Release:  None

Wed 07 Jan 2009 12:41:27 PM UTC, comment #1: 

This not avr-libc bug, this is avr-gcc bug.
More, sourceforge.net bug [ 2490164 ]:
XMega (128A1): subroutine calling may corrupt stack pointer

http://sourceforge.net/tracker/index.php?func=detail&aid=2490164&group_id=68108&atid=520074

Anatoly Sokolov <aesok>
Group administrator
Wed 10 Dec 2008 01:22:32 PM UTC, original submission:  

After tracing the program flow through the simulator on AVR Studio, I have found that if I call sprintf_P, or any of the printf or scanf functions, the Stack Pointer(SP) on the ATXMega128a1 is changed to a constant value. This value is constant no matter what my previous SP value was, and changes to the following value: 0x3FD8

This causes the AVR to reset whenever a return is issued from a function, as the return jump address is stored on the stack.

Attached is a test case. The DEFINE BROKEN in the test_spf.c works as follows. If set to 0, the code executes as expected, because the main() function is never returned from, but sprintf_P still modifies the SP. If BROKEN is set to 1, sprintf_P is called from inside the sayHello() function, and the AVR resets when the end of the sayHello() function is reached.

Also, I tested the same code on an ATMega8, and everything there works fine. Tracing it through a simulator on the ATMega8, the SP remains the same before and after the call to sprintf_P.

Also, during simulating, it seems that the actual value that SP should be is stored in the Y Pointer, so it seems like the SP value is not restored from where it was saved when the sprintf_P call on an ATXMega completes. Perhaps writing to SP is not allowed on the ATXMega.

Sebastian Schocke <sschocke>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #17017:  test_spf.zip added by sschocke (2KiB - application/zip - Test Case source code)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by aesok (Posted a comment)
  • -email is unavailable- added by sschocke (Voted in favor of this item)
  • -email is unavailable- added by sschocke (Submitted the item)
  •  

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-01-07 aesok CategoryLibrary None
        Item Grouplibc code None
        StatusNone Invalid
        Open/ClosedOpen Closed
    2008-12-10 sschocke Carbon-Copy- Added sschocke
    2008-12-10 sschocke Attached File- Added test_spf.zip, #17017

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code