<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Inaccurate delay and Blink doesn&#039;t work</title>
		<link>http://forums.leaflabs.com/topic.php?id=74404</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:09:58 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=74404" rel="self" type="application/rss+xml" />

		<item>
			<title>bobc on "Inaccurate delay and Blink doesn&#039;t work"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74404#post-105609</link>
			<pubDate>Tue, 06 Jan 2015 04:06:27 +0000</pubDate>
			<dc:creator>bobc</dc:creator>
			<guid isPermaLink="false">105609@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;How do you propose to call init() before __libc_init_array()?&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;By changing start_c.c, obviously!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>dbolgheroni on "Inaccurate delay and Blink doesn&#039;t work"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74404#post-105608</link>
			<pubDate>Mon, 05 Jan 2015 16:08:48 +0000</pubDate>
			<dc:creator>dbolgheroni</dc:creator>
			<guid isPermaLink="false">105608@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Apparently it's working OK with both solutions.&#60;/p&#62;
&#60;p&#62;Thank you.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Inaccurate delay and Blink doesn&#039;t work"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74404#post-105607</link>
			<pubDate>Mon, 05 Jan 2015 16:07:35 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">105607@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;&#60;em&#62;&#34;I've run into some problems with the libmaple startup code&#34;&#60;/em&#62;&#60;br /&#62;
I haven't.&#60;/p&#62;
&#60;p&#62;&#60;em&#62;&#34;the use of a constructor to initialise the hardware is not a reliable way to do it&#34;&#60;/em&#62;&#60;br /&#62;
This is only an issue if there are dependencies between constructors which is not handled correctly in the code. When there is only one initialisation function it can't create a problem, unless the code itself contains a bug. If that were the case, it would be consistently wrong.&#60;/p&#62;
&#60;p&#62;&#60;em&#62;&#34;The order of constructor execution is not defined (this is a general C++ problem).&#34;&#60;/em&#62;&#60;br /&#62;
True, but in this specific case, only *one* initialisation function, that is irrelevant.&#60;/p&#62;
&#60;p&#62;&#60;em&#62;&#34;It's possible that static constructors are called before the hardware is initialised&#34;&#60;/em&#62;&#60;br /&#62;
What do you mean? I believe the init() function called by the static constructor *is doing* the hardware initialisation. How do you propose to call init() before __libc_init_array()?&#60;/p&#62;
&#60;p&#62;(Full disclosure: I am not a member of LeafLabs staff.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bobc on "Inaccurate delay and Blink doesn&#039;t work"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74404#post-105606</link>
			<pubDate>Sun, 04 Jan 2015 18:54:24 +0000</pubDate>
			<dc:creator>bobc</dc:creator>
			<guid isPermaLink="false">105606@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hmm, not sure I would recommend that.&#60;/p&#62;
&#60;p&#62;I've run into some problems with the libmaple startup code, the use of a constructor to initialise the hardware is not a reliable way to do it. The order of constructor execution is not defined (this is a general C++ problem). &#60;/p&#62;
&#60;p&#62;It's possible that static constructors are called before the hardware is initialised, which is obviously bad. Really, standard practice is to explicitly call the hardware init function before __libc_init_array() is called.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Inaccurate delay and Blink doesn&#039;t work"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74404#post-105603</link>
			<pubDate>Sun, 04 Jan 2015 14:07:13 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">105603@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;If dbolgheroni is able to compile their program, it is probably better not to use:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;__attribute__((constructor)) void premain() {
    init();
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;and just call init() directly at the start of main().
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bobc on "Inaccurate delay and Blink doesn&#039;t work"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74404#post-105601</link>
			<pubDate>Sun, 04 Jan 2015 04:59:59 +0000</pubDate>
			<dc:creator>bobc</dc:creator>
			<guid isPermaLink="false">105601@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer is right, you need to ensure init() is called.&#60;/p&#62;
&#60;p&#62;Here is a sample from latest libmaple&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;// Blinks the built-in LED

#include &#38;lt;wirish/wirish.h&#38;gt;

void setup() {
    pinMode(BOARD_LED_PIN, OUTPUT);
}

void loop() {
    togglePin(BOARD_LED_PIN);
    delay(100);
}

__attribute__((constructor)) void premain() {
    init();
}

