Re: HAL architecture

Noëlle Clement

{sent again because I forgot to also send it to the mailing list!} 

Thank you a lot both! 
Over the past few weeks I've unexpectedly had to work on some other part of the board port, so only now I'm starting on the low power management.

The good news is that by now I also have a bit better understanding of Zephyr and the power management, partially thanks to your advice! However, now that I've actually started on this part, I have many questions. I thought it would be more useful to ask through the mailing list, in case Francois is busy. The power management is crucial for our application, which is part of a prototype I'm developing for my Bachelor thesis, and I'm on a tight schedule haha. 

I have looked through the PR Erwan mentioned, regarding the low power support for the STM32L4, but there's still some parts that are raising questions. 

Some extra technical details:
- We use the STM32L151CC on our custom board. This board has already been ported by me (or at least the configuration part required for flashing and running the application).
- We need to use the stop mode with RTC
- During 'normal' operation the HSI is used, during the stop mode the LSE is used 
- If I understood correctly, currently the wake up is caused through a timed interrupt from the RTC 

Some of my questions are:
1. In this issue ( only a few series part of the STM32 family are mentioned. Does this mean that low power management is already supported in Zephyr as-is for the other series (like the STM32L1xxx series), or just that they are not a priority or the like?
2. Why was it necessary to create a power.c file specifically for the STM32L4XXX? Is that always required for the STM32 SOCs, or was it only because the sleep modes didn't 'align' with the stop modes?
3. In the (modules/hal/stm32/stm32cube/stm32l1xx/drivers/include/) 'stm32l1xx_ll_pwr.h' file I can't find variables specifying specific stop modes, like in the 'stm32l4xx_ll_pwr.h' file. Why is this the case? How will I specify the specific stop mode if it's not in the HAL? 
4. Are there still things that need to be included / written in the application source, for the power management to work properly, with the way it was set up for the STM32L4xxx (creating the separate power.c file)?

There's a bit of overlap in these questions, as you may have noticed. I guess the main question is 'help, I'm not sure how to set up the power management', since I'm simultaneously learning about power management configuration and how this is done in Zephyr. But I tried to give more direction where I'm most confused haha.
Have a great day!

From: Erwan Gouriou <erwan.gouriou@...>
Sent: Thursday, June 4, 2020 5:06 PM
To: Cufi, Carles <Carles.Cufi@...>
Cc: Noëlle Clement <n.clement@...>; users@... <users@...>; Glaropoulos, Ioannis <Ioannis.Glaropoulos@...>; Francois RAMU <francois.ramu@...>
Subject: Re: HAL architecture
Additionally to Carles's answer, let me point you to an on going PR that aims at implementing lp modes on stm32:

It only supports L4/WB series for now, but you can contact François in CC if you have some questions to adapt this to your use case.


On Thu, 4 Jun 2020 at 16:58, Cufi, Carles <Carles.Cufi@...> wrote:

Hi Noëlle,


Thanks for the kind words.

You can use CMSIS, which is built-in with Zephyr, for WFI.


Simply use:




in your C code.


The definition is here:


That said, are you sure you  need to invoke the WFI instruction manually? this is automatically done by Zephyr when the core can be powered down, for example:






From: users@... <users@...> On Behalf Of Noëlle Clement via
Sent: 04 June 2020 15:09
To: users@...
Subject: [Zephyr-users] HAL architecture


Hi everyone!


First of all: thanks specifically to Carles Cufi for taking the time a few months ago to give very detailed answers to my questions on whether Zephyr would be a right choice for our device. Partially because of this we're going with Zephyr for now - at least for the upcoming phase where I'm going to develop a prototype!


The first step for this prototype is making sure that the OS actually supports the low power mode we need to still meet our battery life requirements. Some context:

- We use the STM32L151CC MCU

- We need to be able to request the WFI (wait_for_interrupt) instruction (we use that one right now)

- In our current (bare-metal) code we use CMSIS +  a separate library (STM32 Standard Peripheral Library), of which the latter actually includes functions for requesting low power modes (including WFI)


I'm trying to figure out whether this specific instruction is already part of the HAL of Zephyr for the STM32Lxx MCU's. However, I'm kind of getting lost in the code, since the abstraction seems to be dispersed over multiple locations. I've looked into the documentation of course, but wasn't able to find an answer for my specific question. 


It would help me tremendously if someone could point me in the right direction or give a summary of the architecture, so I can check whether it's already supported or can start with implementing it myself.


Quick note that I'm relatively new to this, so if you need more information to understand my question or help me, I'm happy to provide it!


All the best,



Join to automatically receive all group messages.