URL: <http://savannah.nongnu.org/bugs/?25062>
Summary: sprintf_P and family problem on ATXMega128a1 Project: AVR C Runtime Library Submitted by: sschocke Submitted on: Wed 10 Dec 2008 01:22:32 PM GMT Category: Library Severity: 3 - Normal Priority: 5 - Normal Item Group: libc code Status: None Percent Complete: 0% Assigned to: None Open/Closed: Open Discussion Lock: Any Release: 1.6.4 Fixed Release: None _______________________________________________________ Details: 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. _______________________________________________________ File Attachments: ------------------------------------------------------- Date: Wed 10 Dec 2008 01:22:32 PM GMT Name: test_spf.zip Size: 2kB By: sschocke Test Case source code <http://savannah.nongnu.org/bugs/download.php?file_id=17017> _______________________________________________________ Reply to this item at: <http://savannah.nongnu.org/bugs/?25062> _______________________________________________ Message sent via/by Savannah http://savannah.nongnu.org/ _______________________________________________ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-libc-dev