Skip to content

Commit 2c68a63

Browse files
authored
Merge pull request #7 from alrvid/main
Fix function order and improve documentation
2 parents 8d936ff + 4bf6436 commit 2c68a63

File tree

4 files changed

+83
-78
lines changed

4 files changed

+83
-78
lines changed

Diff for: docs/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ The microcontroller has three power domains: one for the M7 core (D1), one for t
2626

2727
All configuration of Standby Mode is done when calling `standbyM7()`. It takes one or two parameters, depending on the conditions you want to set for waking up. The first parameter is one of the flags `LowPowerStandbyType::untilPinActivity` and `LowPowerStandbyType::untilTimeElapsed`. If you want to wake up from either type of event, you can combine the flags like so: `LowPowerStandbyType::untilPinActivity | LowPowerStandbyType::untilTimeElapsed`. If `LowPowerStandbyType::untilTimeElapsed` is present, the function takes a second parameter. This parameter's preferred format is `2_h + 30_min + 45_s`. You can use any combination of hours, minutes, and seconds. For example, `15_h`, or `1_h + 30_min`, or just `90_s`. If you first have to calculate the delay in your sketch, you can also pass something like this: `RTCWakeupDelay(1, 20, 30)`. The first number is hours, the second minutes, and the third seconds. But, the preferred option is to use _h, _min, and _s since that's more explicit.
2828

29+
When the microcontroller wakes up again from Standby Mode, both the M7 and the M4 cores do so in parallel.
30+
2931
> [!IMPORTANT]
30-
> You must always upload a sketch to the M4 core, in which you call `standbyM4()`, even if you don't intend to use the M4 core. If you don't, the microcontroller won't enter Standby Mode as a whole, even if you call `standbyM7()`.
32+
> You must always upload a sketch to the M4 core, in which you call `standbyM4()`, even if you don't intend to use the M4 core. If you don't, the microcontroller won't enter Standby Mode as a whole, even if you call `standbyM7()`, and that will lead to an increased power consumption.
3133
3234
## 👀 Examples
3335

Diff for: docs/api.md

