Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c85d1f2

Browse files
Make init() run before C++ static initializers
Before this change, the contents of `init()` run after `.init6`, which is when static initializers run. However, this is not desirable: * init() does not need any C++ classes to be active * C++ static initialization sometimes _does_ require that the hardware be pre-configured! This makes it possible to make calls like `Serial.begin()` inside constructors of global variables.
1 parent 626a00a commit c85d1f2

File tree

1 file changed

+7
-1
lines changed
  • hardware/arduino/avr/cores/arduino

1 file changed

+7
-1
lines changed

‎hardware/arduino/avr/cores/arduino/wiring.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ void delayMicroseconds(unsigned int us)
238238
// return = 4 cycles
239239
}
240240

241-
void init()
241+
//http://www.atmel.com/webdoc/AVRLibcReferenceManual/mem_sections_1sec_dot_init.html
242+
// init5 is after .data, but before C++ initialization - perfect for hardware setup
243+
void _do_setup(void) __attribute__ ((naked, used, section (".init5")));
244+
void _do_setup()
242245
{
243246
// this needs to be called before setup() or some functions won't
244247
// work there
@@ -390,3 +393,6 @@ void init()
390393
UCSR0B = 0;
391394
#endif
392395
}
396+
397+
// for backwards compatibility
398+
void init() {}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /