Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/Continuous-Integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
# First of all, clone the repo using the checkout action.
- name: Checkout
uses: actions/checkout@main
with:
submodules: true

- name: Compilation
id: Compile
Expand Down
31 changes: 31 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# v3.21 implemented semantic changes regarding $<TARGET_OBJECTS:...>
# See https://cmake.org/cmake/help/v3.21/command/target_link_libraries.html#linking-object-libraries-via-target-objects
cmake_minimum_required(VERSION 3.21)

add_library(STM32LowPower INTERFACE)
add_library(STM32LowPower_usage INTERFACE)

target_include_directories(STM32LowPower_usage INTERFACE
src
)


target_link_libraries(STM32LowPower_usage INTERFACE
base_config
)

target_link_libraries(STM32LowPower INTERFACE STM32LowPower_usage)



add_library(STM32LowPower_bin OBJECT EXCLUDE_FROM_ALL
src/low_power.c
src/STM32LowPower.cpp
)
target_link_libraries(STM32LowPower_bin PUBLIC STM32LowPower_usage)

target_link_libraries(STM32LowPower INTERFACE
STM32LowPower_bin
$<TARGET_OBJECTS:STM32LowPower_bin>
)

12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
Arduino library to support STM32 Low Power.

## Requirement
* [Arduino_Core_STM32](https://github.com/stm32duino/Arduino_Core_STM32) version >= 1.3.0
* [STM32RTC](https://github.com/stm32duino/STM32RTC)
* Library version 1.x.x:
* [Arduino_Core_STM32](https://github.com/stm32duino/Arduino_Core_STM32) version >= 1.3.0
* [STM32RTC](https://github.com/stm32duino/STM32RTC) version 1.x.x
* Library version 2.x.x:
* [Arduino_Core_STM32](https://github.com/stm32duino/Arduino_Core_STM32) version 3.x.x
* [STM32RTC](https://github.com/stm32duino/STM32RTC) version 2.x.x

## API

Expand All @@ -30,7 +34,7 @@ Arduino library to support STM32 Low Power.
**param** mode: interrupt mode (HIGH, LOW, RISING, FALLING or CHANGE)
**param** LowPowerMode: Low power mode which will be used (IDLE_MODE, SLEEP_MODE, DEEP_SLEEP_MODE or SHUTDOWN_MODE). In case of SHUTDOWN_MODE only, Wakeup pin capability is activated.

* **`void enableWakeupFrom(HardwareSerial *serial, voidFuncPtrVoid callback)`**: enable a UART peripheral in low power mode. See board documentation for low power mode compatibility.
* **`void enableWakeupFrom(Uart *serial, voidFuncPtrVoid callback)`**: enable a UART peripheral in low power mode. See board documentation for low power mode compatibility.
**param** serial: pointer to a UART
**param** callback: pointer to a callback to call when the board is waked up.

Expand All @@ -51,7 +55,7 @@ enable an I2C peripheral in low power mode. See board documentation for low powe
`attachInterruptWakeup()` or `enableWakeupFrom()` functions should be called before `idle()`, `sleep()`, `deepSleep()` or `shutdown()` functions.

> [!Important]
> * HardwareSerial used as Wakeup source will configure it to use HSI clock source even if another peripheral clock is configured.
> * Uart used as Wakeup source will configure it to use HSI clock source even if another peripheral clock is configured.
>
> * RTC used as Wakeup source requires to have LSE or LSI as clock source. If one of them is used nothing is changed else it will configure it to use LSI clock source. One exception exists when `SHUTDOWN_MODE` is requested and `PWR_CR1_LPMS` is defined, in that case LSE is required. So, if the board does not have LSE, it will fail.
>
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "git",
"url": "https://github.com/stm32duino/STM32LowPower"
},
"version": "1.5.0",
"version": "2.0.0",
"frameworks": "arduino",
"platforms": "ststm32",
"build": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=STM32duino Low Power
version=1.5.0
version=2.0.0
author=STMicroelectonics
maintainer=stm32duino
sentence=Power save primitives features for STM32 boards
Expand Down
8 changes: 4 additions & 4 deletions src/STM32LowPower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void STM32LowPower::shutdown(uint32_t ms)
* In case of SHUTDOWN_MODE only, Wakeup pin capability is activated
* @retval None
*/
void STM32LowPower::attachInterruptWakeup(uint32_t pin, voidFuncPtrVoid callback, uint32_t mode, LP_Mode LowPowerMode)
void STM32LowPower::attachInterruptWakeup(pin_size_t pin, voidFuncPtr callback, PinStatus mode, LP_Mode LowPowerMode)
{
attachInterrupt(pin, callback, mode);

Expand All @@ -161,12 +161,12 @@ void STM32LowPower::attachInterruptWakeup(uint32_t pin, voidFuncPtrVoid callback

/**
* @brief Enable a serial interface as a wakeup source.
* @param serial: pointer to a HardwareSerial
* @param serial: pointer to an Uart
* @param callback: pointer to callback function called when leave the low power
* mode.
* @retval None
*/
void STM32LowPower::enableWakeupFrom(HardwareSerial *serial, voidFuncPtrVoid callback)
void STM32LowPower::enableWakeupFrom(Uart *serial, voidFuncPtr callback)
{
if (serial != NULL) {
_serial = &(serial->_serial);
Expand All @@ -184,7 +184,7 @@ void STM32LowPower::enableWakeupFrom(HardwareSerial *serial, voidFuncPtrVoid cal
* @param data: optional pointer to callback data parameters (default NULL).
* @retval None
*/
void STM32LowPower::enableWakeupFrom(STM32RTC *rtc, voidFuncPtr callback, void *data)
void STM32LowPower::enableWakeupFrom(STM32RTC *rtc, voidFuncPtrParam callback, void *data)
{
if (rtc == NULL) {
rtc = &(STM32RTC::getInstance());
Expand Down
11 changes: 6 additions & 5 deletions src/STM32LowPower.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
#define _STM32_LOW_POWER_H_

#include <Arduino.h>

#if defined(STM32_CORE_VERSION) && (STM32_CORE_VERSION <= 0x020C0000)
#error "This library is not compatible with core version used. Please update the core."
#endif
#include "low_power.h"

// Check if PWR HAL enable in variants/board_name/stm32yzxx_hal_conf.h
Expand All @@ -55,7 +57,6 @@ enum LP_Mode : uint8_t {
SHUTDOWN_MODE
};

typedef void (*voidFuncPtrVoid)(void) ;

class STM32LowPower {
public:
Expand Down Expand Up @@ -89,10 +90,10 @@ class STM32LowPower {
shutdown((uint32_t)ms);
}
#endif
void attachInterruptWakeup(uint32_t pin, voidFuncPtrVoid callback, uint32_t mode, LP_Mode LowPowerMode = SHUTDOWN_MODE);
void attachInterruptWakeup(pin_size_t pin, voidFuncPtr callback, PinStatus mode, LP_Mode LowPowerMode = SHUTDOWN_MODE);

void enableWakeupFrom(HardwareSerial *serial, voidFuncPtrVoid callback);
void enableWakeupFrom(STM32RTC *rtc, voidFuncPtr callback, void *data = NULL);
void enableWakeupFrom(Uart *serial, voidFuncPtr callback);
void enableWakeupFrom(STM32RTC *rtc, voidFuncPtrParam callback, void *data = NULL);

private:
bool _configured; // Low Power mode initialization status
Expand Down
11 changes: 6 additions & 5 deletions src/low_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
******************************************************************************
*/

#include "Arduino.h"
#include "low_power.h"
#include "clock.h"
#include "pins_arduino.h"
#include "stm32yyxx_ll_cortex.h"
#include "stm32yyxx_ll_pwr.h"

Expand Down Expand Up @@ -202,7 +203,7 @@ void LowPower_init()
* @param mode: pin mode (edge or state). The configuration have to be compatible.
* @retval None
*/
void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
void LowPower_EnableWakeUpPin(pin_size_t pin, PinStatus mode)
{
PinName p = digitalPinToPinName(pin);
#if defined(PWR_WAKEUP_SELECT_0) || defined(PWR_WAKEUP1_SOURCE_SELECTION_0)
Expand Down Expand Up @@ -975,10 +976,10 @@ void LowPower_shutdown(bool isRTC)
* with which low power mode the UART is compatible.
* Warning This function will change UART clock source to HSI
* @param serial: pointer to serial
* @param FuncPtr: pointer to callback
* @param callback: pointer to callback
* @retval None
*/
void LowPower_EnableWakeUpUart(serial_t *serial, void (*FuncPtr)(void))
void LowPower_EnableWakeUpUart(serial_t *serial, voidFuncPtr callback)
{
#if defined(UART_WKUP_SUPPORT)
#ifdef IS_UART_WAKEUP_SELECTION
Expand Down Expand Up @@ -1009,7 +1010,7 @@ void LowPower_EnableWakeUpUart(serial_t *serial, void (*FuncPtr)(void))
UNUSED(serial);
#endif
/* Save callback */
WakeUpUartCb = FuncPtr;
WakeUpUartCb = callback;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/low_power.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define __LOW_POWER_H

/* Includes ------------------------------------------------------------------*/
#include "Common.h"
#include "stm32_def.h"
#include "uart.h"

Expand All @@ -53,8 +54,8 @@ extern "C" {
/* Exported functions ------------------------------------------------------- */

void LowPower_init();
void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode);
void LowPower_EnableWakeUpUart(serial_t *serial, void (*FuncPtr)(void));
void LowPower_EnableWakeUpPin(pin_size_t pin, PinStatus mode);
void LowPower_EnableWakeUpUart(serial_t *serial, voidFuncPtr callback);
void LowPower_sleep(uint32_t regulator);
void LowPower_stop(serial_t *obj);
void LowPower_standby();
Expand Down
Loading