Power Driver for stm32l1

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Power Driver for stm32l1

Postby Giovanni » Mon Sep 18, 2017 2:18 pm

This is clear, devil is in the details: Not all power states are the same, some peripheral can work in some power states but not others depending on the system state and various settings.

For example RCC settings have an impact, peripherals can be clocked or not clocked during low power states, this has to be configured somewhere. The various STM32s also have settings about power regulators and clock settings are impacted by those too (max clock frequency, flash wait states, etc).

About OSAL, putting calls to HAL in OSAL is not possible, OSAL depends on the RTOS and is used by HAL but it does cannot call HAL.

My general idea is to remove clock settings from hal_lld and create a specific "clock driver" allowing to change clock configurations at runtime for power management, probably power settings would be part of this but I don't have yet a detailed plan just an idea.

Giovanni

vrollei
Posts: 163
Joined: Sun Nov 13, 2016 8:44 am
Been thanked: 26 times

Re: Power Driver for stm32l1

Postby vrollei » Mon Sep 18, 2017 6:00 pm

Let's try to dive in details )

* hal_pwr:
- responsible for enter/exit low power modes (low power sleep, stop and standby, stm32 view) using idle_thread hooks
- makes decision to enter target power mode based on current hal drivers activities and/or application activities using incoming notifications (start/stop activity) and chVTGetTimersState
- uses PWR_ON_ENTER_X_MODE/PWR_ON_EXIT_X_MODE hooks to do some application specifics task on enter/exit low power mode, e.g. to change port/pin mode
- hal_pwr_lld(1): controls all PWR_xx registers directly, e.g voltage regulator mode according configuration
- hal_pwr_lld(2): controls clock using hal_rcc (now directly) and ST(changes prescaler in low power sleep modes to keep ST timer active, ST based on RTC can run in all modes without ST reconfiguration)
- hal_pwr_lld(3): has configuration: clock source in low power sleep mode, voltage regulator mode in low power sleep etc
- rcc notes: low power sleep mode - cpu clock off, no effect on other clocks or analog clock sources, stop - all clock off except LSI and LSE
- peripherals notes: some peripherals (UART, i2c) can wakeup MCU from STOP mode, so hal drivers have to support it somehow (stop_with_wakeup state e.g.?)
- wake up from STOP without ST based on RTC: should be implemented using RTC or other things, it is not part of hal_pwr

* hal_rcc: should implement hal_pwr_lld(2), should support configuration of peripherals clock in low power sleep modes (?)

* st_lld: is it part of hal and can it use hal_rcc or hal_pwr to restore clock on exit from low power modes?
Vitaly

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Power Driver for stm32l1

Postby Giovanni » Sun Apr 25, 2021 7:30 pm

Giovanni wrote: using incoming notifications (start/stop activity)


There is no such a thing, drivers do not send notifications. Implementing such a thing would require a lot of redesign and would make this driver no more a driver but a full HAL centralized functionality, something I always avoided keeping drivers well separated from each other.

vrollei wrote:chVTGetTimersState


You should not assume there is RT under HAL, "ch" API cannot be used in HAL drivers. There could be no RTOS at all or something entirely different.

Everything looks like "high impact" on the rest of HAL, it is not possible to change things radically without thinking to the impact on all existing ports. You should think to something much simpler. Some suggestions:

- Do not assume you will have to hook on other things, just export functions and let the application do the hooking in the most appropriate way.
- Let the application decide if to go to sleep or not, you don't have access to all the information from inside the driver and forget getting updates by all other drivers.
- Use a passive approach, a driver is something that is called by the application, do not assume it is called by other drivers implicitly.
- This driver would be very device-specific so it cannot be abstracted. Target a specific device for it.
- Do not assume the existence of other drivers, nor the number/activation of other peripherals or their state.

I would make it very low level like DMA drivers or RCC support files and offer explicit functions to enter low power modes and restart, let the application call them where and when appropriate.

Giovanni

vrollei
Posts: 163
Joined: Sun Nov 13, 2016 8:44 am
Been thanked: 26 times

Re: Power Driver for stm32l1

Postby vrollei » Sun Apr 25, 2021 8:11 pm

Hi,

I will create experimental driver for STR32WL to present idea,
with this example it will be easier to discuss approach. There is no need to change anything in HAL right now to implement PWR driver.
Vitaly

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Power Driver for stm32l1

Postby Giovanni » Sun Apr 25, 2021 8:27 pm

Also consider the multiple low power modes, it would be nice to offer support to enter any of those, doing that at register level is not exactly simple.

Giovanni


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 30 guests