+27-27
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
Members | Descriptions
44
--------------------------------|---------------------------------------------
55
`class ` [`LowPowerPortentaH7`](#class_low_power_portenta_h7) | A class that provides low power functionality for the Portenta H7 board.
6-
`class ` [`LowPowerStandbyType`](#class_low_power_standby_type) | The [LowPowerStandbyType](#class_low_power_standby_type) class represents different types of standby modes for low power operation.
7-
`class ` [`RTCWakeupDelay`](#class_r_t_c_wakeup_delay) | The [RTCWakeupDelay](#class_r_t_c_wakeup_delay) class represents a delay before waking up from a low power mode.
6+
`class ` [`LowPowerStandbyType`](#class_low_power_standby_type) | The [LowPowerStandbyType](#class_low_power_standby_type) class represents different methods of wakeup.
7+
`class ` [`RTCWakeupDelay`](#class_r_t_c_wakeup_delay) | The [RTCWakeupDelay](#class_r_t_c_wakeup_delay) class represents a delay before waking up from Standby Mode.
88

99
# class `LowPowerPortentaH7` <a id="class_low_power_portenta_h7" class="anchor"></a>
1010

1111
A class that provides low power functionality for the Portenta H7 board.
1212

13-
The [LowPowerPortentaH7](#class_low_power_portenta_h7) class allows the microcontroller on the Portenta H7 board to enter low power modes such as Standby Mode and Deep Sleep Mode. It provides functions to check the current mode, prepare the option bytes for entering Standby Mode, and control the M4 and M7 cores independently. It also provides functions to measure the time since boot, time spent in idle, sleep, and deep sleep modes.
13+
The [LowPowerPortentaH7](#class_low_power_portenta_h7) class allows the microcontroller on the Portenta H7 board to enter low power modes such as Standby Mode and Deep Sleep Mode. It provides functions to check the mode before startup, prepare the option bytes for entering Standby Mode, and control the M4 and M7 cores independently. It also provides functions to measure the time since boot, time spent in Idle, Sleep, and Deep Sleep modes.
1414

1515
This class is a singleton and shall always be accessed through the global LowPower object.
1616

@@ -23,16 +23,16 @@ This class is specific to the Portenta H7 board.
2323
| [`allowDeepSleep`](#class_low_power_portenta_h7_1a7ed518f8205a0b7306d23b7e2a22e82b) | Make Deep Sleep possible in the default case. |
2424
| [`canDeepSleep`](#class_low_power_portenta_h7_1a07d9e0f356e40ac70655e279fbad87a9) | Check if Deep Sleep is possible or not at the moment. |
2525
| [`checkOptionBytes`](#class_low_power_portenta_h7_1a7519d3acf693f450af84312576d8e669) | Check if the option bytes are correct to enter Standby Mode. |
26-
| [`wasInCPUMode`](#class_low_power_portenta_h7_1ae2059eb4fb01a30342b9fb6918b6ab4c) | Checks if the microcontroller was in the given CPU mode before starting. Note: It's possible that the microcontroller was in more than one of these modes before starting. Call this function multiple times to check for each mode. Important: When you're done checking, call resetStandbyModeFlags() to reset the flags so they are reported correctly the next time the microcontroller starts. |
2726
| [`resetPreviousCPUModeFlags`](#class_low_power_portenta_h7_1a1753e3c053b2b64b59da3cbb9b921d76) | Reset the flags that are used to determine the microcontroller's previous CPU mode. This is necessary to get correct results from [wasInCPUMode()](#class_low_power_portenta_h7_1ae2059eb4fb01a30342b9fb6918b6ab4c). |
2827
| [`numberOfDeepSleepLocks`](#class_low_power_portenta_h7_1a9d2730d86abf42782261b0f03778c3bb) | Check how many Deep Sleep locks are held at the moment. |
2928
| [`prepareOptionBytes`](#class_low_power_portenta_h7_1abdc0ce13b68d3a2188702690997af2ae) | Prepare the option bytes for entry into Standby Mode. |
30-
| [`standbyM4`](#class_low_power_portenta_h7_1a9e07fd4f7895a7753e7e28f99aca1ace) | Make the M4 core enter Standby Mode. |
31-
| [`standbyM7`](#class_low_power_portenta_h7_1aa9c1cb86c832c35f6653a3d6c9f0d32f) | Make the M7 core enter Standby Mode. |
29+
| [`standbyM4`](#class_low_power_portenta_h7_1a9e07fd4f7895a7753e7e28f99aca1ace) | Make the M4 core and D2 domain enter standby mode. |
30+
| [`standbyM7`](#class_low_power_portenta_h7_1aa9c1cb86c832c35f6653a3d6c9f0d32f) | Make the M7 core and D1 domain enter standby mode, and make it possible for the D3 domain to do so too. |
3231
| [`timeSinceBoot`](#class_low_power_portenta_h7_1a4758c25574b6d099545ac8d55eff6f68) | Time since the board was booted. It reports the time since the last wake-up reset (after being in Standby Mode) or power-on depending on what happened last. |
33-
| [`timeSpentIdle`](#class_low_power_portenta_h7_1ad42fdfa6885d8e0fdca5aa012fdb4c60) | Time spent in idle. |
32+
| [`timeSpentIdle`](#class_low_power_portenta_h7_1ad42fdfa6885d8e0fdca5aa012fdb4c60) | Time spent in Idle Mode. |
3433
| [`timeSpentInSleep`](#class_low_power_portenta_h7_1a994eb6fcc0382515a82b81fa37ca9f3c) | Time spent in Sleep Mode. |
3534
| [`timeSpentInDeepSleep`](#class_low_power_portenta_h7_1a146eb61800a74360687fd34b456c0b44) | Time spent in Deep Sleep Mode. |
35+
| [`wasInCPUMode`](#class_low_power_portenta_h7_1ae2059eb4fb01a30342b9fb6918b6ab4c) | Checks if the microcontroller was in the given CPU mode before starting. Note: It's possible that the microcontroller was in more than one of these modes before starting. Call this function multiple times to check for each mode. Important: When you're done checking, call resetStandbyModeFlags() to reset the flags so they are reported correctly the next time the microcontroller starts. |
3636

3737
## Members
3838

@@ -70,20 +70,6 @@ Check if the option bytes are correct to enter Standby Mode.
7070
A constant from the LowPowerReturnCode enum.
7171
<hr />
7272

73-
### `wasInCPUMode` <a id="class_low_power_portenta_h7_1ae2059eb4fb01a30342b9fb6918b6ab4c" class="anchor"></a>
74-
75-
```cpp
76-
bool wasInCPUMode( CPUMode mode) const
77-
```
78-
79-
Checks if the microcontroller was in the given CPU mode before starting. Note: It's possible that the microcontroller was in more than one of these modes before starting. Call this function multiple times to check for each mode. Important: When you're done checking, call resetStandbyModeFlags() to reset the flags so they are reported correctly the next time the microcontroller starts.
80-
#### Parameters
81-
* `mode` The CPU mode to check.
82-
83-
#### Returns
84-
True if the microcontroller was in the given mode, false otherwise.
85-
<hr />
86-
8773
### `resetPreviousCPUModeFlags` <a id="class_low_power_portenta_h7_1a1753e3c053b2b64b59da3cbb9b921d76" class="anchor"></a>
8874

8975
```cpp
@@ -124,7 +110,7 @@ A constant from the LowPowerReturnCode enum.
124110
LowPowerReturnCode standbyM4() const
125111
```
126112

127-
Make the M4 core enter Standby Mode.
113+
Make the M4 core and D2 domain enter standby mode.
128114

129115
#### Returns
130116
A constant from the LowPowerReturnCode enum.
@@ -136,7 +122,7 @@ A constant from the LowPowerReturnCode enum.
136122
LowPowerReturnCode standbyM7(const T standbyType, const Args... args) const
137123
```
138124
139-
Make the M7 core enter Standby Mode.
125+
Make the M7 core and D1 domain enter standby mode, and make it possible for the D3 domain to do so too.
140126
141127
#### Parameters
142128
* `standbyType` One or a combination of [LowPowerStandbyType::untilPinActivity](#class_low_power_standby_type_1a4c5b50ac615cf60ff88dd3b9bb145fa9) and [LowPowerStandbyType::untilTimeElapsed](#class_low_power_standby_type_1aa4882e571c0e9444c5978c8520e8e90e). The combination is done with the | operator.
@@ -165,7 +151,7 @@ Number of microseconds.
165151
uint64_t timeSpentIdle() const
166152
```
167153

168-
Time spent in idle.
154+
Time spent in Idle Mode.
169155

170156
#### Returns
171157
Number of microseconds.
@@ -195,11 +181,25 @@ Time spent in Deep Sleep Mode.
195181
Number of microseconds.
196182
<hr />
197183

184+
### `wasInCPUMode` <a id="class_low_power_portenta_h7_1ae2059eb4fb01a30342b9fb6918b6ab4c" class="anchor"></a>
185+
186+
```cpp
187+
bool wasInCPUMode( CPUMode mode) const
188+
```
189+
190+
Checks if the microcontroller was in the given CPU mode before starting. Note: It's possible that the microcontroller was in more than one of these modes before starting. Call this function multiple times to check for each mode. Important: When you're done checking, call resetStandbyModeFlags() to reset the flags so they are reported correctly the next time the microcontroller starts.
191+
#### Parameters
192+
* `mode` The CPU mode to check.
193+
194+
#### Returns
195+
True if the microcontroller was in the given mode, false otherwise.
196+
<hr />
197+
198198
# class `LowPowerStandbyType` <a id="class_low_power_standby_type" class="anchor"></a>
199199
200-
The [LowPowerStandbyType](#class_low_power_standby_type) class represents different types of standby modes for low power operation.
200+
The [LowPowerStandbyType](#class_low_power_standby_type) class represents different methods of wakeup.
201201
202-
This class provides options for the following standby modes: waiting until pin activity or until a specified time has elapsed, or both. Those are represented by [LowPowerStandbyType::untilPinActivity](#class_low_power_standby_type_1a4c5b50ac615cf60ff88dd3b9bb145fa9) and [LowPowerStandbyType::untilTimeElapsed](#class_low_power_standby_type_1aa4882e571c0e9444c5978c8520e8e90e). To combine the two options use the | operator.
202+
This class provides options for the following methods of wakeup: waiting until pin activity or until a specified time has elapsed, or both. Those are represented by [LowPowerStandbyType::untilPinActivity](#class_low_power_standby_type_1a4c5b50ac615cf60ff88dd3b9bb145fa9) and [LowPowerStandbyType::untilTimeElapsed](#class_low_power_standby_type_1aa4882e571c0e9444c5978c8520e8e90e). To combine the two options use the | operator.
203203
204204
## Summary
205205
@@ -210,7 +210,7 @@ This class provides options for the following standby modes: waiting until pin a
210210
211211
# class `RTCWakeupDelay` <a id="class_r_t_c_wakeup_delay" class="anchor"></a>
212212
213-
The [RTCWakeupDelay](#class_r_t_c_wakeup_delay) class represents a delay before waking up from a low power mode.
213+
The [RTCWakeupDelay](#class_r_t_c_wakeup_delay) class represents a delay before waking up from Standby Mode.
214214
215215
## Summary
216216

Diff for: src/Arduino_LowPowerPortentaH7.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -210,27 +210,6 @@ LowPowerReturnCode LowPowerPortentaH7::checkOptionBytes() const
210210
return LowPowerReturnCode::success;
211211
}
212212

213-
bool LowPowerPortentaH7::wasInCPUMode(CPUMode mode) const
214-
{
215-
const auto registerValue = PWR->CPUCR;
216-
217-
switch (mode)
218-
{
219-
case CPUMode::d1DomainStandby:
220-
return registerValue & PWR_CPUCR_SBF_D1;
221-
case CPUMode::d2DomainStandby:
222-
return registerValue & PWR_CPUCR_SBF_D2;
223-
case CPUMode::standby:
224-
return registerValue & PWR_CPUCR_SBF;
225-
case CPUMode::stop:
226-
return registerValue & PWR_CPUCR_STOPF;
227-
default:
228-
return false;
229-
}
230-
231-
return false;
232-
}
233-
234213
void LowPowerPortentaH7::resetPreviousCPUModeFlags() const
235214
{
236215
PWR->CPUCR |= PWR_CPUCR_CSSF;
@@ -395,3 +374,24 @@ void LowPowerPortentaH7::waitForFlashReady() const
395374
while ((FLASH->SR1 & 0x07) || (FLASH->SR2 & 0x07))
396375
;
397376
}
377+
378+
bool LowPowerPortentaH7::wasInCPUMode(CPUMode mode) const
379+
{
380+
const auto registerValue = PWR->CPUCR;
381+
382+
switch (mode)
383+
{
384+
case CPUMode::d1DomainStandby:
385+
return registerValue & PWR_CPUCR_SBF_D1;
386+
case CPUMode::d2DomainStandby:
387+
return registerValue & PWR_CPUCR_SBF_D2;
388+
case CPUMode::standby:
389+
return registerValue & PWR_CPUCR_SBF;
390+
case CPUMode::stop:
391+
return registerValue & PWR_CPUCR_STOPF;
392+
default:
393+
return false;
394+
}
395+
396+
return false;
397+
}

Diff for: src/Arduino_LowPowerPortentaH7.h

+32-29
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
/**
4141
* @enum LowPowerReturnCode
42-
* @brief Provides the return codes for the standby operations.
42+
* @brief Provides the return codes for the API functions of the library.
4343
* The codes indicate the success or failure of the operations.
4444
*/
4545
enum class LowPowerReturnCode
@@ -62,8 +62,7 @@ enum class LowPowerReturnCode
6262
/**
6363
* @enum CPUMode
6464
* @brief Provides the different modes of the CPU.
65-
* Those can be used to determine in which standby mode the CPU
66-
* was before waking up.
65+
* Those can be used to determine in which mode the CPU was before waking up.
6766
*/
6867
enum class CPUMode
6968
{
@@ -80,9 +79,9 @@ enum class CPUMode
8079
*/
8180

8281
/**
83-
* @brief The LowPowerStandbyType class represents different types of standby modes for low power operation.
82+
* @brief The LowPowerStandbyType class represents different methods of wakeup.
8483
*
85-
* This class provides options for the following standby modes: waiting until pin activity
84+
* This class provides options for the following methods of wakeup: waiting until pin activity
8685
* or until a specified time has elapsed, or both.
8786
* Those are represented by LowPowerStandbyType::untilPinActivity and LowPowerStandbyType::untilTimeElapsed.
8887
* To combine the two options use the | operator.
@@ -91,7 +90,7 @@ class LowPowerStandbyType {
9190
public:
9291
/// @cond DEV
9392
/**
94-
* @brief A class representing the condition that waits until a wakeup pin changes its state.
93+
* @brief A class representing a wakeup option that waits until a wakeup pin changes its state.
9594
*
9695
* This class provides functionality to wait until a specified pin changes its state,
9796
* from HIGH to LOW.
@@ -127,7 +126,7 @@ class LowPowerStandbyType {
127126
/// @cond DEV
128127
/**
129128
* @brief Represents a wakeup option which waits until either
130-
* a pin activity occurs or a specified time has elapsed.
129+
* a pin activity occurs or a specified time has elapsed, whichever happens first
131130
*/
132131
class UntilEitherClass {
133132
};
@@ -143,7 +142,7 @@ class LowPowerStandbyType {
143142
};
144143

145144
/**
146-
* @brief The RTCWakeupDelay class represents a delay before waking up from a low power mode.
145+
* @brief The RTCWakeupDelay class represents a delay before waking up from Standby Mode.
147146
*/
148147
class RTCWakeupDelay {
149148
public:
@@ -188,9 +187,9 @@ class RTCWakeupDelay {
188187
*
189188
* The LowPowerPortentaH7 class allows the microcontroller on the Portenta H7 board
190189
* to enter low power modes such as Standby Mode and Deep Sleep Mode. It provides
191-
* functions to check the current mode, prepare the option bytes for entering Standby Mode,
190+
* functions to check the mode before startup, prepare the option bytes for entering Standby Mode,
192191
* and control the M4 and M7 cores independently. It also provides functions to measure
193-
* the time since boot, time spent in idle, sleep, and deep sleep modes.
192+
* the time since boot, time spent in Idle, Sleep, and Deep Sleep modes.
194193
*
195194
* This class is a singleton and shall always be accessed through the global LowPower object.
196195
*
@@ -285,17 +284,6 @@ class LowPowerPortentaH7 {
285284
*/
286285
LowPowerReturnCode checkOptionBytes() const;
287286

288-
/**
289-
* Checks if the microcontroller was in the given CPU mode before starting.
290-
* Note: It's possible that the microcontroller was in more than one of these modes
291-
* before starting. Call this function multiple times to check for each mode.
292-
* Important: When you're done checking, call resetStandbyModeFlags() to reset the flags
293-
* so they are reported correctly the next time the microcontroller starts.
294-
* @param mode The CPU mode to check.
295-
* @return True if the microcontroller was in the given mode, false otherwise.
296-
*/
297-
bool wasInCPUMode(CPUMode mode) const;
298-
299287
/**
300288
* @brief Reset the flags that are used to determine the microcontroller's
301289
* previous CPU mode. This is necessary to get correct results from
@@ -320,7 +308,7 @@ class LowPowerPortentaH7 {
320308
LowPowerReturnCode prepareOptionBytes() const;
321309

322310
/**
323-
* @brief Make the M4 core enter Standby Mode.
311+
* @brief Make the M4 core and D2 domain enter standby mode.
324312
* @return A constant from the LowPowerReturnCode enum.
325313
*/
326314
LowPowerReturnCode standbyM4() const;
@@ -337,7 +325,7 @@ class LowPowerPortentaH7 {
337325
// have to be since Doxygen is configured with ENABLE_PREPROCESSING NO
338326
#ifdef DOXYGEN_ONLY
339327
/**
340-
* @brief Make the M7 core enter Standby Mode.
328+
* @brief Make the M7 core and D1 domain enter standby mode, and make it possible for the D3 domain to do so too.
341329
* @param standbyType One or a combination of LowPowerStandbyType::untilPinActivity
342330
* and LowPowerStandbyType::untilTimeElapsed. The combination is done with the | operator.
343331
* @param args An optional delay before waking up again, if LowPowerStandbyType::untilTimeElapsed is used.
@@ -355,7 +343,7 @@ class LowPowerPortentaH7 {
355343
uint64_t timeSinceBoot() const;
356344

357345
/**
358-
* @brief Time spent in idle.
346+
* @brief Time spent in Idle Mode.
359347
* @return Number of microseconds.
360348
*/
361349
uint64_t timeSpentIdle() const;
@@ -371,6 +359,17 @@ class LowPowerPortentaH7 {
371359
* @return Number of microseconds.
372360
*/
373361
uint64_t timeSpentInDeepSleep() const;
362+
363+
/**
364+
* Checks if the microcontroller was in the given CPU mode before starting.
365+
* Note: It's possible that the microcontroller was in more than one of these modes
366+
* before starting. Call this function multiple times to check for each mode.
367+
* Important: When you're done checking, call resetStandbyModeFlags() to reset the flags
368+
* so they are reported correctly the next time the microcontroller starts.
369+
* @param mode The CPU mode to check.
370+
* @return True if the microcontroller was in the given mode, false otherwise.
371+
*/
372+
bool wasInCPUMode(CPUMode mode) const;
374373
};
375374

376375
/*
@@ -469,11 +468,15 @@ LowPowerPortentaH7::standbyM7(const T standbyType,
469468
// Standby Mode will fail. Anyone who defines that constant takes
470469
// responsibility for not overheating the resistors. It is NOT part of the
471470
// API intended for ordinary users.
472-
#ifndef NO_ETHERNET_TURN_OFF
473-
if (false == turnOffEthernet())
474-
{
475-
return LowPowerReturnCode::turningOffEthernetFailed;
476-
}
471+
#ifdef NO_ETHERNET_TURN_OFF
472+
#warning "If you are defining NO_ETHERNET_TURN_OFF in your own sketch \
473+
or library, then please make sure to turn off the power \
474+
to the Ethernet chip before going into Standby Mode."
475+
#else
476+
if (false == turnOffEthernet())
477+
{
478+
return LowPowerReturnCode::turningOffEthernetFailed;
479+
}
477480
#endif
478481
479482
// Prevent Mbed from changing things

0 commit comments

Comments
 (0)