<?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: What about low-power modes?</title>
		<link>http://forums.leaflabs.com/topic.php?id=1437</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:08:47 +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=1437" rel="self" type="application/rss+xml" />

		<item>
			<title>manitou on "What about low-power modes?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1437#post-105241</link>
			<pubDate>Mon, 17 Feb 2014 21:07:44 +0000</pubDate>
			<dc:creator>manitou</dc:creator>
			<guid isPermaLink="false">105241@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I modified higwoshy sketch to measure current in SLEEP and STANDBY modes. Results were:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;maple RET6 (Vin): run 49.6 ma   (18.5@9mhz), 35.16ma io disabled
                  sleep 29.4 ma (13.9@9mhz), 12.5ma io disabled (11.1@9mhz)
                  stop  6.6ma
                  standby 6.6ma&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>gbulmer on "What about low-power modes?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1437#post-8567</link>
			<pubDate>Fri, 09 Mar 2012 22:14:24 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">8567@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;higwoshy - if the Maple drops the USB enumeration pin, the host should think the USB device has gone away. Then Maple can go to sleep without worrying about USB. &#60;/p&#62;
&#60;p&#62;When Maple wakes up, and needs to talk over USB, raise the USB enumeration pin. That should force the host to re-enumerate the USB device (Maple).&#60;/p&#62;
&#60;p&#62;Once that is done, communications can be continued, though I haven't thought through how a program on the host will understand what has happened.&#60;/p&#62;
&#60;p&#62;I haven't looked at the details, and I don't know how messy the libraries are, but in theory, that is all that should be needed!-)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>higwoshy on "What about low-power modes?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1437#post-8566</link>
			<pubDate>Fri, 09 Mar 2012 21:39:33 +0000</pubDate>
			<dc:creator>higwoshy</dc:creator>
			<guid isPermaLink="false">8566@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Here is what I have found so far. &#60;/p&#62;
&#60;p&#62;Looking through the docs, it seems that normal sleep mode is a bit of a waste of time, as at best it will save 2ma.&#60;/p&#62;
&#60;p&#62;Moving onto stop mode which seems the best option (standby resets sram?) I managed to get the current down to 3ma (incl regulator) with everything in it's default state and about 5ma with the built in LED on. Not bad. This is a Olimexino running off a 3.7V li-ion battery.&#60;/p&#62;
&#60;p&#62;Here is some rough code, if someone with more knowledge than me could look through it and point out any mistakes/suggestions:-&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;// Engages stop mode on the cpu, wakes up when the onboard button is briefly pressed
// Toggles pin 3 and pin 13 every time the button is pressed/released
// Pin 3 is used to indicate that the main loop has run. It is toggled every time loop() is called.
// Normally this would be constantly flashing on/off so fast it would appear on all the time
// In this case, the loop is only finished when the button has been pressed/released.

// PROBLEMS so far : works as expected,
//                 : note that because it&#38;#39;s in stop mode, you may have to
//                 : reset to reprogram.

//                 : SerialUSB.print : NOT WORKING.

#include &#38;lt;stdint.h&#38;gt;
#include &#38;lt;pwr.h&#38;gt;
#include &#38;lt;scb.h&#38;gt;

// These are possibly defined somewhere but I couldn&#38;#39;t find them. System Control Register
#define SCB_SCR_SLEEPDEEP 4       // Controls deepsleep(1) or sleep(0)
#define SCB_SCR_SLEEPONEXIT 2     // Controls sleeponexit (not used here)

volatile bool ledState = LOW;    // Used in ISR blinkState()

