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

 
 

bug #25062: sprintf_P and family problem on ATXMega128a1

Submitted by:  Sebastian Schocke <sschocke>
Submitted on:  Wed 10 Dec 2008 01:22:32 PM UTC  
Votes:  10  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalItem Group: None
Status: InvalidPercent Complete: 0%
Assigned to: NoneOpen/Closed: Closed
Release: 1.6.4Fixed Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project 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.)

Attach File(s):
   
   
Comment:
   

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
  • -unavailable- added by aesok (Posted a comment)
  • -unavailable- added by sschocke (Voted in favor of this item)
  • -unavailable- added by sschocke (Submitted the item)
  •  

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 6 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 07 Jan 2009 12:41:27 PM UTCaesokCategoryLibrary=>None
      Item Grouplibc code=>None
      StatusNone=>Invalid
      Open/ClosedOpen=>Closed
    Wed 10 Dec 2008 01:32:18 PM UTCsschockeCarbon-Copy-=>Added sschocke
    Wed 10 Dec 2008 01:22:32 PM UTCsschockeAttached File-=>Added test_spf.zip, #17017

    Back to the top


    Powered by Savane 3.1-cleanup1