Skip to content
This repository was archived by the owner on Feb 21, 2020. It is now read-only.

Commit 4108222

Browse files
DHJeffsergiotomasello
authored andcommitted
Added STM32PWR library
1 parent 93b6914 commit 4108222

File tree

6 files changed

+261
-0
lines changed

6 files changed

+261
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
SleepMode.ino
3+
4+
Written by Jeff Wu (jeff@arduino.org)
5+
6+
This example for the Arduino Primo board shows how to use
7+
stm32pwr library.
8+
The STM32 has two functions for power savings. One is sleep mode,
9+
and the other is standby mode. The USER1 BUTTON allows you setup
10+
as an interrupt to trigger STM32 enter to sleep mode or wake up
11+
from sleep mode. When the Primo board is powered by USB cable and
12+
battery, and then disconnect the USB cable, the STM32 will enter
13+
to standby mode or the Primo board is only powered by battery.
14+
Waiting for Primo board reconnect to USB cable to wake up from
15+
standby mode. The disableStandbyMode() function allows you to
16+
disable STM32 enter to standby mode when the Primo disconnect
17+
the USB cable.
18+
19+
This example code is in the public domain.
20+
21+
*/
22+
23+
#include <stm32pwr.h>
24+
25+
void setup() {
26+
// start serial port at 9600 bps
27+
Serial.begin(9600);
28+
// setup USER1_BUTTON as an interrupt to trigger STM32
29+
// enter to sleep mode or wake up from sleep mode
30+
stm32pwr.enableSleepMode();
31+
// disable STM32 enter to standby mode
32+
stm32pwr.disableStandbyMode() ;
33+
}
34+
35+
void loop() {
36+
//Waiting for USER1 BUTTON press trigger STM32 enter to sleep mode
37+
Serial.println("Waiting for USER1 BUTTON press");
38+
delay(5000);
39+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
WiFiPowerManagement.ino
3+
4+
Written by Jeff Wu (jeff@arduino.org)
5+
6+
This example for the Arduino Primo board shows how to use
7+
stm32pwr library.
8+
The STM32 is able to turn the WiFi on or off directly,
9+
Reducing the power consumption of Primo board.
10+
11+
This example code is in the public domain.
12+
13+
*/
14+
15+
#include <stm32pwr.h>
16+
17+
int reading; // the current reading from the input pin
18+
int state = true; //variable for setting WiFi status
19+
long last_time = 0; // the last time the output pin was toggled
20+
long debounce = 200; // the debounce time, increase if the output flickers
21+
22+
void setup() {
23+
// initialize the pushbutton pin as an input:
24+
pinMode(USER2_BUTTON, INPUT);
25+
}
26+
27+
void loop() {
28+
// read the state of the USER2 BUTTON value:
29+
reading = digitalRead(USER2_BUTTON);
30+
31+
// if the input is LOW and we've Waiting long enough to ignore any noise
32+
// on the circuit, toggle the output pin and remember the time
33+
if(reading == 0 && millis() - last_time > debounce ) {
34+
state = !state; // reverse state
35+
if(state == true) {
36+
stm32pwr.powerOnWiFi(); //turn the WiFi on
37+
stm32pwr.enableWiFi(); //enable WiFi
38+
}
39+
else {
40+
stm32pwr.powerOffWiFi(); //turn the WiFi off
41+
stm32pwr.disableWiFi(); //disable WiFi
42+
}
43+
last_time = millis();
44+
}
45+
}

libraries/STM32PWR/keywords.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#######################################
2+
# Syntax Coloring Map stm32pwr
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
stm32pwr KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
powerOnWiFi KEYWORD2
16+
powerOffWiFi KEYWORD2
17+
enableWiFi KEYWORD2
18+
disableWiFi KEYWORD2
19+
enableSleepMode KEYWORD2
20+
disableStandbyMode KEYWORD2
21+
22+
#######################################
23+
# Constants (LITERAL1)
24+
#######################################
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=STM32PWR
2+
version=0.0.1
3+
author=Jeff Wu <jeff@arduino.org>
4+
maintainer=Arduino <swdev@arduino.org>
5+
sentence=stm32pwr
6+
paragraph=Allows STM32 enter to Sleep mode or standby mode
7+
category=Communication
8+
url=http://www.arduino.org/learning/reference/stm32pwr
9+
architectures=nrf52

libraries/STM32PWR/stm32pwr.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
****************************************************************************
3+
* Copyright (c) 2017 Arduino srl. All right reserved.
4+
*
5+
* File : stm32pwr.cpp
6+
* Date : 2017/04/30
7+
* Revision : 0.0.1 $
8+
* Author: jeff[at]arduino[dot]org
9+
*
10+
****************************************************************************
11+
12+
This library is free software; you can redistribute it and/or
13+
modify it under the terms of the GNU Lesser General Public
14+
License as published by the Free Software Foundation; either
15+
version 2.1 of the License, or (at your option) any later version.
16+
17+
This library is distributed in the hope that it will be useful,
18+
but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20+
Lesser General Public License for more details.
21+
22+
You should have received a copy of the GNU Lesser General Public
23+
License along with this library; if not, write to the Free Software
24+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25+
*/
26+
27+
28+
#include "stm32pwr.h"
29+
30+
31+
32+
void stm32pwrClass::powerOnWiFi()
33+
{
34+
digitalWrite(GPIO_ESP_PW, HIGH);
35+
}
36+
37+
void stm32pwrClass::powerOffWiFi()
38+
{
39+
digitalWrite(GPIO_ESP_PW, LOW);
40+
}
41+
42+
void stm32pwrClass::enableWiFi()
43+
{
44+
digitalWrite(GPIO_ESP_EN, HIGH);
45+
}
46+
47+
void stm32pwrClass::disableWiFi()
48+
{
49+
digitalWrite(GPIO_ESP_EN, LOW);
50+
}
51+
52+
void stm32pwrClass::enableSleepMode()
53+
{
54+
pinMode(USER1_BUTTON, STM32_IT);
55+
}
56+
57+
void stm32pwrClass::disableStandbyMode()
58+
{
59+
pinMode(BAT_VOL, INPUT);
60+
}
61+
62+
63+
stm32pwrClass stm32pwr;

libraries/STM32PWR/stm32pwr.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
****************************************************************************
3+
* Copyright (c) 2017 Arduino srl. All right reserved.
4+
*
5+
* File : stm32pwr.h
6+
* Date : 2017/04/30
7+
* Revision : 0.0.1 $
8+
* Author: jeff[at]arduino[dot]org
9+
*
10+
****************************************************************************
11+
12+
This library is free software; you can redistribute it and/or
13+
modify it under the terms of the GNU Lesser General Public
14+
License as published by the Free Software Foundation; either
15+
version 2.1 of the License, or (at your option) any later version.
16+
17+
This library is distributed in the hope that it will be useful,
18+
but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20+
Lesser General Public License for more details.
21+
22+
You should have received a copy of the GNU Lesser General Public
23+
License along with this library; if not, write to the Free Software
24+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25+
*/
26+
27+
28+
#ifndef STM32PWR_h
29+
#define STM32PWR_h
30+
31+
#include "Arduino.h"
32+
33+
#ifdef __cplusplus
34+
extern "C" {
35+
#endif
36+
#ifdef __cplusplus
37+
}
38+
#endif
39+
40+
41+
class stm32pwrClass{
42+
43+
public:
44+
45+
/**
46+
* \turn the WiFi on
47+
*/
48+
void powerOnWiFi(void) ;
49+
50+
/**
51+
* \turn the WiFi off
52+
*/
53+
void powerOffWiFi(void) ;
54+
55+
/**
56+
* \enable WiFi
57+
*/
58+
void enableWiFi(void) ;
59+
60+
/**
61+
* \disable WiFi
62+
*/
63+
void disableWiFi(void) ;
64+
65+
/**
66+
* \setup USER1_BUTTON as an interrupt to trigger STM32 enter to sleep mode or wake up from sleep mode
67+
*/
68+
void enableSleepMode(void) ;
69+
70+
/**
71+
* \disable STM32 enter to standby mode
72+
*/
73+
void disableStandbyMode(void) ;
74+
75+
private:
76+
77+
};
78+
79+
extern stm32pwrClass stm32pwr;
80+
81+
#endif //STM32PWR_h

0 commit comments

Comments
 (0)