Skip to content

Commit

Permalink
Similar startup delay code between Teensy 3 and 4
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulStoffregen committed Jul 27, 2022
1 parent d44e8bb commit 4e35529
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions teensy3/pins_teensy.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,9 @@ void _init_Teensyduino_internal_(void)
// https://forum.pjrc.com/threads/31290-Teensey-3-2-Teensey-Loader-1-24-Issues?p=87273&viewfull=1#post87273

startup_middle_hook();
delay(TEENSY_INIT_USB_DELAY_BEFORE);
while (millis() < TEENSY_INIT_USB_DELAY_BEFORE) ; // wait
usb_init();
delay(TEENSY_INIT_USB_DELAY_AFTER);
while (millis() < TEENSY_INIT_USB_DELAY_AFTER + TEENSY_INIT_USB_DELAY_BEFORE) ; // wait
}


Expand Down
16 changes: 13 additions & 3 deletions teensy4/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,20 @@ void ResetHandler(void)
pwm_init();
tempmon_init();
startup_middle_hook();
while (millis() < 20) ; // wait at least 20ms before starting USB
usb_init();

while (millis() < 300) ; // wait at least 300ms before calling user code
#if !defined(TEENSY_INIT_USB_DELAY_BEFORE)
#define TEENSY_INIT_USB_DELAY_BEFORE 20
#endif
#if !defined(TEENSY_INIT_USB_DELAY_AFTER)
#define TEENSY_INIT_USB_DELAY_AFTER 280
#endif
// for background about this startup delay, please see these conversations
// https://forum.pjrc.com/threads/36606?p=113980&viewfull=1#post113980
// https://forum.pjrc.com/threads/31290?p=87273&viewfull=1#post87273

while (millis() < TEENSY_INIT_USB_DELAY_BEFORE) ; // wait
usb_init();
while (millis() < TEENSY_INIT_USB_DELAY_AFTER + TEENSY_INIT_USB_DELAY_BEFORE) ; // wait
//printf("before C++ constructors\n");
startup_late_hook();
__libc_init_array();
Expand Down

0 comments on commit 4e35529

Please sign in to comment.