void setup()
{
    pinMode(BOARD_LED_PIN, OUTPUT);
    pinMode(3,OUTPUT);
    pinMode(BOARD_BUTTON_PIN, INPUT);

    // Just to show that the board has reset (wdt or possibly standby mode(not used here))
    for (int i=0; i&#38;lt;20; ++i)
    {
        delay(200);
        toggleLED();
    }

    togglePin(3);

    // Wake up cpu on button press.
    attachInterrupt(BOARD_BUTTON_PIN, blinkState, FALLING);

}

void loop()
{
  //SerialUSB.println(&#38;quot;HI!&#38;quot;);  delay(100);    // Only works on first iteration, before stop mode

  // Clear PDDS and LPDS bits
  PWR_BASE-&#38;gt;CR &#38;amp;= PWR_CR_LPDS &#124; PWR_CR_PDDS;

  // set sleepdeep in the system control register
  SCB_BASE-&#38;gt;SCR &#124;= SCB_SCR_SLEEPDEEP;

  // Now go into stop mode, wake up on interrupt
  asm(&#38;quot;    wfi&#38;quot;);

  digitalWrite(BOARD_LED_PIN, ledState);
  togglePin(3);

}

// Interrupt Service Routine (ISR)
void blinkState()
{
    ledState=!ledState;
    waitForButtonPress();    // Dangerous in ISR, I know, but quick demo only so blah.
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;It pretty much came down 2 lines of code in the end. Doesn't seem like much, but it took 30 pages of docs to get there. I'm guessing it's not in any way robust, but at least it's a starting point. It should work with the RTC as Rod mentioned or any external interrupt. I'm not sure whether I have to clear flags in the ISR or not.&#60;/p&#62;
&#60;p&#62;The main problem is that the SerialUSB goes down, I don't know whether re-init it would help.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Rod on "What about low-power modes?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1437#post-8558</link>
			<pubDate>Fri, 09 Mar 2012 16:18:27 +0000</pubDate>
			<dc:creator>Rod</dc:creator>
			<guid isPermaLink="false">8558@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I was working on low power sleep modes when I wrote the RTC device driver. The RTC is the way to wake up from very low power sleep. You'll want to get that working first on whatever board you are using. It is known to work on the Olimexino and Maple Mini.&#60;/p&#62;
&#60;p&#62;You can access the code on github as rodgilchrist/libmaple (take the whole libmaple directory). There is an outstanding pull request out to Leaf Labs.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>higwoshy on "What about low-power modes?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1437#post-8553</link>
			<pubDate>Fri, 09 Mar 2012 15:15:04 +0000</pubDate>
			<dc:creator>higwoshy</dc:creator>
			<guid isPermaLink="false">8553@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ok, thanks. If I came up with anything useful I'll post it here.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "What about low-power modes?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1437#post-8551</link>
			<pubDate>Fri, 09 Mar 2012 14:59:50 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">8551@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;higwoshy - I'd recommend getting those ST Micro application notes and libraries linked to from &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1437#post-8535&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1437#post-8535&#60;/a&#62;. &#60;/p&#62;
&#60;p&#62;I think they give enough information and examples to get into low-power modes.&#60;/p&#62;
&#60;p&#62;According to the RM0008 manual, rev 14, page 602:&#60;br /&#62;
&#34;Due to USB data rate and packet memory interface requirements, the APB1 clock frequency must be greater than 8 MHz to avoid data overrun/underrun problems.&#34;&#60;/p&#62;
&#60;p&#62;IIRC you could set the systick so that it wakes up every second or so, which should be much lower power, and easy to test.&#60;br /&#62;
The systick timer is 24bits, so it will count to roughly 16 million, and it's clock signal can be the system clock/8 (I think this is the libmaple default), giving a maximum count of roughly 128 million cycles.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>higwoshy on "What about low-power modes?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1437#post-8546</link>
			<pubDate>Fri, 09 Mar 2012 12:54:50 +0000</pubDate>
			<dc:creator>higwoshy</dc:creator>
			<guid isPermaLink="false">8546@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I haven't managed to get a scope on it to see (lack of time), but it seems likely that it's the systick timer, but I don't know the maple well enough. &#60;/p&#62;
&#60;p&#62;I think I meant to say &#60;code&#62;systick_init&#60;/code&#62; which is in the systick.h. I was thinking that if I slowed down the main clock by 4, I could just call systick_init (normal value / 4) to have delays etc still working, but it seems that won't work.&#60;/p&#62;
&#60;p&#62;As to sleeping, I'm going to have a look at getting the maple to sleep. So...disable the systick and call one of the sleep instructions? Obviously I need to setup a handler to deal with waking up, but just getting it to sleep is a step in the right direction. Thanks.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "What about low-power modes?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1437#post-8543</link>
			<pubDate>Fri, 09 Mar 2012 10:36:18 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">8543@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;higwoshy -&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;I've tried the two sleep instructions but had no luck as they seem to return instantly
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;When you say 'instantly', do you mean on the next instruction, or do you mean within a millisecond? The systick timer is going to trigger every millisecond, which should wake Maple up.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;I'm toying with the idea of using &#60;code&#62;sys_init ( n )&#60;/code&#62; ...
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;What does &#60;code&#62;sys_init()&#60;/code&#62; do? I haven't found that in the Maple library source.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>higwoshy on "What about low-power modes?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1437#post-8539</link>
			<pubDate>Fri, 09 Mar 2012 07:33:18 +0000</pubDate>
			<dc:creator>higwoshy</dc:creator>
			<guid isPermaLink="false">8539@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I know this is only a partial solution(?) but, for now, if I want lowish power consumption I just slow down the main cpu:-&#60;/p&#62;
&#60;p&#62;'// slow! div speed. NOTE! 512 is stop/hang when USB not connected!&#60;br /&#62;
'rcc_set_prescaler(RCC_PRESCALER_AHB, RCC_AHB_SYSCLK_DIV_256);  &#60;/p&#62;
&#60;p&#62;// Normal speed&#60;br /&#62;
rcc_set_prescaler(RCC_PRESCALER_AHB, RCC_AHB_SYSCLK_DIV_1);&#60;br /&#62;
'&#60;br /&#62;
This gets the current down to about 8-9ma for slow speed. The only problem is that the SerialUSB may stop working, even when you go back to normal speed before a print. Obviously all the delays() etc in your code will be massively out as well.&#60;/p&#62;
&#60;p&#62;I'm toying with the idea of using &#60;code&#62;sys_init ( n )&#60;/code&#62; to change the ticks speed, but I haven't tried it yet due to lack of time. Any maple experts used this, know what effect it has?&#60;/p&#62;
&#60;p&#62;I've tried the two sleep instructions but had no luck as they seem to return instantly, but I'm just hacking around until a proper solution surfaces. I'm guessing it's because something in the core libraries is instantly waking up the maple from sleep?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "What about low-power modes?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1437#post-8535</link>
			<pubDate>Fri, 09 Mar 2012 05:47:33 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">8535@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Gravity - it might be worth getting the ST Micro application note:&#60;br /&#62;
&#34;AN2629 Application note: STM32F101xx, STM32F102xx and STM32F103xx low-power modes&#34;&#60;br /&#62;
at&#60;br /&#62;
&#60;a href=&#34;http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/APPLICATION_NOTE/CD00171691.pdf&#34; rel=&#34;nofollow&#34;&#62;http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/APPLICATION_NOTE/CD00171691.pdf&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;and the accompanying firmware&#60;br /&#62;
&#60;a href=&#34;http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/FIRMWARE/an2629.zip&#34; rel=&#34;nofollow&#34;&#62;http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/FIRMWARE/an2629.zip&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;It is also probably worth downloading the firmware &#34;STM32F10x standard peripheral library&#34; (and its application note), and &#34;STM32Fx firmware library&#34; and its documentation (under resources) from:&#60;br /&#62;
&#60;a href=&#34;http://www.st.com/stonline/stappl/resourceSelector/app?page=resourceSelector&#38;amp;doctype=FIRMWARE&#38;amp;SubClassID=1169&#34; rel=&#34;nofollow&#34;&#62;http://www.st.com/stonline/stappl/resourceSelector/app?page=resourceSelector&#38;amp;doctype=FIRMWARE&#38;amp;SubClassID=1169&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;AFAIK, the links you posted are to code from ST, for example in the &#34;STM32F10x standard peripheral library&#34;.&#60;br /&#62;
There may also be a project in their which lets you test things.&#60;br /&#62;
Sadly LeafLabs don't use the same interrupt vector names as ST, and ST don't provide startup code and link scripts, so it'll likely be hard to build.&#60;/p&#62;
&#60;p&#62;(Full disclosure: I am not a member of LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Gravity on "What about low-power modes?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1437#post-8532</link>
			<pubDate>Fri, 09 Mar 2012 04:41:05 +0000</pubDate>
			<dc:creator>Gravity</dc:creator>
			<guid isPermaLink="false">8532@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I was checking out pwr.h in the api&#60;br /&#62;
&#60;a href=&#34;http://leaflabs.com/docs/libmaple/api/pwr.html&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/libmaple/api/pwr.html&#60;/a&#62;&#60;br /&#62;
because I want to put the Maple into low power or sleep mode.&#60;/p&#62;
&#60;p&#62;At first I just tried selecting standby mode&#60;/p&#62;
&#60;p&#62;&#60;code&#62;PWR_BASE-&#38;gt;CR &#124;= PWR_CR_PDDS;&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;but it didn't seem to work, probably because that's not even close to the solution. So I started searching around the web and came across these gems&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://brawikov.narod.ru/StdPerLibSTM32F10x/stm32f10x__pwr_8c_source.html#l00197&#34; rel=&#34;nofollow&#34;&#62;http://brawikov.narod.ru/StdPerLibSTM32F10x/stm32f10x__pwr_8c_source.html#l00197&#60;/a&#62;&#60;br /&#62;
&#60;a href=&#34;http://brawikov.narod.ru/StdPerLibSTM32F10x/stm32f10x__pwr_8c_source.html#l00236&#34; rel=&#34;nofollow&#34;&#62;http://brawikov.narod.ru/StdPerLibSTM32F10x/stm32f10x__pwr_8c_source.html#l00236&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;so there is obviously more to it. So I just want to know if anyone has worked on this with the maple, or knows how to tackle it.&#60;/p&#62;
&#60;p&#62;Thanks.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
