Skip to content

Commit eb00dbe

Browse files
Replace STM32L0.stop() by STM32L0.deepsleep(); add STM32L0.enablePowerSave() / STM32L0.disablePowerSave() to allow better default power savings
1 parent 8bca76e commit eb00dbe

File tree

11 files changed

+41
-12
lines changed

11 files changed

+41
-12
lines changed

cores/arduino/delay.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void delay(uint32_t timeout)
5959
{
6060
timeout = end - now;
6161

62-
stm32l0_system_sleep(STM32L0_SYSTEM_POLICY_RUN, timeout);
62+
stm32l0_system_sleep(g_defaultPolicy, timeout);
6363

6464
now = millis();
6565
}

cores/arduino/wiring.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ void HardFault_Handler(void)
6969

7070
int g_swdStatus = 0;
7171

72+
int g_defaultPolicy = STM32L0_SYSTEM_POLICY_RUN;
73+
7274
uint32_t g_wakeupControl = 0;
7375

7476
void init( void )

cores/arduino/wiring_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ extern void WMSGSM42_Initialize(void);
7575

7676
extern int g_swdStatus; /* 0, default, 1 = enable, 2 = disable, 3 = forced disable */
7777

78+
extern int g_defaultPolicy;
79+
7880
extern uint32_t g_wakeupControl;
7981

8082
extern void (*g_serialEventRun)(void);

libraries/DOSFS/examples/DOSFS_DataLogger/DOSFS_DataLogger.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* that if no wok is pending, the SDCARD/SFLASH can go
1616
* to sleep, hence consuming less power.
1717
*
18-
* The loop is run every 5 seconds (STM32L0.stop() to
18+
* The loop is run every 5 seconds (STM32L0.deepsleep() to
1919
* put STM32L0 into STOP mode). Every 60 seconds the current
2020
* log file is printed out.
2121
*
@@ -75,7 +75,7 @@ void loop( void )
7575
}
7676
}
7777

78-
STM32L0.stop(5000);
78+
STM32L0.deepsleep(5000);
7979
}
8080

8181

libraries/GNSS/examples/GNSS_periodic/GNSS_periodic.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void setup( void )
3333

3434
void loop( void )
3535
{
36-
STM32L0.stop();
36+
STM32L0.deepsleep();
3737

3838
if (GNSS.location(myLocation))
3939
{

libraries/GNSS/examples/GNSS_suspend/GNSS_suspend.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void setup( void )
5454

5555
void loop( void )
5656
{
57-
STM32L0.stop();
57+
STM32L0.deepsleep();
5858

5959
if (GNSS.location(myLocation))
6060
{

libraries/LoRaWAN/examples/LoRaWAN_DeepSleep/LoRaWAN_DeepSleep.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* The code joins the network and sends 50 packets. Then it
44
* shuts down the USB connection (which blocks STOP mode),
5-
* and then uses STM32L0.stop() instead of delay() to
5+
* and then uses STM32L0.deepsleep() instead of delay() to
66
* wait. STOP mode consumes about 2.1uA for the MCU and
77
* SX1272/SX176. SLEEP mode (which is used during delay())
88
* consumes about 2mA.
@@ -132,6 +132,6 @@ void loop( void )
132132
}
133133
else
134134
{
135-
STM32L0.stop(30000);
135+
STM32L0.deepsleep(30000);
136136
}
137137
}

libraries/LoRaWAN/examples/LoRaWAN_TimerMillis/LoRaWAN_TimerMillis.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Idea is to start a periodic timer, where every 10 seconds a packet
44
* is send to the gateway in the background. The main "loop()" could
5-
* be reading sensors in the forground, or use STM32L0.stop() to enter
5+
* be reading sensors in the forground, or use STM32L0.deepsleep() to enter
66
* STOP mode.
77
*
88
* In setup() below please replace the argument to LoRaWAN.begin()

libraries/STM32L0/keywords.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ getVREF KEYWORD2
1919
getTemperature KEYWORD2
2020
resetCause KEYWORD2
2121
wakeupReason KEYWORD2
22+
enablePowerSave KEYWORD2
23+
disablePowerSave KEYWORD2
2224
wakeup KEYWORD2
2325
sleep KEYWORD2
24-
stop KEYWORD2
26+
deepsleep KEYWORD2
2527
standby KEYWORD2
2628
reset KEYWORD2
29+
dfu KEYWORD2
2730
wdtEnable KEYWORD2
2831
wdtReset KEYWORD2
2932
flashErase KEYWORD2

libraries/STM32L0/src/STM32L0.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,27 @@ uint32_t STM32L0Class::wakeupReason()
119119
return stm32l0_system_wakeup_reason();
120120
}
121121

122+
void STM32L0Class::enablePowerSave()
123+
{
124+
g_defaultPolicy = STM32L0_SYSTEM_POLICY_SLEEP;
125+
}
126+
127+
void STM32L0Class::disablePowerSave()
128+
{
129+
g_defaultPolicy = STM32L0_SYSTEM_POLICY_RUN;
130+
}
131+
122132
void STM32L0Class::wakeup()
123133
{
124134
stm32l0_system_wakeup();
125135
}
126136

127137
void STM32L0Class::sleep(uint32_t timeout)
128138
{
129-
stm32l0_system_sleep(STM32L0_SYSTEM_POLICY_SLEEP, timeout);
139+
stm32l0_system_sleep(g_defaultPolicy, timeout);
130140
}
131141

132-
void STM32L0Class::stop(uint32_t timeout)
142+
void STM32L0Class::deepsleep(uint32_t timeout)
133143
{
134144
if (g_swdStatus == 0) {
135145
stm32l0_system_swd_disable();
@@ -150,6 +160,11 @@ void STM32L0Class::reset()
150160
stm32l0_system_reset();
151161
}
152162

163+
void STM32L0Class::dfu()
164+
{
165+
stm32l0_system_dfu();
166+
}
167+
153168
void STM32L0Class::swdEnable()
154169
{
155170
if (g_swdStatus != 3) {

libraries/STM32L0/src/STM32L0.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ class STM32L0Class {
6262
uint32_t resetCause();
6363
uint32_t wakeupReason();
6464

65+
void enablePowerSave();
66+
void disablePowerSave();
6567
void wakeup();
6668
void sleep(uint32_t timeout = 0xffffffff);
67-
void stop(uint32_t timeout = 0xffffffff);
69+
void deepsleep(uint32_t timeout = 0xffffffff);
6870
void standby(uint32_t timeout = 0xffffffff);
6971
void reset();
72+
void dfu();
7073

7174
void swdEnable();
7275
void swdDisable();
@@ -76,6 +79,10 @@ class STM32L0Class {
7679

7780
bool flashErase(uint32_t address, uint32_t count);
7881
bool flashProgram(uint32_t address, const void *data, uint32_t count);
82+
83+
public:
84+
void stop(uint32_t timeout = 0xffffffff) __attribute__((deprecated("use STM32L0.deepsleep() instead"))) { deepsleep(timeout); }
85+
7986
};
8087

8188
extern STM32L0Class STM32L0;

0 commit comments

Comments
 (0)