diff --git a/.github/workflows/Continuous-Integration.yml b/.github/workflows/Continuous-Integration.yml index ff16262..a99f55a 100644 --- a/.github/workflows/Continuous-Integration.yml +++ b/.github/workflows/Continuous-Integration.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..467c733 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,31 @@ +# v3.21 implemented semantic changes regarding $ +# 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 + $ +) + diff --git a/README.md b/README.md index 73149f0..5b5debb 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. @@ -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. > diff --git a/library.json b/library.json index 11261df..672a9e7 100644 --- a/library.json +++ b/library.json @@ -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": { diff --git a/library.properties b/library.properties index 688e1c3..e2f8a8c 100644 --- a/library.properties +++ b/library.properties @@ -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 diff --git a/src/STM32LowPower.cpp b/src/STM32LowPower.cpp index d3abfe8..97bab8e 100644 --- a/src/STM32LowPower.cpp +++ b/src/STM32LowPower.cpp @@ -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); @@ -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); @@ -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()); diff --git a/src/STM32LowPower.h b/src/STM32LowPower.h index 9737522..16d4eff 100644 --- a/src/STM32LowPower.h +++ b/src/STM32LowPower.h @@ -38,7 +38,9 @@ #define _STM32_LOW_POWER_H_ #include - +#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 @@ -55,7 +57,6 @@ enum LP_Mode : uint8_t { SHUTDOWN_MODE }; -typedef void (*voidFuncPtrVoid)(void) ; class STM32LowPower { public: @@ -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 diff --git a/src/low_power.c b/src/low_power.c index 0d32340..73c7ca4 100644 --- a/src/low_power.c +++ b/src/low_power.c @@ -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" @@ -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) @@ -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 @@ -1009,7 +1010,7 @@ void LowPower_EnableWakeUpUart(serial_t *serial, void (*FuncPtr)(void)) UNUSED(serial); #endif /* Save callback */ - WakeUpUartCb = FuncPtr; + WakeUpUartCb = callback; } /** diff --git a/src/low_power.h b/src/low_power.h index 7aede40..88843de 100644 --- a/src/low_power.h +++ b/src/low_power.h @@ -38,6 +38,7 @@ #define __LOW_POWER_H /* Includes ------------------------------------------------------------------*/ +#include "Common.h" #include "stm32_def.h" #include "uart.h" @@ -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();