apache-mynewt-bot removed a comment on issue #2224: add functionality to allow 
low power operation for STM32L1xx
URL: https://github.com/apache/mynewt-core/pull/2224#issuecomment-595362454
 
 
   
   <!-- 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,8 +35,8 @@
    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 */
   @@ -49,7 +49,7 @@
    
        while (1) {
    
   -        /*Disables the Power Voltage Detector(PVD) */                
   +        /*Disables the Power Voltage Detector(PVD) */
            HAL_PWR_DisablePVD( );
            /* Enable Ultra low power mode */
            HAL_PWREx_EnableUltraLowPower( );
   @@ -61,13 +61,13 @@
        }
    }
    
   -void 
   +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) */
   @@ -77,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);
    
   @@ -102,7 +102,7 @@
    
    }
    
   -void 
   +void
    stm32_tickless_start(uint32_t timeMS)
    {
    
   @@ -116,10 +116,10 @@
        CLEAR_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk);
    }
    
   -void 
   +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 int asleep_ticks = os_time_ms_to_ticks32(asleep_ms);
   @@ -133,10 +133,10 @@
        NVIC_EnableIRQ(SysTick_IRQn);
        /* reenable SysTick */
        SET_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk);
   -    
   -}
   -
   -void 
   +
   +}
   +
   +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 */
   @@ -147,7 +147,7 @@
    
        if (durationMS >= 32000) {
            /* 32 sec is the largest value of wakeuptimer   leave 100ms slack */
   -        durationMS = (32000 - 100); 
   +        durationMS = (32000 - 100);
        }
    
        /* begin tickless */
   @@ -158,7 +158,7 @@
        switch (power_mode) {
        case HAL_BSP_POWER_OFF:
        case HAL_BSP_POWER_DEEP_SLEEP: {
   -        /*Disables the Power Voltage Detector(PVD) */                
   +        /*Disables the Power Voltage Detector(PVD) */
            HAL_PWR_DisablePVD( );
            /* Enable Ultra low power mode */
            HAL_PWREx_EnableUltraLowPower( );
   @@ -172,7 +172,7 @@
        }
        case HAL_BSP_POWER_SLEEP: {
    
   -        /*Disables the Power Voltage Detector(PVD) */                
   +        /*Disables the Power Voltage Detector(PVD) */
            HAL_PWR_DisablePVD( );
            /* Enable Ultra low power mode */
            HAL_PWREx_EnableUltraLowPower( );
   @@ -187,16 +187,16 @@
        case HAL_BSP_POWER_WFI: {
            HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
    
   -//        SystemClock_RestartPLL();            
   +/*        SystemClock_RestartPLL(); */
            break;
        }
        case HAL_BSP_POWER_ON:
        default: {
   -        
   -        break;
   -    }
   -    }
   -    
   +
   +        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,13 +1,13 @@
    /**
     * 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.
     */
    
   @@ -81,13 +81,13 @@
    
    
    /*!
   - * RTC timer context 
   + * 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;
   +} RtcTimerContext_t;
    
    
    /*!
   @@ -95,7 +95,7 @@
     */
    static RTC_HandleTypeDef RtcHandle = {
        .Instance = NULL,
   -    .Init = { 
   +    .Init = {
            .HourFormat = 0,
            .AsynchPrediv = 0,
            .SynchPrediv = 0,
   @@ -116,10 +116,10 @@
    
    
    /**
   -  * @brief  This function handles  WAKE UP TIMER  interrupt request.
   -  * @retval None
   -  */
   -void 
   + * @brief  This function handles  WAKE UP TIMER  interrupt request.
   + * @retval None
   + */
   +void
    RTC_WKUP_IRQHandler(void)
    {
        HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
   @@ -131,29 +131,29 @@
    #endif
    
    /**
   -  * @brief  This function handles  ALARM (A&B)  interrupt request.
   -  * @retval None
   -  */
   -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 
   + * @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 
   +void
    hal_rtc_init(RTC_DateTypeDef *date, RTC_TimeTypeDef *time)
    {
        int rc;
   @@ -161,7 +161,7 @@
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
        NVIC_DisableIRQ(RTC_Alarm_IRQn);
        NVIC_DisableIRQ(TAMPER_STAMP_IRQn);
   -        
   +
        RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
    
        __HAL_RCC_RTC_ENABLE( );
   @@ -169,8 +169,7 @@
        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);
        }
    
   @@ -181,7 +180,7 @@
        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);
        assert(rc == 0);
    
   @@ -196,7 +195,7 @@
            date = &default_date;
        }
    
   -    if (time==NULL) {
   +    if (time == NULL) {
            RTC_TimeTypeDef default_time = {
                .Hours = 0,
                .Minutes = 0,
   @@ -206,18 +205,18 @@
                .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)
   +    /* Enable Direct Read of the calendar registers (not through Shadow 
registers) */
        HAL_RTCEx_DisableBypassShadow(&RtcHandle);
   -    
   -#ifdef RTC_ALARM_TEST   
   -    //setup alarm
   +
   +#ifdef RTC_ALARM_TEST
   +    /*setup alarm */
        RtcAlarm.AlarmTime.Hours = 0;
        RtcAlarm.AlarmTime.Minutes = 0;
        RtcAlarm.AlarmTime.Seconds = 1;
   @@ -251,30 +250,30 @@
        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 = 
   +    WakeUpTimer_Settings.follower_counter_start =
            (FOLLOWER_PRESCALER_S - (uint32_t)((RtcHandle.Instance->SSR) & 
RTC_SSR_SS));
    
        assert(rc == 0);
   -    
   -}
   -
   -
   -void 
   +
   +}
   +
   +
   +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)
   -    */
   +     */
    
    
        /*
   @@ -289,13 +288,13 @@
         * – 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 */
   @@ -305,7 +304,7 @@
        } 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);
   @@ -313,19 +312,19 @@
        }
    
        /* Setting the Wake up time */
   -    rc = HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, 
(uint32_t)WakeUpTimer_Settings.autoreload_timer, 
   +    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 = 
   +    WakeUpTimer_Settings.follower_counter_start =
            (FOLLOWER_PRESCALER_S - (uint32_t)((RtcHandle.Instance->SSR) & 
RTC_SSR_SS));
    }
    
   -uint32_t 
   +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));
    
   @@ -339,18 +338,18 @@
    
        /*convert it into ms*/
        time_ms = ((follower_counter_elapsed * 1000) / 
DIVIDED_FOLLOWER_FREQUENCY);
   -    
   +
        return (uint32_t)time_ms;
    
    }
    
   -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
   @@ -48,12 +48,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) 
   +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;
   @@ -78,7 +78,7 @@
    
    }
    
   -static void 
   +static void
    stm32_power_enter(int power_mode, uint32_t durationMS)
    {
        __DSB();
   @@ -97,7 +97,7 @@
        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;
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32l1xx/src/clock_stm32l1xx.c
   <details>
   
   ```diff
   @@ -261,16 +261,15 @@
        __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_MSI)
   @@ -278,7 +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
    
   @@ -286,14 +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);
    
        /* 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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to