public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/44082]  New: AVR watchdog resets the core during initialization
@ 2010-05-11 14:41 j-etienne at users dot sourceforge dot net
  2010-06-09 20:21 ` [Bug target/44082] " eric dot weddington at atmel dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: j-etienne at users dot sourceforge dot net @ 2010-05-11 14:41 UTC (permalink / raw)
  To: gcc-bugs

After watchdog reset (for example, to enter reprogramming), the AVR core
restarts with watchdog enabled, contrary to a cold start after power on.
The C program is not given an opportunity to disable or reset the watchdog
before "main" ; and when the data and/or bss section is large enough, the
watchdog triggers a CPU reset during __do_copy_data or __do_clear_bss, and the
main therefore never starts.

To avoid this, I've added watchdog reset instructions in the __do_copy_data and
__do_clear_bss loops. Here is a patch :

*** gcc-4.5-20100311.orig/gcc/config/avr/libgcc.S       2009-05-23
09:16:07.000000000 +0200
--- gcc-4.5-20100311/gcc/config/avr/libgcc.S    2010-05-11 16:30:29.000000000
+0200
***************
*** 710,715 ****
--- 710,716 ----
        out     __RAMPZ__, r16
        rjmp    .L__do_copy_data_start
  .L__do_copy_data_loop:
+    wdr         /* Avoid watchdog reset if active */
        elpm    r0, Z+
        st      X+, r0
  .L__do_copy_data_start:
***************
*** 728,733 ****
--- 729,735 ----
        out     __RAMPZ__, r16
        rjmp    .L__do_copy_data_start
  .L__do_copy_data_loop:
+    wdr         /* Avoid watchdog reset if active */
        elpm
        st      X+, r0
        adiw    r30, 1
***************
*** 744,749 ****
--- 746,752 ----
        ldi     r31, hi8(__data_load_start)
        rjmp    .L__do_copy_data_start
  .L__do_copy_data_loop:
+    wdr         /* Avoid watchdog reset if active */
  #if defined (__AVR_HAVE_LPMX__)
        lpm     r0, Z+
  #else
***************
*** 769,774 ****
--- 772,778 ----
        ldi     r27, hi8(__bss_start)
        rjmp    .do_clear_bss_start
  .do_clear_bss_loop:
+    wdr         /* Avoid watchdog reset if active */
        st      X+, __zero_reg__
  .do_clear_bss_start:
        cpi     r26, lo8(__bss_end)


-- 
           Summary: AVR watchdog resets the core during initialization
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: j-etienne at users dot sourceforge dot net
 GCC build triplet: x86_64-apple-darwin10.2.0
  GCC host triplet: x86_64-apple-darwin10.2.0
GCC target triplet: avr-unknown-none


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44082


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/44082] AVR watchdog resets the core during initialization
  2010-05-11 14:41 [Bug c/44082] New: AVR watchdog resets the core during initialization j-etienne at users dot sourceforge dot net
@ 2010-06-09 20:21 ` eric dot weddington at atmel dot com
  2010-06-10 16:40 ` j-etienne at users dot sourceforge dot net
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: eric dot weddington at atmel dot com @ 2010-06-09 20:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from eric dot weddington at atmel dot com  2010-06-09 20:21 -------
This is not a bug.
Please see the avr-libc documentation for <avr/wdt.h> here:
http://www.nongnu.org/avr-libc/user-manual/group__avr__watchdog.html
which gives the method to disable the watchdog.


-- 

eric dot weddington at atmel dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eric dot weddington at atmel
                   |                            |dot com
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44082


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/44082] AVR watchdog resets the core during initialization
  2010-05-11 14:41 [Bug c/44082] New: AVR watchdog resets the core during initialization j-etienne at users dot sourceforge dot net
  2010-06-09 20:21 ` [Bug target/44082] " eric dot weddington at atmel dot com
@ 2010-06-10 16:40 ` j-etienne at users dot sourceforge dot net
  2010-06-10 16:43 ` j at uriah dot heep dot sax dot de
  2010-06-10 17:17 ` eric dot weddington at atmel dot com
  3 siblings, 0 replies; 5+ messages in thread
From: j-etienne at users dot sourceforge dot net @ 2010-06-10 16:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from j-etienne at users dot sourceforge dot net  2010-06-10 16:39 -------
<avr/wdt.h> does provide the means to stop/start/refresh the watchdog from the
main C program. But, as said in the original comment, if the bss and/or data
section is too large, the CPU spends a lot of time initializing these memory
sections, and the watchdog fires *before* the start of the main C program.
Therefore, the device endlessly resets, whatever code is in the main.


-- 

j-etienne at users dot sourceforge dot net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44082


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/44082] AVR watchdog resets the core during initialization
  2010-05-11 14:41 [Bug c/44082] New: AVR watchdog resets the core during initialization j-etienne at users dot sourceforge dot net
  2010-06-09 20:21 ` [Bug target/44082] " eric dot weddington at atmel dot com
  2010-06-10 16:40 ` j-etienne at users dot sourceforge dot net
@ 2010-06-10 16:43 ` j at uriah dot heep dot sax dot de
  2010-06-10 17:17 ` eric dot weddington at atmel dot com
  3 siblings, 0 replies; 5+ messages in thread
From: j at uriah dot heep dot sax dot de @ 2010-06-10 16:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from j at uriah dot heep dot sax dot de  2010-06-10 16:43 -------
(In reply to comment #2)
> <avr/wdt.h> does provide the means to stop/start/refresh the watchdog from the
> main C program.

No.  It contains a fairly detailed description how to place the
watchdog reset/initialization into the custom startup code, so
it can be run before the initialization loops.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44082


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/44082] AVR watchdog resets the core during initialization
  2010-05-11 14:41 [Bug c/44082] New: AVR watchdog resets the core during initialization j-etienne at users dot sourceforge dot net
                   ` (2 preceding siblings ...)
  2010-06-10 16:43 ` j at uriah dot heep dot sax dot de
@ 2010-06-10 17:17 ` eric dot weddington at atmel dot com
  3 siblings, 0 replies; 5+ messages in thread
From: eric dot weddington at atmel dot com @ 2010-06-10 17:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from eric dot weddington at atmel dot com  2010-06-10 17:16 -------
Again: setting this to INVALID.


-- 

eric dot weddington at atmel dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44082


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-06-10 17:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-11 14:41 [Bug c/44082] New: AVR watchdog resets the core during initialization j-etienne at users dot sourceforge dot net
2010-06-09 20:21 ` [Bug target/44082] " eric dot weddington at atmel dot com
2010-06-10 16:40 ` j-etienne at users dot sourceforge dot net
2010-06-10 16:43 ` j at uriah dot heep dot sax dot de
2010-06-10 17:17 ` eric dot weddington at atmel dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).