diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/blinky.cpp | 8 | ||||
-rw-r--r-- | examples/debug-dtrrts.cpp | 10 | ||||
-rw-r--r-- | examples/qa-slave-shield.cpp | 10 | ||||
-rw-r--r-- | examples/spi_master.cpp | 21 | ||||
-rw-r--r-- | examples/test-session.cpp | 9 |
5 files changed, 44 insertions, 14 deletions
diff --git a/examples/blinky.cpp b/examples/blinky.cpp index e156bf2..b037a1f 100644 --- a/examples/blinky.cpp +++ b/examples/blinky.cpp @@ -42,8 +42,14 @@ void loop() { delay(100);
}
-int main(void) {
+// Force init to be called *first*, i.e. before static object allocation.
+// Otherwise, statically allocated object that need libmaple may fail.
+ __attribute__(( constructor )) void premain() {
init();
+}
+
+int main(void)
+{
setup();
while (1) {
diff --git a/examples/debug-dtrrts.cpp b/examples/debug-dtrrts.cpp index c85b342..f9f8b96 100644 --- a/examples/debug-dtrrts.cpp +++ b/examples/debug-dtrrts.cpp @@ -30,9 +30,14 @@ void loop() { Serial2.println(usbGetRTS(), DEC); } - -int main(void) { +// Force init to be called *first*, i.e. before static object allocation. +// Otherwise, statically allocated object that need libmaple may fail. + __attribute__(( constructor )) void premain() { init(); +} + +int main(void) +{ setup(); while (1) { @@ -40,3 +45,4 @@ int main(void) { } return 0; } + diff --git a/examples/qa-slave-shield.cpp b/examples/qa-slave-shield.cpp index fcee9cf..b395cca 100644 --- a/examples/qa-slave-shield.cpp +++ b/examples/qa-slave-shield.cpp @@ -37,9 +37,14 @@ void loop() { } } - -int main(void) { +// Force init to be called *first*, i.e. before static object allocation. +// Otherwise, statically allocated object that need libmaple may fail. + __attribute__(( constructor )) void premain() { init(); +} + +int main(void) +{ setup(); while (1) { @@ -47,3 +52,4 @@ int main(void) { } return 0; } + diff --git a/examples/spi_master.cpp b/examples/spi_master.cpp index 2b62c8d..9f6d81b 100644 --- a/examples/spi_master.cpp +++ b/examples/spi_master.cpp @@ -59,12 +59,19 @@ void loop() { delay(1000);
}
-int main(void) {
- init();
- setup();
+// Force init to be called *first*, i.e. before static object allocation.
+// Otherwise, statically allocated object that need libmaple may fail.
+ __attribute__(( constructor )) void premain() {
+ init();
+}
+
+int main(void)
+{
+ setup();
- while (1) {
- loop();
- }
- return 0;
+ while (1) {
+ loop();
+ }
+ return 0;
}
+
diff --git a/examples/test-session.cpp b/examples/test-session.cpp index 4f09591..9885ab3 100644 --- a/examples/test-session.cpp +++ b/examples/test-session.cpp @@ -555,8 +555,14 @@ void do_fast_gpio(void) { gpio_write_bit(GPIOB_BASE, 5, 1); gpio_write_bit(GPIOB_BASE, 5, 0); } -int main(void) { +// Force init to be called *first*, i.e. before static object allocation. +// Otherwise, statically allocated object that need libmaple may fail. + __attribute__(( constructor )) void premain() { init(); +} + +int main(void) +{ setup(); while (1) { @@ -564,4 +570,3 @@ int main(void) { } return 0; } - |