You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2020/03/03 13:38:55 UTC

[GitHub] [mynewt-core] apache-mynewt-bot commented on issue #2224: add functionality to allow low power operation for STM32L1xx

apache-mynewt-bot commented on issue #2224: add functionality to allow low power operation for STM32L1xx
URL: https://github.com/apache/mynewt-core/pull/2224#issuecomment-593954354
 
 
   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### hw/mcu/stm/stm32l1xx/src/hal_power_mgnt.c
   <details>
   
   ```diff
   @@ -35,7 +35,9 @@
    void stm32_tickless_start(uint32_t timeMS);
    
    /* Put MCU  in lowest power stop state, exit only via POR or reset pin */
   -void hal_mcu_halt() {
   +void
   +hal_mcu_halt()
   +{
    
        /* all interupts and exceptions off */
        /* PVD off */
   @@ -45,9 +47,9 @@
        /*start tickless mode forever */
        stm32_tickless_start(0);
    
   -    while(1) {
   -
   -        /*Disables the Power Voltage Detector(PVD) */                
   +    while (1) {
   +
   +        /*Disables the Power Voltage Detector(PVD) */
            HAL_PWR_DisablePVD( );
            /* Enable Ultra low power mode */
            HAL_PWREx_EnableUltraLowPower( );
   @@ -59,11 +61,13 @@
        }
    }
    
   -void stm32_tick_init(uint32_t os_ticks_per_sec, int prio) {
   +void
   +stm32_tick_init(uint32_t os_ticks_per_sec, int prio)
   +{
        /* Even for tickless we use SYSTICK for normal tick.*/
        /*nb of ticks per seconds is hardcoded in HAL_InitTick(..) to have 1ms/tick */
        assert(os_ticks_per_sec == OS_TICKS_PER_SEC);
   -    
   +
        volatile uint32_t reload_val;
    
        /*Reload Value = SysTick Counter Clock (Hz) x  Desired Time base (s) */
   @@ -73,8 +77,8 @@
        SysTick->VAL = 0;
    
        /* CLKSOURCE : 1 -> HCLK, 0-> AHB Clock (which is HCLK/8). Use HCLK, as this is the value of SystemCoreClock as used above */
   -    SysTick->CTRL = ( SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk );  
   -        
   +    SysTick->CTRL = (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk);
   +
        /* Set the system tick priority */
        NVIC_SetPriority(SysTick_IRQn, prio);
    
   @@ -99,10 +103,12 @@
    
    
    }
   -void stm32_tickless_start(uint32_t timeMS) {
   +void
   +stm32_tickless_start(uint32_t timeMS)
   +{
    
        /* Start RTC alarm for in this amount of time */
   -    if(timeMS>0){
   +    if (timeMS > 0) {
            hal_rtc_enable_wakeup(timeMS);
        }
        /* Stop SYSTICK */
   @@ -111,12 +117,14 @@
        CLEAR_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk);
    }
    
   -void stm32_tickless_stop(uint32_t timeMS) {
   -    
   +void
   +stm32_tickless_stop(uint32_t timeMS)
   +{
   +
        /* add asleep duration to tick counter : how long we should have slept for minus any remaining time */
   -    volatile uint32_t asleep_ms =  hal_rtc_get_elapsed_wakeup_timer();
   +    volatile uint32_t asleep_ms = hal_rtc_get_elapsed_wakeup_timer();
        volatile int asleep_ticks = os_time_ms_to_ticks32(asleep_ms);
   -    assert(asleep_ticks>=0);
   +    assert(asleep_ticks >= 0);
        os_time_advance(asleep_ticks);
    
        /* disable RTC */
   @@ -126,21 +134,22 @@
        NVIC_EnableIRQ(SysTick_IRQn);
        /* reenable SysTick */
        SET_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk);
   -    
   -}
   -
   -void stm32_power_enter(int power_mode, uint32_t durationMS)
   +
   +}
   +
   +void
   +stm32_power_enter(int power_mode, uint32_t durationMS)
    {
        /* if sleep time was less than MIN_TICKS, it is 0. Just do usual WFI and systick will wake us in 1ms */
   -    if (durationMS==0) {
   +    if (durationMS == 0) {
            HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
            return;
        }
    
   -    if(durationMS >= 32000) {
   +    if (durationMS >= 32000) {
            /* 32 sec is the largest value of wakeuptimer   */
   -        /* TODO :  fix this                             */ 
   -        durationMS = 32000 - 1; 
   +        /* TODO :  fix this                             */
   +        durationMS = 32000 - 1;
        }
    
        /* begin tickless */
   @@ -148,48 +157,48 @@
        stm32_tickless_start(durationMS);
    #endif
    
   -    switch(power_mode) {
   -        case HAL_BSP_POWER_OFF:
   -        case HAL_BSP_POWER_DEEP_SLEEP: {
   -            /*Disables the Power Voltage Detector(PVD) */                
   -            HAL_PWR_DisablePVD( );
   -            /* Enable Ultra low power mode */
   -            HAL_PWREx_EnableUltraLowPower( );
   -            /* Enable the fast wake up from Ultra low power mode */
   -            HAL_PWREx_DisableFastWakeUp( );
   -            /* Enters StandBy mode */
   -            HAL_PWR_EnterSTANDBYMode();
   -
   -            SystemClock_RestartPLL();
   -            break;
   -        }
   -        case HAL_BSP_POWER_SLEEP: {
   -
   -            /*Disables the Power Voltage Detector(PVD) */                
   -            HAL_PWR_DisablePVD( );
   -            /* Enable Ultra low power mode */
   -            HAL_PWREx_EnableUltraLowPower( );
   -            /* Enable the fast wake up from Ultra low power mode */
   -            HAL_PWREx_DisableFastWakeUp( );
   -            /* Enters Stop mode not in PWR_MAINREGULATOR_ON*/
   -            HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
   -
   -            SystemClock_RestartPLL();
   -            break;
   -        }
   -        case HAL_BSP_POWER_WFI: {
   -            HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   -
   -            SystemClock_RestartPLL();            
   -            break;
   -        }
   -        case HAL_BSP_POWER_ON:
   -        default: {
   -            
   -            break;
   -        }
   -    }
   -    
   +    switch (power_mode) {
   +    case HAL_BSP_POWER_OFF:
   +    case HAL_BSP_POWER_DEEP_SLEEP: {
   +        /*Disables the Power Voltage Detector(PVD) */
   +        HAL_PWR_DisablePVD( );
   +        /* Enable Ultra low power mode */
   +        HAL_PWREx_EnableUltraLowPower( );
   +        /* Enable the fast wake up from Ultra low power mode */
   +        HAL_PWREx_DisableFastWakeUp( );
   +        /* Enters StandBy mode */
   +        HAL_PWR_EnterSTANDBYMode();
   +
   +        SystemClock_RestartPLL();
   +        break;
   +    }
   +    case HAL_BSP_POWER_SLEEP: {
   +
   +        /*Disables the Power Voltage Detector(PVD) */
   +        HAL_PWR_DisablePVD( );
   +        /* Enable Ultra low power mode */
   +        HAL_PWREx_EnableUltraLowPower( );
   +        /* Enable the fast wake up from Ultra low power mode */
   +        HAL_PWREx_DisableFastWakeUp( );
   +        /* Enters Stop mode not in PWR_MAINREGULATOR_ON*/
   +        HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
   +
   +        SystemClock_RestartPLL();
   +        break;
   +    }
   +    case HAL_BSP_POWER_WFI: {
   +        HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   +
   +        SystemClock_RestartPLL();
   +        break;
   +    }
   +    case HAL_BSP_POWER_ON:
   +    default: {
   +
   +        break;
   +    }
   +    }
   +
    #if MYNEWT_VAL(OS_TICKLESS_RTC)
        /* exit tickless low power mode */
        stm32_tickless_stop(durationMS);
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32l1xx/src/rtc_utils.c
   <details>
   
   ```diff
   @@ -1,15 +1,15 @@
    /**
     * Copyright 2019 Wyres
   - * Licensed under the Apache License, Version 2.0 (the "License"); 
   - * you may not use this file except in compliance with the License. 
   + * Licensed under the Apache License, Version 2.0 (the "License");
   + * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *    http://www.apache.org/licenses/LICENSE-2.0
   - * Unless required by applicable law or agreed to in writing, 
   - * software distributed under the License is distributed on 
   - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
   - * either express or implied. See the License for the specific 
   + * Unless required by applicable law or agreed to in writing,
   + * software distributed under the License is distributed on
   + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
   + * either express or implied. See the License for the specific
     * language governing permissions and limitations under the License.
   -*/
   + */
    
    /**
     * Utilities for rtc management
   @@ -47,24 +47,24 @@
    /*!
     * \brief Days, Hours, Minutes and seconds
     */
   -#define DAYS_IN_LEAP_YEAR                           ( ( uint32_t )  366U )
   -#define DAYS_IN_YEAR                                ( ( uint32_t )  365U )
   -#define SECONDS_IN_1DAY                             ( ( uint32_t )86400U )
   -#define SECONDS_IN_1HOUR                            ( ( uint32_t ) 3600U )
   -#define SECONDS_IN_1MINUTE                          ( ( uint32_t )   60U )
   -#define MINUTES_IN_1HOUR                            ( ( uint32_t )   60U )
   -#define HOURS_IN_1DAY                               ( ( uint32_t )   24U )
   +#define DAYS_IN_LEAP_YEAR                           (( uint32_t )  366U)
   +#define DAYS_IN_YEAR                                (( uint32_t )  365U)
   +#define SECONDS_IN_1DAY                             (( uint32_t )86400U)
   +#define SECONDS_IN_1HOUR                            (( uint32_t ) 3600U)
   +#define SECONDS_IN_1MINUTE                          (( uint32_t )   60U)
   +#define MINUTES_IN_1HOUR                            (( uint32_t )   60U)
   +#define HOURS_IN_1DAY                               (( uint32_t )   24U)
    
    /*!
     * \brief Correction factors
     */
   -#define  DAYS_IN_MONTH_CORRECTION_NORM              ( ( uint32_t )0x99AAA0 )
   -#define  DAYS_IN_MONTH_CORRECTION_LEAP              ( ( uint32_t )0x445550 )
   +#define  DAYS_IN_MONTH_CORRECTION_NORM              (( uint32_t )0x99AAA0)
   +#define  DAYS_IN_MONTH_CORRECTION_LEAP              (( uint32_t )0x445550)
    
    /*!
     * \brief Calculates ceiling( X / N )
     */
   -#define DIVC( X, N )                                ( ( ( X ) + ( N ) -1 ) / ( N ) )
   +#define DIVC(X, N)                                (((X) + ( N ) -1) / (N))
    
    
    #define RTC_CLOCK_PRESCALER                         16.0f
   @@ -79,24 +79,21 @@
    
    
    /*!
   - * RTC timer context 
   - */
   -typedef struct
   -{
   -    uint32_t        Time;         // Reference time
   -    RTC_TimeTypeDef CalendarTime; // Reference time in calendar format
   -    RTC_DateTypeDef CalendarDate; // Reference date in calendar format
   -}RtcTimerContext_t;
   + * RTC timer context
   + */
   +typedef struct {
   +    uint32_t Time;                /* Reference time */
   +    RTC_TimeTypeDef CalendarTime; /* Reference time in calendar format */
   +    RTC_DateTypeDef CalendarDate; /* Reference date in calendar format */
   +} RtcTimerContext_t;
    
    
    /*!
     * \brief RTC Handle
     */
   -static RTC_HandleTypeDef RtcHandle = 
   -{
   +static RTC_HandleTypeDef RtcHandle = {
        .Instance = NULL,
   -    .Init = 
   -    { 
   +    .Init = {
            .HourFormat = 0,
            .AsynchPrediv = 0,
            .SynchPrediv = 0,
   @@ -108,23 +105,23 @@
        .State = HAL_RTC_STATE_RESET
    };
    
   -static struct
   -{
   +static struct {
        uint32_t clk_srce_sel;
        uint16_t autoreload_timer;
        uint16_t follower_counter_start;
    
   -}WakeUpTimer_Settings;
   -
   -
   -
   -/**
   -  * @brief  This function handles  WAKE UP TIMER  interrupt request.
   -  * @retval None
   -  */
   -void RTC_WKUP_IRQHandler(void)
   -{
   -  HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
   +} WakeUpTimer_Settings;
   +
   +
   +
   +/**
   + * @brief  This function handles  WAKE UP TIMER  interrupt request.
   + * @retval None
   + */
   +void
   +RTC_WKUP_IRQHandler(void)
   +{
   +    HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
    }
    
    
   @@ -133,34 +130,37 @@
    #endif
    
    /**
   -  * @brief  This function handles  ALARM (A&B)  interrupt request.
   -  * @retval None
   -  */
   -void RTC_Alarm_IRQHandler(void)
   + * @brief  This function handles  ALARM (A&B)  interrupt request.
   + * @retval None
   + */
   +void
   +RTC_Alarm_IRQHandler(void)
    {
        HAL_RTC_AlarmIRQHandler(&RtcHandle);
    }
    
    /**
   -  * @brief  Alarm A callback.
   -  * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   -  *                the configuration information for RTC.
   -  * @retval None
   -  */
   -void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
   -{
   -
   -}
   -
   -
   -void hal_rtc_init(RTC_DateTypeDef *date, RTC_TimeTypeDef *time)
   + * @brief  Alarm A callback.
   + * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   + *                the configuration information for RTC.
   + * @retval None
   + */
   +void
   +HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
   +{
   +
   +}
   +
   +
   +void
   +hal_rtc_init(RTC_DateTypeDef *date, RTC_TimeTypeDef *time)
    {
        int rc;
    
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
        NVIC_DisableIRQ(RTC_Alarm_IRQn);
        NVIC_DisableIRQ(TAMPER_STAMP_IRQn);
   -        
   +
        RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
    
        __HAL_RCC_RTC_ENABLE( );
   @@ -168,71 +168,68 @@
        PeriphClkInit.PeriphClockSelection |= RCC_PERIPHCLK_RTC;
        PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
    
   -    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
   -    {
   +    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
            assert(0);
        }
    
   -    RtcHandle.Instance            = RTC;
   -    RtcHandle.Init.HourFormat     = RTC_HOURFORMAT_24;
   -    RtcHandle.Init.AsynchPrediv   = PREDIV_A;
   -    RtcHandle.Init.SynchPrediv    = PREDIV_S;
   -    RtcHandle.Init.OutPut         = RTC_OUTPUT_DISABLE;
   +    RtcHandle.Instance = RTC;
   +    RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
   +    RtcHandle.Init.AsynchPrediv = PREDIV_A;
   +    RtcHandle.Init.SynchPrediv = PREDIV_S;
   +    RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
        RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
   -    RtcHandle.Init.OutPutType     = RTC_OUTPUT_TYPE_OPENDRAIN;
   -    
   -    rc = HAL_RTC_Init( &RtcHandle );
   +    RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
   +
   +    rc = HAL_RTC_Init(&RtcHandle);
        assert(rc == 0);
    
   -    if (date==NULL) {
   -    
   -        RTC_DateTypeDef default_date =
   -        {
   -            .Year                     = 0,
   -            .Month                    = RTC_MONTH_JANUARY,
   -            .Date                     = 1,
   -            .WeekDay                  = RTC_WEEKDAY_MONDAY,
   +    if (date == NULL) {
   +
   +        RTC_DateTypeDef default_date = {
   +            .Year = 0,
   +            .Month = RTC_MONTH_JANUARY,
   +            .Date = 1,
   +            .WeekDay = RTC_WEEKDAY_MONDAY,
            };
    
            date = &default_date;
        }
    
   -    if (time==NULL) {
   -        
   -        RTC_TimeTypeDef default_time =
   -        {
   -            .Hours                    = 0,
   -            .Minutes                  = 0,
   -            .Seconds                  = 0,
   -            .SubSeconds               = 0,
   -            .TimeFormat               = 0,
   -            .StoreOperation           = RTC_STOREOPERATION_RESET,
   -            .DayLightSaving           = RTC_DAYLIGHTSAVING_NONE,
   +    if (time == NULL) {
   +
   +        RTC_TimeTypeDef default_time = {
   +            .Hours = 0,
   +            .Minutes = 0,
   +            .Seconds = 0,
   +            .SubSeconds = 0,
   +            .TimeFormat = 0,
   +            .StoreOperation = RTC_STOREOPERATION_RESET,
   +            .DayLightSaving = RTC_DAYLIGHTSAVING_NONE,
            };
   -        
   +
            time = &default_time;
        }
    
   -    HAL_RTC_SetDate( &RtcHandle, date, RTC_FORMAT_BIN );
   -    HAL_RTC_SetTime( &RtcHandle, time, RTC_FORMAT_BIN );
   -
   -    // Enable Direct Read of the calendar registers (not through Shadow registers)
   -    HAL_RTCEx_DisableBypassShadow( &RtcHandle );
   -    
   -#ifdef RTC_ALARM_TEST   
   -    //setup alarm
   -    RtcAlarm.AlarmTime.Hours            = 0;
   -    RtcAlarm.AlarmTime.Minutes          = 0;
   -    RtcAlarm.AlarmTime.Seconds          = 1;
   -    RtcAlarm.AlarmTime.SubSeconds       = 0;
   -    RtcAlarm.AlarmTime.TimeFormat       = RTC_HOURFORMAT12_AM;
   -    RtcAlarm.AlarmTime.DayLightSaving   = RTC_DAYLIGHTSAVING_NONE;
   -    RtcAlarm.AlarmTime.StoreOperation   = RTC_STOREOPERATION_RESET;
   -    RtcAlarm.AlarmMask                  = RTC_ALARMMASK_SECONDS;
   -    RtcAlarm.AlarmSubSecondMask         = RTC_ALARMSUBSECONDMASK_ALL;
   -    RtcAlarm.AlarmDateWeekDaySel        = RTC_ALARMDATEWEEKDAYSEL_DATE;
   -    RtcAlarm.AlarmDateWeekDay           = 1;
   -    RtcAlarm.Alarm                      = RTC_ALARM_A;
   +    HAL_RTC_SetDate(&RtcHandle, date, RTC_FORMAT_BIN);
   +    HAL_RTC_SetTime(&RtcHandle, time, RTC_FORMAT_BIN);
   +
   +    /* Enable Direct Read of the calendar registers (not through Shadow registers) */
   +    HAL_RTCEx_DisableBypassShadow(&RtcHandle);
   +
   +#ifdef RTC_ALARM_TEST
   +    /*setup alarm */
   +    RtcAlarm.AlarmTime.Hours = 0;
   +    RtcAlarm.AlarmTime.Minutes = 0;
   +    RtcAlarm.AlarmTime.Seconds = 1;
   +    RtcAlarm.AlarmTime.SubSeconds = 0;
   +    RtcAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM;
   +    RtcAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
   +    RtcAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
   +    RtcAlarm.AlarmMask = RTC_ALARMMASK_SECONDS;
   +    RtcAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
   +    RtcAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
   +    RtcAlarm.AlarmDateWeekDay = 1;
   +    RtcAlarm.Alarm = RTC_ALARM_A;
    
        NVIC_SetPriority(RTC_Alarm_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
        NVIC_SetVector(RTC_Alarm_IRQn, (uint32_t)RTC_Alarm_IRQHandler);
   @@ -241,8 +238,8 @@
        rc = HAL_RTC_SetAlarm_IT(&RtcHandle, &RtcAlarm, FORMAT_BIN);
    #else
    
   -    HAL_RTC_DeactivateAlarm( &RtcHandle, RTC_ALARM_A );
   -    HAL_RTC_DeactivateAlarm( &RtcHandle, RTC_ALARM_B );
   +    HAL_RTC_DeactivateAlarm(&RtcHandle, RTC_ALARM_A);
   +    HAL_RTC_DeactivateAlarm(&RtcHandle, RTC_ALARM_B);
        NVIC_DisableIRQ(RTC_Alarm_IRQn);
    #endif
    
   @@ -254,81 +251,82 @@
        NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
        /*Enable IRQ now forever */
        NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -    
   +
        /*Initialises start value of the follower*/
   -    WakeUpTimer_Settings.follower_counter_start = (FOLLOWER_PRESCALER_S - (uint32_t)((RtcHandle.Instance->SSR) & RTC_SSR_SS));
   +    WakeUpTimer_Settings.follower_counter_start =
   +        (FOLLOWER_PRESCALER_S - (uint32_t)((RtcHandle.Instance->SSR) & RTC_SSR_SS));
    
        assert(rc == 0);
   -    
   -}
   -
   -
   -void hal_rtc_enable_wakeup(uint32_t time_ms)
   -{    
   +
   +}
   +
   +
   +void
   +hal_rtc_enable_wakeup(uint32_t time_ms)
   +{
        int rc;
    
        /* WARNING : works only with time_ms =< 32 s (MAX_RTC_PERIOD_MSEC)
   -                (due to the follower which is currently 
   +                (due to the follower which is currently
                    unable to setup lower resolution)
   -       
   -       TODO : improve setup of follower's resolution 
   -
   -       NOTE : for time_ms > 32 follower could be used as is by using 
   +
   +       TODO : improve setup of follower's resolution
   +
   +       NOTE : for time_ms > 32 follower could be used as is by using
                  ALARM features (assuming RTC clocking very different of 1Hz)
   -    */
   +     */
    
    
        /*
   -    The wakeup timer clock input can be:
   -    • RTC clock (RTCCLK) divided by 2, 4, 8, or 16.
   -    When RTCCLK is LSE(32.768kHz), this allows configuring the wakeup interrupt period
   -    from 122 µs to 32 s, with a resolution down to 61µs
   -    • ck_spre (usually 1 Hz internal clock)
   -    When ck_spre frequency is 1Hz, this allows achieving a wakeup time from 1 s to
   -    around 36 hours with one-second resolution. This large programmable time range is
   -    divided in 2 parts:
   -    – from 1s to 18 hours when WUCKSEL [2:1] = 10
   -    – and from around 18h to 36h when WUCKSEL[2:1] = 11
   -    */
   -    
   -
   -    if(time_ms < (uint32_t)(MAX_RTC_PERIOD_MSEC) )
   -    {
   +       The wakeup timer clock input can be:
   +       • RTC clock (RTCCLK) divided by 2, 4, 8, or 16.
   +       When RTCCLK is LSE(32.768kHz), this allows configuring the wakeup interrupt period
   +       from 122 µs to 32 s, with a resolution down to 61µs
   +       • ck_spre (usually 1 Hz internal clock)
   +       When ck_spre frequency is 1Hz, this allows achieving a wakeup time from 1 s to
   +       around 36 hours with one-second resolution. This large programmable time range is
   +       divided in 2 parts:
   +       – from 1s to 18 hours when WUCKSEL [2:1] = 10
   +       – and from around 18h to 36h when WUCKSEL[2:1] = 11
   +     */
   +
   +
   +    if (time_ms < (uint32_t)(MAX_RTC_PERIOD_MSEC)) {
            /* 0 < time_ms < 32 sec */
            WakeUpTimer_Settings.clk_srce_sel = RTC_WAKEUPCLOCK_RTCCLK_DIV16;
            WakeUpTimer_Settings.autoreload_timer = (uint32_t)(time_ms / (MIN_RTC_PERIOD_MSEC));
   -    }
   -    else if(time_ms < (uint32_t)(18 * 60 * 60 * 1000) )
   -    {   
   +    } else if (time_ms < (uint32_t)(18 * 60 * 60 * 1000)) {
            /* 32 sec < time_ms < 18h */
            WakeUpTimer_Settings.clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
            /* load counter */
            WakeUpTimer_Settings.autoreload_timer = (time_ms / 1000);
            /* do little adjustement */
            WakeUpTimer_Settings.autoreload_timer -= 1;
   -    }
   -    else{
   +    } else {
            /* 18h < time_ms < 36h */
    
            /*
   -        TODO : setup wakeup with ALARM feature instead of WAKEUP     
   -        */
   +           TODO : setup wakeup with ALARM feature instead of WAKEUP
   +         */
            WakeUpTimer_Settings.clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
            WakeUpTimer_Settings.autoreload_timer = (time_ms / 1000);
    
        }
    
        /* Setting the Wake up time */
   -    rc = HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, (uint32_t)WakeUpTimer_Settings.autoreload_timer, WakeUpTimer_Settings.clk_srce_sel);
   +    rc = HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, (uint32_t)WakeUpTimer_Settings.autoreload_timer,
   +                                     WakeUpTimer_Settings.clk_srce_sel);
        assert (rc == HAL_OK);
    
   -    WakeUpTimer_Settings.follower_counter_start = (FOLLOWER_PRESCALER_S - (uint32_t)((RtcHandle.Instance->SSR) & RTC_SSR_SS));
   -}
   -
   -uint32_t hal_rtc_get_elapsed_wakeup_timer(void)
   +    WakeUpTimer_Settings.follower_counter_start =
   +        (FOLLOWER_PRESCALER_S - (uint32_t)((RtcHandle.Instance->SSR) & RTC_SSR_SS));
   +}
   +
   +uint32_t
   +hal_rtc_get_elapsed_wakeup_timer(void)
    {
        volatile uint16_t time_ms, follower_counter_elapsed;
   -    
   +
        /*RTC_SSR is a downcounter*/
        follower_counter_elapsed = (FOLLOWER_PRESCALER_S - (uint16_t)((RtcHandle.Instance->SSR) & RTC_SSR_SS));
    
   @@ -336,24 +334,24 @@
        follower_counter_elapsed -= WakeUpTimer_Settings.follower_counter_start;
    
        /*when stop-time wrap around the counter then elapsed time is more than expected */
   -    if(follower_counter_elapsed > FOLLOWER_PRESCALER_S)
   -    {
   +    if (follower_counter_elapsed > FOLLOWER_PRESCALER_S) {
            follower_counter_elapsed -= (((1<<(CHAR_BIT * sizeof(follower_counter_elapsed)))-1) - FOLLOWER_PRESCALER_S);
        }
    
        /*convert it into ms*/
        time_ms = ((follower_counter_elapsed * 1000) / DIVIDED_FOLLOWER_FREQUENCY);
   -    
   +
        return (uint32_t)time_ms;
    
    }
    
   -void hal_rtc_disable_wakeup(void)
   +void
   +hal_rtc_disable_wakeup(void)
    {
        HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
   -    
   +
        /* In order to take into account the pending IRQ and clear      */
   -    /* wakeup flags (EXTI->PR & RTC_EXTI_LINE_WAKEUPTIMER_EVENT)    */    
   +    /* wakeup flags (EXTI->PR & RTC_EXTI_LINE_WAKEUPTIMER_EVENT)    */
        /* after reentring in critical region : DO NOT DISABLE IRQ !!!  */
        /* IRQ will remain enabled forever                              */
        /* NVIC_DisableIRQ(RTC_WKUP_IRQn); */
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32_common/src/hal_os_tick.c
   <details>
   
   ```diff
   @@ -52,10 +52,12 @@
    extern void stm32_power_enter(int power_mode, uint32_t durationMS);
    extern void stm32_tick_init(uint32_t os_ticks_per_sec, int prio);
    #else
   -static void stm32_tick_init(uint32_t os_ticks_per_sec, int prio) {
   -        /*nb of ticks per seconds is hardcoded in HAL_InitTick(..) to have 1ms/tick */
   +static void
   +stm32_tick_init(uint32_t os_ticks_per_sec, int prio)
   +{
   +    /*nb of ticks per seconds is hardcoded in HAL_InitTick(..) to have 1ms/tick */
        assert(os_ticks_per_sec == OS_TICKS_PER_SEC);
   -    
   +
        uint32_t reload_val;
    
        reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
   @@ -79,12 +81,15 @@
    #endif
    
    }
   -static void stm32_power_enter(int power_mode, uint32_t durationMS)
   +static void
   +stm32_power_enter(int power_mode, uint32_t durationMS)
    {
        __DSB();
        __WFI();
    }
   -void stm32_tickless_init() {
   +void
   +stm32_tickless_init()
   +{
    }
    
    #endif
   @@ -94,12 +99,12 @@
    os_tick_idle(os_time_t ticks)
    {
        /* default mode will enter in WFI */
   -    int power_mode=HAL_BSP_POWER_WFI;
   +    int power_mode = HAL_BSP_POWER_WFI;
    
        OS_ASSERT_CRITICAL();
    
        /* if < MIN_TICKS, then just leave standard SYSTICK and WFI to and wakeup in 1ms */
   -    if (ticks==0) { 
   +    if (ticks == 0) {
            __DSB();
            __WFI();
            return;
   @@ -110,7 +115,7 @@
    
    #if MYNEWT_VAL(BSP_POWER_SETUP)
        /* ask bsp for lowest power mode that is possible */
   -    power_mode=hal_bsp_power_handler_get_mode(timeMS);
   +    power_mode = hal_bsp_power_handler_get_mode(timeMS);
    
        /* Tell BSP we enter sleep, so it should shut down any board periphs it can for the mode it wants */
        hal_bsp_power_handler_sleep_enter(power_mode);
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32l1xx/src/clock_stm32l1xx.c
   <details>
   
   ```diff
   @@ -254,24 +254,22 @@
    SystemClock_RestartPLL(void)
    {
        __HAL_RCC_PWR_CLK_ENABLE( );
   -    __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 );
   +    __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
    
    #if MYNEWT_VAL(STM32_CLOCK_HSE)
        /* Enable HSE */
   -    __HAL_RCC_HSE_CONFIG( RCC_HSE_ON );
   +    __HAL_RCC_HSE_CONFIG(RCC_HSE_ON);
    
        /* Wait till HSE is ready */
   -    while( __HAL_RCC_GET_FLAG( RCC_FLAG_HSERDY ) == RESET )
   -    {
   -    }
   -#endif 
   +    while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET) {
   +    }
   +#endif
    #if MYNEWT_VAL(STM32_CLOCK_HSI)
        /* Enable HSI */
        __HAL_RCC_HSI_ENABLE( );
    
        /* Wait till HSI is ready */
   -    while( __HAL_RCC_GET_FLAG( RCC_FLAG_HSIRDY ) == RESET )
   -    {
   +    while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET) {
        }
    #endif
    #if MYNEWT_VAL(STM32_CLOCK_HSI)
   @@ -279,8 +277,7 @@
        __HAL_RCC_MSI_ENABLE( );
    
        /* Wait till MSI is ready */
   -    while( __HAL_RCC_GET_FLAG( RCC_FLAG_MSIRDY ) == RESET )
   -    {
   +    while (__HAL_RCC_GET_FLAG(RCC_FLAG_MSIRDY) == RESET) {
        }
    #endif
    
   @@ -288,16 +285,14 @@
        __HAL_RCC_PLL_ENABLE( );
    
        /* Wait till PLL is ready */
   -    while( __HAL_RCC_GET_FLAG( RCC_FLAG_PLLRDY ) == RESET )
   -    {
   +    while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET) {
        }
    
        /* Select PLL as system clock source */
   -    __HAL_RCC_SYSCLK_CONFIG ( RCC_SYSCLKSOURCE_PLLCLK );
   +    __HAL_RCC_SYSCLK_CONFIG (RCC_SYSCLKSOURCE_PLLCLK);
    
        /* Wait till PLL is used as system clock source */
   -    while( __HAL_RCC_GET_SYSCLK_SOURCE( ) != RCC_SYSCLKSOURCE_STATUS_PLLCLK )
   -    {
   +    while (__HAL_RCC_GET_SYSCLK_SOURCE( ) != RCC_SYSCLKSOURCE_STATUS_PLLCLK) {
        }
    }
    #endif
   ```
   
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services