int main(void) {
    setup();

    while (true) {
        loop();
    }
    return 0;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Inaccurate delay and Blink doesn&#039;t work"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74404#post-105600</link>
			<pubDate>Sat, 03 Jan 2015 19:47:50 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">105600@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The reason I asked you to upload without your main() is the traditional Maple main() has a call to an init function which initialised the peripherals. For example that initialisation uses the external crystal as a clock source, rather than the internal (on chip) RC oscillator. Also it initialises other peripherals, and sets the speeds and dividers for the clock signals. Hence using that is likely to fix your timing problem.&#60;/p&#62;
&#60;p&#62;So all the symptoms may be corrected by using a different main().&#60;/p&#62;
&#60;p&#62;If you look through the source of the libmaple library code, and especially the Maple mini main(), you should be able to track down the appropriate code.&#60;/p&#62;
&#60;p&#62;Edit:&#60;br /&#62;
You could call init() directly form your main(), before calling setup().
&#60;/p&#62;</description>
		</item>
		<item>
			<title>dbolgheroni on "Inaccurate delay and Blink doesn&#039;t work"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74404#post-105599</link>
			<pubDate>Sat, 03 Jan 2015 17:33:23 +0000</pubDate>
			<dc:creator>dbolgheroni</dc:creator>
			<guid isPermaLink="false">105599@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;Are you able to try the same program using the Maple IDE, and without your main()? If so, are the results all the same?&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;I fail to see why the main() routine would cause the problem, but no. I can run the IDE, since it's where I got the Blink and added main(), but I have problems uploading to the board with it (&#34;Reset via USB Serial Failed!&#34;, &#34;Couldn't find the DFU device: [1EAF:0003]&#34;, etc.). It works without a problem via CLI, though, using the toolchain indicated in the LeafLabs site.&#60;/p&#62;
&#60;p&#62;What about the Serial1.begin() problem? I think it's more critical. If I use somewhere in the code, the LED doesn't blink or it blinks 2 or 3 times after the program code is run (I know the difference between bootloader blinks and the program itself blinks). Doesn't blink even with the inaccurate delay I mentioned earlier. How this can be related to Serial is another thing that's bugging me now.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;Have you access to an oscilloscope? You could try setting a PWM value for 50:50 mark space ratio with a cycle of 1ms, and see if that looks correct.&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;No.&#60;/p&#62;
&#60;p&#62;Thank you very much.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Inaccurate delay and Blink doesn&#039;t work"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74404#post-105598</link>
			<pubDate>Sat, 03 Jan 2015 10:35:12 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">105598@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Are you able to try the same program using the  Maple IDE, and without your main()? If so, are the results all the same?&#60;/p&#62;
&#60;p&#62;Have you access to an oscilloscope? You could try setting a PWM value for 50:50 mark space ratio with a cycle of 1ms, and see if that looks correct.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>dbolgheroni on "Inaccurate delay and Blink doesn&#039;t work"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74404#post-105597</link>
			<pubDate>Fri, 02 Jan 2015 21:16:46 +0000</pubDate>
			<dc:creator>dbolgheroni</dc:creator>
			<guid isPermaLink="false">105597@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi,&#60;/p&#62;
&#60;p&#62;I'm using the CLI Unix toolchain on Linux to develop for a Maple Mini board I have. But I'm running into various strange problems.&#60;/p&#62;
&#60;p&#62;1) using a toggleLED(), the delay is not accurate. For example, when set to 1000 ms, it take approximately 10x as much, or 10 seconds;&#60;br /&#62;
2) using Serial1.begin() or Serial2.begin(), even if after this I doesn't touch in code related to serial again, the LED doesn't blink. If I reset the board, it may or may not blink 2 or 3 times, but after this it stops.&#60;/p&#62;
&#60;p&#62;I'm compiling with&#60;/p&#62;
&#60;p&#62;$ BOARD=maple_mini make&#60;/p&#62;
&#60;p&#62;and the code is the simpliest:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;lt;wirish/wirish.h&#38;gt;

void setup() {
    // Set up the built-in LED pin as an output:
    pinMode(BOARD_LED_PIN, OUTPUT);

    Serial1.begin(9600);
}

void loop() {
    toggleLED();
    delay(100);
}

int main(void) {
    setup();

    while (true) {
        loop();
    }

    return 0;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Any hints?&#60;br /&#62;
Thank you.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
