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 2019/12/21 18:57:50 UTC

[GitHub] [mynewt-core] brianwyld opened a new pull request #2138: Add possibility to configure idle task stack size in syscfg.yml

brianwyld opened a new pull request #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138
 
 
   The hard defined idle stack size of 64 on cortex-m3 sometimes overruns depending on which ISRs run on it. This PR makes the idle stack size configurable in syscfg (like the main task) so that a given project can increase its size. The change currently only will apply to cortex-m3 architecture (as other architectures have arch.h with specific size definitions hard coded.

----------------------------------------------------------------
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

[GitHub] [mynewt-core] andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-568294928
 
 
   Interrupts use separate stack (main stack), they do not use tasks' stacks (process stack).
   If stack for idle task needs to be larger you need to explain why. Making it configurable via syscfg does not make much sense because idle task does not execute any user code so it can be calculated how much stack is needed. The reason why size is different when SysView is enabled is because SysView calls may involve messages exchange over RTT which use some additional stack so its size was adjusted accordingly.

----------------------------------------------------------------
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

[GitHub] [mynewt-core] brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-571659425
 
 
   This one:
   Revision: 13423bde3b2a8177431b740e4e61f93beac1faf1
   Author: Andrzej Kaczmarek <an...@codecoup.pl>
   Date: 05/12/2019 10:40:32
   Message:
   kernel/os: Fix invalid stacktop references
   
   
   
   On Tue, 7 Jan 2020 at 17:11, Andrzej Kaczmarek <no...@github.com>
   wrote:
   
   > Hi Andrzej,
   > I haven't replicated my ISR stack since. However, I do get the stack
   > overflow detection code asserting on the idle task.
   > This might be due to my extra code I call in os_tick_idle() which I'm
   > updating to do low power management on STM32L1xx (tickless mode, BSP periph
   > power down)...
   > I note commits in the master related to the stack check code by yourself
   > in december which I don't have in this fork - are these to fix bugs in this
   > check code?
   > thanks
   >
   > which commits you are referring to?
   >
   > —
   > You are receiving this because you authored the thread.
   > Reply to this email directly, view it on GitHub
   > <https://github.com/apache/mynewt-core/pull/2138?email_source=notifications&email_token=AMIHRIDW3F7QR3KVR5KGDHTQ4SSTTA5CNFSM4J6IHSX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIJMFGI#issuecomment-571654809>,
   > or unsubscribe
   > <https://github.com/notifications/unsubscribe-auth/AMIHRICOHRU6UVZZF4NACR3Q4SSTTANCNFSM4J6IHSXQ>
   > .
   >
   

----------------------------------------------------------------
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

[GitHub] [mynewt-core] brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-568296800
 
 
   ok... I'll try to replicate the idle stack overflow, which I was pretty sure was due to an ISR... 

----------------------------------------------------------------
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

[GitHub] [mynewt-core] apache-mynewt-bot commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-576345926
 
 
   
   <!-- style-bot -->
   
   ## Style check summary
   
   #### hw/mcu/stm/stm32_common/src/hal_os_tick.c
   <details>
   
   ```diff
   @@ -1,135 +1,138 @@
   -/*
   - * Licensed to the Apache Software Foundation (ASF) under one
   - * or more contributor license agreements.  See the NOTICE file
   - * distributed with this work for additional information
   - * regarding copyright ownership.  The ASF licenses this file
   - * to you 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 language governing permissions and limitations
   - * under the License.
   - */
   -
   -#include <assert.h>
   -#include "os/mynewt.h"
   -#include <hal/hal_os_tick.h>
   -#include <hal/hal_bsp.h>
   -#include "bsp/bsp.h"
   -#include "system_stm32l1xx.h"
   -#include "core_cm3.h"
   -#include "stm32l151xc.h"
   -
   -/*
   - * Errata for STM32F405, STM32F407, STM32F415, STM32F417.
   - * When WFI instruction is placed at address like 0x080xxxx4
   - * (also seen for addresses ending with xxx2). System may
   - * crash.
   - * __WFI function places WFI instruction at address ending with x0 or x8
   - * for affected MCUs.
   - */
   -#include "stm32l1xx_hal.h"
   -
   -#if defined(STM32F405xx) || defined(STM32F407xx) || \
   -    defined(STM32F415xx) || defined(STM32F417xx)
   -#undef __WFI
   -__attribute__((aligned(8), naked)) void static
   -__WFI(void)
   -{
   -     __ASM volatile("wfi\n"
   -                    "bx lr");
   -}
   -#endif
   -
   -/* implementation of different power modes available on STM32 processors */
   -#ifdef STM32L151xC
   -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 */
   -    assert(os_ticks_per_sec == OS_TICKS_PER_SEC);
   -    
   -    uint32_t reload_val;
   -
   -    reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
   -
   -    /* Set the system time ticker up */
   -    SysTick->LOAD = reload_val;
   -    SysTick->VAL = 0;
   -    SysTick->CTRL = 0x0007;
   -
   -    /* Set the system tick priority */
   -    NVIC_SetPriority(SysTick_IRQn, prio);
   -
   -    /*
   -     * Keep clocking debug even when CPU is sleeping, stopped or in standby.
   -     */
   -#if !MYNEWT_VAL(MCU_STM32F0)
   -    DBGMCU->CR |= (DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   -#else
   -    DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   -#endif
   -
   -}
   -static void stm32_power_enter(int power_mode, uint32_t durationMS)
   -{
   -    __DSB();
   -    __WFI();
   -}
   -void stm32_tickless_init() {
   -}
   -
   -#endif
   -
   -
   -void
   -os_tick_idle(os_time_t ticks)
   -{
   -    /* default mode will enter in 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) { 
   -        __DSB();
   -        __WFI();
   -        return;
   -    }
   -
   -
   -    /* Convert to ms */
   -    volatile uint32_t timeMS = os_time_ticks_to_ms32(ticks);
   -
   -#if MYNEWT_VAL(BSP_POWER_SETUP)
   -    /* ask bsp for lowest power mode that is possible */
   -    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();
   -
   -#endif
   -
   -    /* setup the appropriate mcu power mode during timeMs asked by os scheduling */
   -    stm32_power_enter(power_mode, timeMS);
   -
   -#if MYNEWT_VAL(BSP_POWER_SETUP)
   -    /* bsp exits the actual power mode */
   -    hal_bsp_power_handler_sleep_exit();
   -#endif
   -
   -
   -}
   -
   -void
   -os_tick_init(uint32_t os_ticks_per_sec, int prio)
   -{
   -    stm32_tick_init(os_ticks_per_sec, prio);
   -}
   +/*
   + * Licensed to the Apache Software Foundation (ASF) under one
   + * or more contributor license agreements.  See the NOTICE file
   + * distributed with this work for additional information
   + * regarding copyright ownership.  The ASF licenses this file
   + * to you 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 language governing permissions and limitations
   + * under the License.
   + */
   +
   +#include <assert.h>
   +#include "os/mynewt.h"
   +#include <hal/hal_os_tick.h>
   +#include <hal/hal_bsp.h>
   +#include "bsp/bsp.h"
   +#include "system_stm32l1xx.h"
   +#include "core_cm3.h"
   +#include "stm32l151xc.h"
   +
   +/*
   + * Errata for STM32F405, STM32F407, STM32F415, STM32F417.
   + * When WFI instruction is placed at address like 0x080xxxx4
   + * (also seen for addresses ending with xxx2). System may
   + * crash.
   + * __WFI function places WFI instruction at address ending with x0 or x8
   + * for affected MCUs.
   + */
   +#include "stm32l1xx_hal.h"
   +
   +#if defined(STM32F405xx) || defined(STM32F407xx) || \
   +    defined(STM32F415xx) || defined(STM32F417xx)
   +#undef __WFI
   +__attribute__((aligned(8), naked)) void static
   +__WFI(void)
   +{
   +    __ASM volatile ("wfi\n"
   +                    "bx lr");
   +}
   +#endif
   +
   +/* implementation of different power modes available on STM32 processors */
   +#ifdef STM32L151xC
   +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 */
   +    assert(os_ticks_per_sec == OS_TICKS_PER_SEC);
   +
   +    uint32_t reload_val;
   +
   +    reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
   +
   +    /* Set the system time ticker up */
   +    SysTick->LOAD = reload_val;
   +    SysTick->VAL = 0;
   +    SysTick->CTRL = 0x0007;
   +
   +    /* Set the system tick priority */
   +    NVIC_SetPriority(SysTick_IRQn, prio);
   +
   +    /*
   +     * Keep clocking debug even when CPU is sleeping, stopped or in standby.
   +     */
   +#if !MYNEWT_VAL(MCU_STM32F0)
   +    DBGMCU->CR |= (DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   +#else
   +    DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   +#endif
   +
   +}
   +static void
   +stm32_power_enter(int power_mode, uint32_t durationMS)
   +{
   +    __DSB();
   +    __WFI();
   +}
   +void
   +stm32_tickless_init() {
   +}
   +
   +#endif
   +
   +
   +void
   +os_tick_idle(os_time_t ticks)
   +{
   +    /* default mode will enter in 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) {
   +        __DSB();
   +        __WFI();
   +        return;
   +    }
   +
   +
   +    /* Convert to ms */
   +    volatile uint32_t timeMS = os_time_ticks_to_ms32(ticks);
   +
   +#if MYNEWT_VAL(BSP_POWER_SETUP)
   +    /* ask bsp for lowest power mode that is possible */
   +    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();
   +
   +#endif
   +
   +    /* setup the appropriate mcu power mode during timeMs asked by os scheduling */
   +    stm32_power_enter(power_mode, timeMS);
   +
   +#if MYNEWT_VAL(BSP_POWER_SETUP)
   +    /* bsp exits the actual power mode */
   +    hal_bsp_power_handler_sleep_exit();
   +#endif
   +
   +
   +}
   +
   +void
   +os_tick_init(uint32_t os_ticks_per_sec, int prio)
   +{
   +    stm32_tick_init(os_ticks_per_sec, prio);
   +}
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32l1xx/src/hal_power_mgnt.c
   <details>
   
   ```diff
   @@ -1,145 +1,150 @@
   -/*
   - * Licensed to the Apache Software Foundation (ASF) under one
   - * or more contributor license agreements.  See the NOTICE file
   - * distributed with this work for additional information
   - * regarding copyright ownership.  The ASF licenses this file
   - * to you 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 language governing permissions and limitations
   - * under the License.
   - */
   -
   -#include <string.h>
   -#include <assert.h>
   -#include <os/mynewt.h>
   -#include <syscfg/syscfg.h>
   -#include <mcu/stm32_hal.h>
   -#include <hal/hal_bsp.h>
   -#include "stm32l1xx_hal_pwr.h"
   -#include "stm32l1xx_hal_rtc.h"
   -
   -
   -extern void hal_rtc_enable_wakeup(uint32_t time_ms);
   -extern void hal_rtc_disable_wakeup(void);
   -extern uint32_t hal_rtc_get_remaining_time_before_wakeup(void);
   -extern void hal_rtc_init(RTC_DateTypeDef *date, RTC_TimeTypeDef *time);
   -
   -/* Put MCU  in lowest power stop state, exit only via POR or reset pin */
   -void hal_mcu_halt() {
   -    /* all interupts and exceptions off */
   -    /* PVD off */
   -    /* power watchdog off */
   -    /* Be in lowest power mode forever */
   -    while(1) {
   -//        HAL_PWR_EnterSTANDBYMode();
   -        // TEST : don't lose RAM so can debug low powerness
   -        HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
   -        /* debug breakpoint */
   -
   -    }
   -}
   -
   -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);
   -    
   -    uint32_t reload_val;
   -
   -    reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
   -
   -    /* Set the system time ticker up */
   -    SysTick->LOAD = reload_val;
   -    SysTick->VAL = 0;
   -    SysTick->CTRL = 0x0007;
   -
   -    /* Set the system tick priority */
   -    NVIC_SetPriority(SysTick_IRQn, prio);
   -
   -    /*
   -     * Keep clocking debug even when CPU is sleeping, stopped or in standby.
   -     */
   -#if !MYNEWT_VAL(MCU_STM32F0)
   -    DBGMCU->CR |= (DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   -#else
   -    DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   -#endif
   -
   -#if MYNEWT_VAL(OS_TICKLESS_RTC)
   -    /* initialise RTC for tickless code if required */
   -    hal_rtc_init(NULL, NULL);
   -#endif
   -
   -}
   -void stm32_tickless_start(uint32_t timeMS) {
   -    /* Start RTC alarm for in this amount of time */
   -    hal_rtc_enable_wakeup(timeMS);
   -    /* Stop SYSTICK */
   -    NVIC_DisableIRQ(SysTick_IRQn);
   -    //HAL_SuspendTick();
   -}
   -
   -void stm32_tickless_stop(uint32_t timeMS) {
   -    /* disable RTC */
   -    hal_rtc_disable_wakeup();
   -
   -    /* reenable systick */
   -    NVIC_EnableIRQ(SysTick_IRQn);
   -    //HAL_ResumeTick();
   -
   -    /* add asleep duration to tick counter : how long we should have slept for minus any remaining time */ 
   -    int asleep_ticks = os_time_ms_to_ticks32(timeMS - hal_rtc_get_remaining_time_before_wakeup());
   -    assert(asleep_ticks>=0);
   -    os_time_advance(asleep_ticks);
   -}
   -
   -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) {
   -        HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   -        return;
   -    }
   -    /* begin tickless */
   -#if MYNEWT_VAL(OS_TICKLESS_RTC)
   -    stm32_tickless_start(durationMS);
   -#endif
   -
   -    switch(power_mode) {
   -        case HAL_BSP_POWER_OFF: {
   -            HAL_PWR_EnterSTANDBYMode();
   -            break;
   -        }
   -        case HAL_BSP_POWER_DEEP_SLEEP: {
   -            HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
   -            break;
   -        }
   -        case HAL_BSP_POWER_SLEEP: {
   -            HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   -            break;
   -        }
   -        case HAL_BSP_POWER_WFI: {
   -            HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   -            break;
   -        }
   -        case HAL_BSP_POWER_ON:
   -        default: {
   -            
   -            break;
   -        }
   -    }
   -
   -#if MYNEWT_VAL(OS_TICKLESS_RTC)
   -    /* exit tickless low power mode */
   -    stm32_tickless_stop(durationMS);
   -#endif
   -
   +/*
   + * Licensed to the Apache Software Foundation (ASF) under one
   + * or more contributor license agreements.  See the NOTICE file
   + * distributed with this work for additional information
   + * regarding copyright ownership.  The ASF licenses this file
   + * to you 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 language governing permissions and limitations
   + * under the License.
   + */
   +
   +#include <string.h>
   +#include <assert.h>
   +#include <os/mynewt.h>
   +#include <syscfg/syscfg.h>
   +#include <mcu/stm32_hal.h>
   +#include <hal/hal_bsp.h>
   +#include "stm32l1xx_hal_pwr.h"
   +#include "stm32l1xx_hal_rtc.h"
   +
   +
   +extern void hal_rtc_enable_wakeup(uint32_t time_ms);
   +extern void hal_rtc_disable_wakeup(void);
   +extern uint32_t hal_rtc_get_remaining_time_before_wakeup(void);
   +extern void hal_rtc_init(RTC_DateTypeDef *date, RTC_TimeTypeDef *time);
   +
   +/* Put MCU  in lowest power stop state, exit only via POR or reset pin */
   +void
   +hal_mcu_halt() {
   +    /* all interupts and exceptions off */
   +    /* PVD off */
   +    /* power watchdog off */
   +    /* Be in lowest power mode forever */
   +    while (1) {
   +/*        HAL_PWR_EnterSTANDBYMode(); */
   +        /* TEST : don't lose RAM so can debug low powerness */
   +        HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
   +        /* debug breakpoint */
   +
   +    }
   +}
   +
   +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);
   +
   +    uint32_t reload_val;
   +
   +    reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
   +
   +    /* Set the system time ticker up */
   +    SysTick->LOAD = reload_val;
   +    SysTick->VAL = 0;
   +    SysTick->CTRL = 0x0007;
   +
   +    /* Set the system tick priority */
   +    NVIC_SetPriority(SysTick_IRQn, prio);
   +
   +    /*
   +     * Keep clocking debug even when CPU is sleeping, stopped or in standby.
   +     */
   +#if !MYNEWT_VAL(MCU_STM32F0)
   +    DBGMCU->CR |= (DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   +#else
   +    DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   +#endif
   +
   +#if MYNEWT_VAL(OS_TICKLESS_RTC)
   +    /* initialise RTC for tickless code if required */
   +    hal_rtc_init(NULL, NULL);
   +#endif
   +
   +}
   +void
   +stm32_tickless_start(uint32_t timeMS) {
   +    /* Start RTC alarm for in this amount of time */
   +    hal_rtc_enable_wakeup(timeMS);
   +    /* Stop SYSTICK */
   +    NVIC_DisableIRQ(SysTick_IRQn);
   +    /*HAL_SuspendTick(); */
   +}
   +
   +void
   +stm32_tickless_stop(uint32_t timeMS) {
   +    /* disable RTC */
   +    hal_rtc_disable_wakeup();
   +
   +    /* reenable systick */
   +    NVIC_EnableIRQ(SysTick_IRQn);
   +    /*HAL_ResumeTick(); */
   +
   +    /* add asleep duration to tick counter : how long we should have slept for minus any remaining time */
   +    int asleep_ticks = os_time_ms_to_ticks32(timeMS - hal_rtc_get_remaining_time_before_wakeup());
   +    assert(asleep_ticks >= 0);
   +    os_time_advance(asleep_ticks);
   +}
   +
   +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) {
   +        HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   +        return;
   +    }
   +    /* begin tickless */
   +#if MYNEWT_VAL(OS_TICKLESS_RTC)
   +    stm32_tickless_start(durationMS);
   +#endif
   +
   +    switch (power_mode) {
   +    case HAL_BSP_POWER_OFF: {
   +        HAL_PWR_EnterSTANDBYMode();
   +        break;
   +    }
   +    case HAL_BSP_POWER_DEEP_SLEEP: {
   +        HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
   +        break;
   +    }
   +    case HAL_BSP_POWER_SLEEP: {
   +        HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   +        break;
   +    }
   +    case HAL_BSP_POWER_WFI: {
   +        HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   +        break;
   +    }
   +    case HAL_BSP_POWER_ON:
   +    default: {
   +
   +        break;
   +    }
   +    }
   +
   +#if MYNEWT_VAL(OS_TICKLESS_RTC)
   +    /* exit tickless low power mode */
   +    stm32_tickless_stop(durationMS);
   +#endif
   +
    }
   \ No newline at end of file
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32l1xx/src/rtc_utils.c
   <details>
   
   ```diff
   @@ -1,340 +1,341 @@
   -/**
   - * 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. 
   - * 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 
   - * language governing permissions and limitations under the License.
   -*/
   -
   -/**
   - * Hal for rtc management
   - */
   -
   -#include <assert.h>
   -#include "os/mynewt.h"
   -
   -#include "hal/hal_gpio.h"
   -#include "stm32l1xx_hal_rtc.h"
   -#include "stm32l1xx_hal_pwr.h"
   -#include "bsp.h"
   -
   -// sub-second number of bits
   -#define N_PREDIV_S                                  10
   -
   -// Synchronous prediv
   -#define PREDIV_S                                    ( ( 1 << N_PREDIV_S ) - 1 )
   -
   -// Asynchronous prediv
   -#define PREDIV_A                                    ( 1 << ( 15 - N_PREDIV_S ) ) - 1
   -
   -// Sub-second mask definition
   -#define ALARM_SUBSECOND_MASK                        ( N_PREDIV_S << RTC_ALRMASSR_MASKSS_Pos )
   -
   -// RTC Time base in us
   -#define USEC_NUMBER                                 1000000
   -#define MSEC_NUMBER                                 ( USEC_NUMBER / 1000 )
   -
   -#define COMMON_FACTOR                               3
   -#define CONV_NUMER                                  ( MSEC_NUMBER >> COMMON_FACTOR )
   -#define CONV_DENOM                                  ( 1 << ( N_PREDIV_S - COMMON_FACTOR ) )
   -
   -
   -/*!
   - * \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 )
   -
   -/*!
   - * \brief Correction factors
   - */
   -#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 RTC_CLOCK_PRESCALER                         16.0f
   -#define DIVIDED_RTC_FREQUENCY                       (((float)LSE_VALUE)/RTC_CLOCK_PRESCALER)
   -#define DIVIDED_RTC_PERIOD                          (1.0f/DIVIDED_RTC_FREQUENCY)
   -#define MIN_RTC_PERIOD_SEC                          (1.0f*DIVIDED_RTC_PERIOD)
   -#define MAX_RTC_PERIOD_SEC                          (65535.0f*DIVIDED_RTC_PERIOD)
   -#define MIN_RTC_PERIOD_MSEC                         (1000.0f*MIN_RTC_PERIOD_SEC)
   -#define MAX_RTC_PERIOD_MSEC                         (1000.0f*MAX_RTC_PERIOD_SEC)
   -
   -/*!
   - * 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 = 
   -{
   -    .Instance = NULL,
   -    .Init = 
   -    { 
   -        .HourFormat = 0,
   -        .AsynchPrediv = 0,
   -        .SynchPrediv = 0,
   -        .OutPut = 0,
   -        .OutPutPolarity = 0,
   -        .OutPutType = 0
   -    },
   -    .Lock = HAL_UNLOCKED,
   -    .State = HAL_RTC_STATE_RESET
   -};
   -
   -
   -/**
   -  * @brief  This function handles  WAKE UP TIMER  interrupt request.
   -  * @retval None
   -  */
   -void RTC_WKUP_IRQHandler(void)
   -{
   -  HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
   -}
   -
   -/**
   -  * @brief  Wake Up Timer callback.
   -  * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   -  *                the configuration information for RTC.
   -  * @retval None
   -  */
   -void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
   -{
   -
   -}
   -
   -#ifdef RTC_ALARM_TEST
   -static RTC_AlarmTypeDef RtcAlarm;
   -#endif
   -
   -/**
   -  * @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)
   -{
   -    int rc;
   -
   -    NVIC_DisableIRQ(RTC_Alarm_IRQn);
   -    NVIC_DisableIRQ(RTC_WKUP_IRQn);
   -
   -
   -    RtcHandle.Instance            = RTC;
   -    RtcHandle.Init.HourFormat     = RTC_HOURFORMAT_24;
   -    RtcHandle.Init.AsynchPrediv   = PREDIV_A;  // RTC_ASYNCH_PREDIV;
   -    RtcHandle.Init.SynchPrediv    = PREDIV_S;  // RTC_SYNCH_PREDIV;
   -    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);
   -
   -    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,
   -        };
   -        
   -        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_EnableBypassShadow( &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);
   -    NVIC_EnableIRQ(RTC_Alarm_IRQn);
   -
   -    rc = HAL_RTC_SetAlarm_IT(&RtcHandle, &RtcAlarm, FORMAT_BIN);
   -#endif
   -
   -    HAL_RTC_DeactivateAlarm( &RtcHandle, RTC_ALARM_A );
   -    HAL_RTC_DeactivateAlarm( &RtcHandle, RTC_ALARM_B );
   -    HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
   -    
   -    assert(rc == 0);
   -}
   -
   -static uint32_t clk_srce_sel;
   -static uint16_t wkup_autoreload_timer;
   -
   -void hal_rtc_enable_wakeup(uint32_t time_ms)
   -{    
   -    /* Enable and set RTC_WKUP_IRQ */
   -
   -    //this NVIC setup doesn't work .... 
   -    //TODO : find out why ...
   -    //HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   -    //HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -    //HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   -
   -    
   -    NVIC_DisableIRQ(RTC_WKUP_IRQn);
   -
   -    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
   -
   -    /*
   -    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) )
   -    {
   -        clk_srce_sel = RTC_WAKEUPCLOCK_RTCCLK_DIV16;
   -        wkup_autoreload_timer = (uint32_t)((float)time_ms / (MIN_RTC_PERIOD_MSEC));
   -    }
   -    else if(time_ms < (uint32_t)(18 * 60 * 60 * 1000) )
   -    {   
   -        clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
   -        wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else if(time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)) )
   -    {   
   -        clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   -        wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else{
   -        /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -        */
   -       clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   -       /* 
   -       for now, set the maximum possible time
   -       */
   -       wkup_autoreload_timer = 0xFFFF;
   -
   -    }
   -
   -    HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, (uint32_t)wkup_autoreload_timer, clk_srce_sel);
   -
   -    //NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   -    //NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   -    //NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -
   -}
   -
   -uint32_t hal_rtc_get_remaining_time_before_wakeup(void)
   -{
   -    uint32_t time_ms, elapsed_time = HAL_RTCEx_GetWakeUpTimer(&RtcHandle);
   -
   -    if(clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16)
   -    {
   -        time_ms = (uint32_t)(((float)elapsed_time) * (MIN_RTC_PERIOD_MSEC));
   -    }
   -    else //if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS )
   -    {   
   -        time_ms = (elapsed_time * 1000);
   -    }
   -    /*
   -    else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   -    {   
   -        time_ms = (elapsed_time * 1000);
   -    }
   -    */
   -    /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -       
   -    else{
   -        time_ms = (elapsed_time * 1000) + (36 * 60 * 60 * 1000);
   -
   -    }
   -    */
   -    
   -
   -    return time_ms;
   -}
   -
   -void hal_rtc_disable_wakeup(void)
   -{
   -    HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
   -    NVIC_DisableIRQ(RTC_WKUP_IRQn);
   -}
   +/**
   + * 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.
   + * 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
   + * language governing permissions and limitations under the License.
   + */
   +
   +/**
   + * Hal for rtc management
   + */
   +
   +#include <assert.h>
   +#include "os/mynewt.h"
   +
   +#include "hal/hal_gpio.h"
   +#include "stm32l1xx_hal_rtc.h"
   +#include "stm32l1xx_hal_pwr.h"
   +#include "bsp.h"
   +
   +/* sub-second number of bits */
   +#define N_PREDIV_S                                  10
   +
   +/* Synchronous prediv */
   +#define PREDIV_S                                    ((1 << N_PREDIV_S) - 1)
   +
   +/* Asynchronous prediv */
   +#define PREDIV_A                                    (1 << (15 - N_PREDIV_S)) - 1
   +
   +/* Sub-second mask definition */
   +#define ALARM_SUBSECOND_MASK                        (N_PREDIV_S << RTC_ALRMASSR_MASKSS_Pos)
   +
   +/* RTC Time base in us */
   +#define USEC_NUMBER                                 1000000
   +#define MSEC_NUMBER                                 (USEC_NUMBER / 1000)
   +
   +#define COMMON_FACTOR                               3
   +#define CONV_NUMER                                  (MSEC_NUMBER >> COMMON_FACTOR)
   +#define CONV_DENOM                                  (1 << (N_PREDIV_S - COMMON_FACTOR))
   +
   +
   +/*!
   + * \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)
   +
   +/*!
   + * \brief Correction factors
   + */
   +#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 RTC_CLOCK_PRESCALER                         16.0f
   +#define DIVIDED_RTC_FREQUENCY                       (((float)LSE_VALUE) / RTC_CLOCK_PRESCALER)
   +#define DIVIDED_RTC_PERIOD                          (1.0f / DIVIDED_RTC_FREQUENCY)
   +#define MIN_RTC_PERIOD_SEC                          (1.0f * DIVIDED_RTC_PERIOD)
   +#define MAX_RTC_PERIOD_SEC                          (65535.0f * DIVIDED_RTC_PERIOD)
   +#define MIN_RTC_PERIOD_MSEC                         (1000.0f * MIN_RTC_PERIOD_SEC)
   +#define MAX_RTC_PERIOD_MSEC                         (1000.0f * MAX_RTC_PERIOD_SEC)
   +
   +/*!
   + * 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 = {
   +    .Instance = NULL,
   +    .Init = {
   +        .HourFormat = 0,
   +        .AsynchPrediv = 0,
   +        .SynchPrediv = 0,
   +        .OutPut = 0,
   +        .OutPutPolarity = 0,
   +        .OutPutType = 0
   +    },
   +    .Lock = HAL_UNLOCKED,
   +    .State = HAL_RTC_STATE_RESET
   +};
   +
   +
   +/**
   + * @brief  This function handles  WAKE UP TIMER  interrupt request.
   + * @retval None
   + */
   +void
   +RTC_WKUP_IRQHandler(void)
   +{
   +    HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
   +}
   +
   +/**
   + * @brief  Wake Up Timer callback.
   + * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   + *                the configuration information for RTC.
   + * @retval None
   + */
   +void
   +HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
   +{
   +
   +}
   +
   +#ifdef RTC_ALARM_TEST
   +static RTC_AlarmTypeDef RtcAlarm;
   +#endif
   +
   +/**
   + * @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)
   +{
   +    int rc;
   +
   +    NVIC_DisableIRQ(RTC_Alarm_IRQn);
   +    NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +
   +
   +    RtcHandle.Instance            = RTC;
   +    RtcHandle.Init.HourFormat     = RTC_HOURFORMAT_24;
   +    RtcHandle.Init.AsynchPrediv   = PREDIV_A;  /* RTC_ASYNCH_PREDIV; */
   +    RtcHandle.Init.SynchPrediv    = PREDIV_S;  /* RTC_SYNCH_PREDIV; */
   +    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);
   +
   +    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,
   +        };
   +
   +        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_EnableBypassShadow( &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);
   +    NVIC_EnableIRQ(RTC_Alarm_IRQn);
   +
   +    rc = HAL_RTC_SetAlarm_IT(&RtcHandle, &RtcAlarm, FORMAT_BIN);
   +#endif
   +
   +    HAL_RTC_DeactivateAlarm( &RtcHandle, RTC_ALARM_A );
   +    HAL_RTC_DeactivateAlarm( &RtcHandle, RTC_ALARM_B );
   +    HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
   +
   +    assert(rc == 0);
   +}
   +
   +static uint32_t clk_srce_sel;
   +static uint16_t wkup_autoreload_timer;
   +
   +void
   +hal_rtc_enable_wakeup(uint32_t time_ms)
   +{
   +    /* Enable and set RTC_WKUP_IRQ */
   +
   +    /*
   +       this NVIC setup doesn't work ....
   +       TODO : find out why ...
   +       HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   +       HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +       HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +     */
   +
   +
   +    NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +
   +    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
   +
   +    /*
   +       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)) {
   +        clk_srce_sel = RTC_WAKEUPCLOCK_RTCCLK_DIV16;
   +        wkup_autoreload_timer = (uint32_t)((float)time_ms / (MIN_RTC_PERIOD_MSEC));
   +    } else if (time_ms < (uint32_t)(18 * 60 * 60 * 1000))   {
   +        clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
   +        wkup_autoreload_timer = (time_ms / 1000);
   +    } else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))   {
   +        clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   +        wkup_autoreload_timer = (time_ms / 1000);
   +    } else   {
   +        /*
   +           TODO : setup wakeup with ALARM feature istead of wakeup
   +         */
   +        clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   +        /*
   +           for now, set the maximum possible time
   +         */
   +        wkup_autoreload_timer = 0xFFFF;
   +
   +    }
   +
   +    HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, (uint32_t)wkup_autoreload_timer, clk_srce_sel);
   +
   +    /*
   +       NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   +       NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   +       NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +     */
   +
   +}
   +
   +uint32_t
   +hal_rtc_get_remaining_time_before_wakeup(void)
   +{
   +    uint32_t time_ms, elapsed_time = HAL_RTCEx_GetWakeUpTimer(&RtcHandle);
   +
   +    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16) {
   +        time_ms = (uint32_t)(((float)elapsed_time) * (MIN_RTC_PERIOD_MSEC));
   +    } else   { /*if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS ) */
   +        time_ms = (elapsed_time * 1000);
   +    }
   +    /*
   +       else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   +       {
   +        time_ms = (elapsed_time * 1000);
   +       }
   +     */
   +    /*
   +        TODO : setup wakeup with ALARM feature istead of wakeup
   +
   +       else{
   +        time_ms = (elapsed_time * 1000) + (36 * 60 * 60 * 1000);
   +
   +       }
   +     */
   +
   +
   +    return time_ms;
   +}
   +
   +void
   +hal_rtc_disable_wakeup(void)
   +{
   +    HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
   +    NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +}
   ```
   
   </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

[GitHub] [mynewt-core] apache-mynewt-bot commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-579253297
 
 
   
   <!-- style-bot -->
   
   ## Style check summary
   
   #### hw/mcu/stm/stm32l1xx/src/hal_power_mgnt.c
   <details>
   
   ```diff
   @@ -32,22 +32,25 @@
    extern void hal_rtc_init(RTC_DateTypeDef *date, RTC_TimeTypeDef *time);
    
    /* 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 */
        /* power watchdog off */
        /* Be in lowest power mode forever */
   -    while (1)
   -    {
   -        //        HAL_PWR_EnterSTANDBYMode();
   -        // TEST : don't lose RAM so can debug low powerness
   +    while (1) {
   +        /*
   +                  HAL_PWR_EnterSTANDBYMode();
   +           TEST : don't lose RAM so can debug low powerness
   +         */
            HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
            /* debug breakpoint */
        }
    }
    
   -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 */
   @@ -79,23 +82,25 @@
        hal_rtc_init(NULL, NULL);
    #endif
    }
   -void stm32_tickless_start(uint32_t timeMS)
   +void
   +stm32_tickless_start(uint32_t timeMS)
    {
        /* Start RTC alarm for in this amount of time */
        hal_rtc_enable_wakeup(timeMS);
        /* Stop SYSTICK */
        NVIC_DisableIRQ(SysTick_IRQn);
   -    //HAL_SuspendTick();
   +    /*HAL_SuspendTick(); */
    }
    
   -void stm32_tickless_stop(uint32_t timeMS)
   +void
   +stm32_tickless_stop(uint32_t timeMS)
    {
        /* disable RTC */
        hal_rtc_disable_wakeup();
    
        /* reenable systick */
        NVIC_EnableIRQ(SysTick_IRQn);
   -    //HAL_ResumeTick();
   +    /*HAL_ResumeTick(); */
    
        /* add asleep duration to tick counter : how long we should have slept for minus any remaining time */
        int asleep_ticks = os_time_ms_to_ticks32(timeMS - hal_rtc_get_remaining_time_before_wakeup());
   @@ -103,11 +108,11 @@
        os_time_advance(asleep_ticks);
    }
    
   -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;
        }
   @@ -116,8 +121,7 @@
        stm32_tickless_start(durationMS);
    #endif
    
   -    switch (power_mode)
   -    {
   +    switch (power_mode) {
        case HAL_BSP_POWER_OFF:
        {
            HAL_PWR_EnterSTANDBYMode();
   ```
   
   </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.
   -*/
   + */
    
    /**
     * Hal for rtc management
   @@ -23,19 +23,19 @@
    #include "stm32l1xx_hal_pwr.h"
    #include "bsp.h"
    
   -// sub-second number of bits
   +/* sub-second number of bits */
    #define N_PREDIV_S 10
    
   -// Synchronous prediv
   +/* Synchronous prediv */
    #define PREDIV_S ((1 << N_PREDIV_S) - 1)
    
   -// Asynchronous prediv
   +/* Asynchronous prediv */
    #define PREDIV_A (1 << (15 - N_PREDIV_S)) - 1
    
   -// Sub-second mask definition
   +/* Sub-second mask definition */
    #define ALARM_SUBSECOND_MASK (N_PREDIV_S << RTC_ALRMASSR_MASKSS_Pos)
    
   -// RTC Time base in us
   +/* RTC Time base in us */
    #define USEC_NUMBER 1000000
    #define MSEC_NUMBER (USEC_NUMBER / 1000)
    
   @@ -74,48 +74,49 @@
    #define MAX_RTC_PERIOD_MSEC (1000.0f * MAX_RTC_PERIOD_SEC)
    
    /*!
   - * 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
   + * 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 =
   -    {
   -        .Instance = NULL,
   -        .Init =
   -            {
   -                .HourFormat = 0,
   -                .AsynchPrediv = 0,
   -                .SynchPrediv = 0,
   -                .OutPut = 0,
   -                .OutPutPolarity = 0,
   -                .OutPutType = 0},
   -        .Lock = HAL_UNLOCKED,
   -        .State = HAL_RTC_STATE_RESET};
   -
   -/**
   -  * @brief  This function handles  WAKE UP TIMER  interrupt request.
   -  * @retval None
   -  */
   -void RTC_WKUP_IRQHandler(void)
   +static RTC_HandleTypeDef RtcHandle = {
   +    .Instance = NULL,
   +    .Init = {
   +        .HourFormat = 0,
   +        .AsynchPrediv = 0,
   +        .SynchPrediv = 0,
   +        .OutPut = 0,
   +        .OutPutPolarity = 0,
   +        .OutPutType = 0
   +    },
   +    .Lock = HAL_UNLOCKED,
   +    .State = HAL_RTC_STATE_RESET
   +};
   +
   +/**
   + * @brief  This function handles  WAKE UP TIMER  interrupt request.
   + * @retval None
   + */
   +void
   +RTC_WKUP_IRQHandler(void)
    {
        HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
    }
    
    /**
   -  * @brief  Wake Up Timer callback.
   -  * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   -  *                the configuration information for RTC.
   -  * @retval None
   -  */
   -void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
   + * @brief  Wake Up Timer callback.
   + * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   + *                the configuration information for RTC.
   + * @retval None
   + */
   +void
   +HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
    {
    }
    
   @@ -124,25 +125,28 @@
    #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;
    
   @@ -151,8 +155,8 @@
    
        RtcHandle.Instance = RTC;
        RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
   -    RtcHandle.Init.AsynchPrediv = PREDIV_A; // RTC_ASYNCH_PREDIV;
   -    RtcHandle.Init.SynchPrediv = PREDIV_S;  // RTC_SYNCH_PREDIV;
   +    RtcHandle.Init.AsynchPrediv = PREDIV_A; /* RTC_ASYNCH_PREDIV; */
   +    RtcHandle.Init.SynchPrediv = PREDIV_S;  /* RTC_SYNCH_PREDIV; */
        RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
        RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
        RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
   @@ -160,33 +164,29 @@
    
        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;
        }
   @@ -194,11 +194,13 @@
        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_EnableBypassShadow( &RtcHandle );
   +    /*
   +       Enable Direct Read of the calendar registers (not through Shadow registers)
   +       HAL_RTCEx_EnableBypassShadow( &RtcHandle );
   +     */
    
    #ifdef RTC_ALARM_TEST
   -    //setup alarm
   +    /*setup alarm */
        RtcAlarm.AlarmTime.Hours = 0;
        RtcAlarm.AlarmTime.Minutes = 0;
        RtcAlarm.AlarmTime.Seconds = 1;
   @@ -229,98 +231,95 @@
    static uint32_t clk_srce_sel;
    static uint16_t wkup_autoreload_timer;
    
   -void hal_rtc_enable_wakeup(uint32_t time_ms)
   +void
   +hal_rtc_enable_wakeup(uint32_t time_ms)
    {
        /* Enable and set RTC_WKUP_IRQ */
    
   -    //this NVIC setup doesn't work ....
   -    //TODO : find out why ...
   -    //HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   -    //HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -    //HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +    /*
   +       this NVIC setup doesn't work ....
   +       TODO : find out why ...
   +       HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   +       HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +       HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +     */
    
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
    
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
    
        /*
   -    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)) {
            clk_srce_sel = RTC_WAKEUPCLOCK_RTCCLK_DIV16;
            wkup_autoreload_timer = (uint32_t)((float)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))   {
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
            wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))
   -    {
   +    } else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))   {
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
            wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else
   -    {
   +    } else   {
            /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -        */
   +           TODO : setup wakeup with ALARM feature istead of wakeup
   +         */
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   -        /* 
   -       for now, set the maximum possible time
   -       */
   +        /*
   +           for now, set the maximum possible time
   +         */
            wkup_autoreload_timer = 0xFFFF;
        }
    
        HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, (uint32_t)wkup_autoreload_timer, clk_srce_sel);
    
   -    //NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   -    //NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   -    //NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -}
   -
   -uint32_t hal_rtc_get_remaining_time_before_wakeup(void)
   +    /*
   +       NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   +       NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   +       NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +     */
   +}
   +
   +uint32_t
   +hal_rtc_get_remaining_time_before_wakeup(void)
    {
        uint32_t time_ms, elapsed_time = HAL_RTCEx_GetWakeUpTimer(&RtcHandle);
    
   -    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16)
   -    {
   +    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16) {
            time_ms = (uint32_t)(((float)elapsed_time) * (MIN_RTC_PERIOD_MSEC));
   -    }
   -    else //if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS )
   -    {
   +    } else   { /*if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS ) */
            time_ms = (elapsed_time * 1000);
        }
        /*
   -    else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   -    {   
   +       else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   +       {
            time_ms = (elapsed_time * 1000);
   -    }
   -    */
   -    /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -       
   -    else{
   +       }
   +     */
   +    /*
   +        TODO : setup wakeup with ALARM feature istead of wakeup
   +
   +       else{
            time_ms = (elapsed_time * 1000) + (36 * 60 * 60 * 1000);
    
   -    }
   -    */
   +       }
   +     */
    
        return time_ms;
    }
    
   -void hal_rtc_disable_wakeup(void)
   +void
   +hal_rtc_disable_wakeup(void)
    {
        HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32_common/src/hal_os_tick.c
   <details>
   
   ```diff
   @@ -39,10 +39,11 @@
    #if defined(STM32F405xx) || defined(STM32F407xx) || \
        defined(STM32F415xx) || defined(STM32F417xx)
    #undef __WFI
   -__attribute__((aligned(8), naked)) void static __WFI(void)
   +__attribute__((aligned(8), naked)) void static
   +__WFI(void)
    {
   -    __ASM volatile("wfi\n"
   -                   "bx lr");
   +    __ASM volatile ("wfi\n"
   +                    "bx lr");
    }
    #endif
    
   @@ -51,7 +52,8 @@
    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);
   @@ -77,18 +79,21 @@
        DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
    #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
    
   -void os_tick_idle(os_time_t ticks)
   +void
   +os_tick_idle(os_time_t ticks)
    {
        /* default mode will enter in WFI */
        int power_mode = HAL_BSP_POWER_WFI;
   @@ -96,8 +101,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;
   @@ -124,7 +128,8 @@
    #endif
    }
    
   -void os_tick_init(uint32_t os_ticks_per_sec, int prio)
   +void
   +os_tick_init(uint32_t os_ticks_per_sec, int prio)
    {
        stm32_tick_init(os_ticks_per_sec, prio);
    }
   ```
   
   </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

[GitHub] [mynewt-core] andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-573073522
 
 
   @brianwyld that's why I suggested it should be configured by either MCU or BSP. OS code can e.g. include some file from BSP where proper definitions can be expected. I did not look through the code to see what is the best way to do this now, perhaps we need to add something.

----------------------------------------------------------------
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

[GitHub] [mynewt-core] utzig commented on a change in pull request #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
utzig commented on a change in pull request #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#discussion_r363753755
 
 

 ##########
 File path: hw/mcu/stm/stm32_common/src/hal_os_tick.c
 ##########
 @@ -1,78 +1,135 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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 language governing permissions and limitations
- * under the License.
- */
-
-#include <assert.h>
-#include "os/mynewt.h"
-#include <hal/hal_os_tick.h>
-
-/*
- * XXX implement tickless mode.
- */
-
-/*
- * Errata for STM32F405, STM32F407, STM32F415, STM32F417.
- * When WFI instruction is placed at address like 0x080xxxx4
- * (also seen for addresses ending with xxx2). System may
- * crash.
- * __WFI function places WFI instruction at address ending with x0 or x8
- * for affected MCUs.
- */
-#if defined(STM32F405xx) || defined(STM32F407xx) || \
-    defined(STM32F415xx) || defined(STM32F417xx)
-#undef __WFI
-__attribute__((aligned(8), naked)) void static
-__WFI(void)
-{
-     __ASM volatile("wfi\n"
-                    "bx lr");
-}
-#endif
-
-void
-os_tick_idle(os_time_t ticks)
-{
-    OS_ASSERT_CRITICAL();
-    __DSB();
-    __WFI();
-}
-
-void
-os_tick_init(uint32_t os_ticks_per_sec, int prio)
-{
-    uint32_t reload_val;
-
-    reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
-
-    /* Set the system time ticker up */
-    SysTick->LOAD = reload_val;
-    SysTick->VAL = 0;
-    SysTick->CTRL = 0x0007;
-
-    /* Set the system tick priority */
-    NVIC_SetPriority(SysTick_IRQn, prio);
-
-    /*
-     * Keep clocking debug even when CPU is sleeping, stopped or in standby.
-     */
-#if !MYNEWT_VAL(MCU_STM32F0)
-    DBGMCU->CR |= (DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
-#else
-    DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
-#endif
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include "os/mynewt.h"
+#include <hal/hal_os_tick.h>
+#include <hal/hal_bsp.h>
+#include "bsp/bsp.h"
+#include "system_stm32l1xx.h"
 
 Review comment:
   This file is shared by all STM32 ports so adding STM32L1x specific includes here is not OK. Also please fix your file save format because it is probably using `\r\n` for line endings (based on the diff).

----------------------------------------------------------------
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

[GitHub] [mynewt-core] brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-568291728
 
 
   Ok, but I don't see how mynewt prevents an ISR happening during the idle task (and hence on its stack)?
   Mostly required to change it because on my STM32L151 (cortex-m3) I had stack overflow on the idle task (as checked by the mynewt stack overflow check) and the debugger showed my as being in the idle task with a stack containing ISR handlers? 
   Also, I see the idle task stack size is already different depending if you include SYSVIEW functionality... so it already needs tuning depending on syscfg...
   Is there an issue making it configurable?

----------------------------------------------------------------
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

[GitHub] [mynewt-core] apache-mynewt-bot removed a comment on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-579253297
 
 
   
   <!-- style-bot -->
   
   ## Style check summary
   
   #### hw/mcu/stm/stm32l1xx/src/hal_power_mgnt.c
   <details>
   
   ```diff
   @@ -32,22 +32,25 @@
    extern void hal_rtc_init(RTC_DateTypeDef *date, RTC_TimeTypeDef *time);
    
    /* 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 */
        /* power watchdog off */
        /* Be in lowest power mode forever */
   -    while (1)
   -    {
   -        //        HAL_PWR_EnterSTANDBYMode();
   -        // TEST : don't lose RAM so can debug low powerness
   +    while (1) {
   +        /*
   +                  HAL_PWR_EnterSTANDBYMode();
   +           TEST : don't lose RAM so can debug low powerness
   +         */
            HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
            /* debug breakpoint */
        }
    }
    
   -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 */
   @@ -79,23 +82,25 @@
        hal_rtc_init(NULL, NULL);
    #endif
    }
   -void stm32_tickless_start(uint32_t timeMS)
   +void
   +stm32_tickless_start(uint32_t timeMS)
    {
        /* Start RTC alarm for in this amount of time */
        hal_rtc_enable_wakeup(timeMS);
        /* Stop SYSTICK */
        NVIC_DisableIRQ(SysTick_IRQn);
   -    //HAL_SuspendTick();
   +    /*HAL_SuspendTick(); */
    }
    
   -void stm32_tickless_stop(uint32_t timeMS)
   +void
   +stm32_tickless_stop(uint32_t timeMS)
    {
        /* disable RTC */
        hal_rtc_disable_wakeup();
    
        /* reenable systick */
        NVIC_EnableIRQ(SysTick_IRQn);
   -    //HAL_ResumeTick();
   +    /*HAL_ResumeTick(); */
    
        /* add asleep duration to tick counter : how long we should have slept for minus any remaining time */
        int asleep_ticks = os_time_ms_to_ticks32(timeMS - hal_rtc_get_remaining_time_before_wakeup());
   @@ -103,11 +108,11 @@
        os_time_advance(asleep_ticks);
    }
    
   -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;
        }
   @@ -116,8 +121,7 @@
        stm32_tickless_start(durationMS);
    #endif
    
   -    switch (power_mode)
   -    {
   +    switch (power_mode) {
        case HAL_BSP_POWER_OFF:
        {
            HAL_PWR_EnterSTANDBYMode();
   ```
   
   </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.
   -*/
   + */
    
    /**
     * Hal for rtc management
   @@ -23,19 +23,19 @@
    #include "stm32l1xx_hal_pwr.h"
    #include "bsp.h"
    
   -// sub-second number of bits
   +/* sub-second number of bits */
    #define N_PREDIV_S 10
    
   -// Synchronous prediv
   +/* Synchronous prediv */
    #define PREDIV_S ((1 << N_PREDIV_S) - 1)
    
   -// Asynchronous prediv
   +/* Asynchronous prediv */
    #define PREDIV_A (1 << (15 - N_PREDIV_S)) - 1
    
   -// Sub-second mask definition
   +/* Sub-second mask definition */
    #define ALARM_SUBSECOND_MASK (N_PREDIV_S << RTC_ALRMASSR_MASKSS_Pos)
    
   -// RTC Time base in us
   +/* RTC Time base in us */
    #define USEC_NUMBER 1000000
    #define MSEC_NUMBER (USEC_NUMBER / 1000)
    
   @@ -74,48 +74,49 @@
    #define MAX_RTC_PERIOD_MSEC (1000.0f * MAX_RTC_PERIOD_SEC)
    
    /*!
   - * 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
   + * 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 =
   -    {
   -        .Instance = NULL,
   -        .Init =
   -            {
   -                .HourFormat = 0,
   -                .AsynchPrediv = 0,
   -                .SynchPrediv = 0,
   -                .OutPut = 0,
   -                .OutPutPolarity = 0,
   -                .OutPutType = 0},
   -        .Lock = HAL_UNLOCKED,
   -        .State = HAL_RTC_STATE_RESET};
   -
   -/**
   -  * @brief  This function handles  WAKE UP TIMER  interrupt request.
   -  * @retval None
   -  */
   -void RTC_WKUP_IRQHandler(void)
   +static RTC_HandleTypeDef RtcHandle = {
   +    .Instance = NULL,
   +    .Init = {
   +        .HourFormat = 0,
   +        .AsynchPrediv = 0,
   +        .SynchPrediv = 0,
   +        .OutPut = 0,
   +        .OutPutPolarity = 0,
   +        .OutPutType = 0
   +    },
   +    .Lock = HAL_UNLOCKED,
   +    .State = HAL_RTC_STATE_RESET
   +};
   +
   +/**
   + * @brief  This function handles  WAKE UP TIMER  interrupt request.
   + * @retval None
   + */
   +void
   +RTC_WKUP_IRQHandler(void)
    {
        HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
    }
    
    /**
   -  * @brief  Wake Up Timer callback.
   -  * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   -  *                the configuration information for RTC.
   -  * @retval None
   -  */
   -void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
   + * @brief  Wake Up Timer callback.
   + * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   + *                the configuration information for RTC.
   + * @retval None
   + */
   +void
   +HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
    {
    }
    
   @@ -124,25 +125,28 @@
    #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;
    
   @@ -151,8 +155,8 @@
    
        RtcHandle.Instance = RTC;
        RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
   -    RtcHandle.Init.AsynchPrediv = PREDIV_A; // RTC_ASYNCH_PREDIV;
   -    RtcHandle.Init.SynchPrediv = PREDIV_S;  // RTC_SYNCH_PREDIV;
   +    RtcHandle.Init.AsynchPrediv = PREDIV_A; /* RTC_ASYNCH_PREDIV; */
   +    RtcHandle.Init.SynchPrediv = PREDIV_S;  /* RTC_SYNCH_PREDIV; */
        RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
        RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
        RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
   @@ -160,33 +164,29 @@
    
        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;
        }
   @@ -194,11 +194,13 @@
        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_EnableBypassShadow( &RtcHandle );
   +    /*
   +       Enable Direct Read of the calendar registers (not through Shadow registers)
   +       HAL_RTCEx_EnableBypassShadow( &RtcHandle );
   +     */
    
    #ifdef RTC_ALARM_TEST
   -    //setup alarm
   +    /*setup alarm */
        RtcAlarm.AlarmTime.Hours = 0;
        RtcAlarm.AlarmTime.Minutes = 0;
        RtcAlarm.AlarmTime.Seconds = 1;
   @@ -229,98 +231,95 @@
    static uint32_t clk_srce_sel;
    static uint16_t wkup_autoreload_timer;
    
   -void hal_rtc_enable_wakeup(uint32_t time_ms)
   +void
   +hal_rtc_enable_wakeup(uint32_t time_ms)
    {
        /* Enable and set RTC_WKUP_IRQ */
    
   -    //this NVIC setup doesn't work ....
   -    //TODO : find out why ...
   -    //HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   -    //HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -    //HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +    /*
   +       this NVIC setup doesn't work ....
   +       TODO : find out why ...
   +       HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   +       HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +       HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +     */
    
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
    
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
    
        /*
   -    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)) {
            clk_srce_sel = RTC_WAKEUPCLOCK_RTCCLK_DIV16;
            wkup_autoreload_timer = (uint32_t)((float)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))   {
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
            wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))
   -    {
   +    } else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))   {
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
            wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else
   -    {
   +    } else   {
            /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -        */
   +           TODO : setup wakeup with ALARM feature istead of wakeup
   +         */
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   -        /* 
   -       for now, set the maximum possible time
   -       */
   +        /*
   +           for now, set the maximum possible time
   +         */
            wkup_autoreload_timer = 0xFFFF;
        }
    
        HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, (uint32_t)wkup_autoreload_timer, clk_srce_sel);
    
   -    //NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   -    //NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   -    //NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -}
   -
   -uint32_t hal_rtc_get_remaining_time_before_wakeup(void)
   +    /*
   +       NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   +       NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   +       NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +     */
   +}
   +
   +uint32_t
   +hal_rtc_get_remaining_time_before_wakeup(void)
    {
        uint32_t time_ms, elapsed_time = HAL_RTCEx_GetWakeUpTimer(&RtcHandle);
    
   -    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16)
   -    {
   +    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16) {
            time_ms = (uint32_t)(((float)elapsed_time) * (MIN_RTC_PERIOD_MSEC));
   -    }
   -    else //if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS )
   -    {
   +    } else   { /*if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS ) */
            time_ms = (elapsed_time * 1000);
        }
        /*
   -    else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   -    {   
   +       else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   +       {
            time_ms = (elapsed_time * 1000);
   -    }
   -    */
   -    /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -       
   -    else{
   +       }
   +     */
   +    /*
   +        TODO : setup wakeup with ALARM feature istead of wakeup
   +
   +       else{
            time_ms = (elapsed_time * 1000) + (36 * 60 * 60 * 1000);
    
   -    }
   -    */
   +       }
   +     */
    
        return time_ms;
    }
    
   -void hal_rtc_disable_wakeup(void)
   +void
   +hal_rtc_disable_wakeup(void)
    {
        HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32_common/src/hal_os_tick.c
   <details>
   
   ```diff
   @@ -39,10 +39,11 @@
    #if defined(STM32F405xx) || defined(STM32F407xx) || \
        defined(STM32F415xx) || defined(STM32F417xx)
    #undef __WFI
   -__attribute__((aligned(8), naked)) void static __WFI(void)
   +__attribute__((aligned(8), naked)) void static
   +__WFI(void)
    {
   -    __ASM volatile("wfi\n"
   -                   "bx lr");
   +    __ASM volatile ("wfi\n"
   +                    "bx lr");
    }
    #endif
    
   @@ -51,7 +52,8 @@
    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);
   @@ -77,18 +79,21 @@
        DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
    #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
    
   -void os_tick_idle(os_time_t ticks)
   +void
   +os_tick_idle(os_time_t ticks)
    {
        /* default mode will enter in WFI */
        int power_mode = HAL_BSP_POWER_WFI;
   @@ -96,8 +101,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;
   @@ -124,7 +128,8 @@
    #endif
    }
    
   -void os_tick_init(uint32_t os_ticks_per_sec, int prio)
   +void
   +os_tick_init(uint32_t os_ticks_per_sec, int prio)
    {
        stm32_tick_init(os_ticks_per_sec, prio);
    }
   ```
   
   </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

[GitHub] [mynewt-core] apache-mynewt-bot removed a comment on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-593442659
 
 
   
   <!-- 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

[GitHub] [mynewt-core] apache-mynewt-bot removed a comment on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-578512183
 
 
   
   <!-- style-bot -->
   
   ## Style check summary
   
   #### hw/mcu/stm/stm32l1xx/src/hal_power_mgnt.c
   <details>
   
   ```diff
   @@ -32,22 +32,25 @@
    extern void hal_rtc_init(RTC_DateTypeDef *date, RTC_TimeTypeDef *time);
    
    /* 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 */
        /* power watchdog off */
        /* Be in lowest power mode forever */
   -    while (1)
   -    {
   -        //        HAL_PWR_EnterSTANDBYMode();
   -        // TEST : don't lose RAM so can debug low powerness
   +    while (1) {
   +        /*
   +                  HAL_PWR_EnterSTANDBYMode();
   +           TEST : don't lose RAM so can debug low powerness
   +         */
            HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
            /* debug breakpoint */
        }
    }
    
   -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 */
   @@ -79,23 +82,25 @@
        hal_rtc_init(NULL, NULL);
    #endif
    }
   -void stm32_tickless_start(uint32_t timeMS)
   +void
   +stm32_tickless_start(uint32_t timeMS)
    {
        /* Start RTC alarm for in this amount of time */
        hal_rtc_enable_wakeup(timeMS);
        /* Stop SYSTICK */
        NVIC_DisableIRQ(SysTick_IRQn);
   -    //HAL_SuspendTick();
   +    /*HAL_SuspendTick(); */
    }
    
   -void stm32_tickless_stop(uint32_t timeMS)
   +void
   +stm32_tickless_stop(uint32_t timeMS)
    {
        /* disable RTC */
        hal_rtc_disable_wakeup();
    
        /* reenable systick */
        NVIC_EnableIRQ(SysTick_IRQn);
   -    //HAL_ResumeTick();
   +    /*HAL_ResumeTick(); */
    
        /* add asleep duration to tick counter : how long we should have slept for minus any remaining time */
        int asleep_ticks = os_time_ms_to_ticks32(timeMS - hal_rtc_get_remaining_time_before_wakeup());
   @@ -103,11 +108,11 @@
        os_time_advance(asleep_ticks);
    }
    
   -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;
        }
   @@ -116,8 +121,7 @@
        stm32_tickless_start(durationMS);
    #endif
    
   -    switch (power_mode)
   -    {
   +    switch (power_mode) {
        case HAL_BSP_POWER_OFF:
        {
            HAL_PWR_EnterSTANDBYMode();
   ```
   
   </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.
   -*/
   + */
    
    /**
     * Hal for rtc management
   @@ -23,19 +23,19 @@
    #include "stm32l1xx_hal_pwr.h"
    #include "bsp.h"
    
   -// sub-second number of bits
   +/* sub-second number of bits */
    #define N_PREDIV_S 10
    
   -// Synchronous prediv
   +/* Synchronous prediv */
    #define PREDIV_S ((1 << N_PREDIV_S) - 1)
    
   -// Asynchronous prediv
   +/* Asynchronous prediv */
    #define PREDIV_A (1 << (15 - N_PREDIV_S)) - 1
    
   -// Sub-second mask definition
   +/* Sub-second mask definition */
    #define ALARM_SUBSECOND_MASK (N_PREDIV_S << RTC_ALRMASSR_MASKSS_Pos)
    
   -// RTC Time base in us
   +/* RTC Time base in us */
    #define USEC_NUMBER 1000000
    #define MSEC_NUMBER (USEC_NUMBER / 1000)
    
   @@ -74,48 +74,49 @@
    #define MAX_RTC_PERIOD_MSEC (1000.0f * MAX_RTC_PERIOD_SEC)
    
    /*!
   - * 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
   + * 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 =
   -    {
   -        .Instance = NULL,
   -        .Init =
   -            {
   -                .HourFormat = 0,
   -                .AsynchPrediv = 0,
   -                .SynchPrediv = 0,
   -                .OutPut = 0,
   -                .OutPutPolarity = 0,
   -                .OutPutType = 0},
   -        .Lock = HAL_UNLOCKED,
   -        .State = HAL_RTC_STATE_RESET};
   -
   -/**
   -  * @brief  This function handles  WAKE UP TIMER  interrupt request.
   -  * @retval None
   -  */
   -void RTC_WKUP_IRQHandler(void)
   +static RTC_HandleTypeDef RtcHandle = {
   +    .Instance = NULL,
   +    .Init = {
   +        .HourFormat = 0,
   +        .AsynchPrediv = 0,
   +        .SynchPrediv = 0,
   +        .OutPut = 0,
   +        .OutPutPolarity = 0,
   +        .OutPutType = 0
   +    },
   +    .Lock = HAL_UNLOCKED,
   +    .State = HAL_RTC_STATE_RESET
   +};
   +
   +/**
   + * @brief  This function handles  WAKE UP TIMER  interrupt request.
   + * @retval None
   + */
   +void
   +RTC_WKUP_IRQHandler(void)
    {
        HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
    }
    
    /**
   -  * @brief  Wake Up Timer callback.
   -  * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   -  *                the configuration information for RTC.
   -  * @retval None
   -  */
   -void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
   + * @brief  Wake Up Timer callback.
   + * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   + *                the configuration information for RTC.
   + * @retval None
   + */
   +void
   +HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
    {
    }
    
   @@ -124,25 +125,28 @@
    #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;
    
   @@ -151,8 +155,8 @@
    
        RtcHandle.Instance = RTC;
        RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
   -    RtcHandle.Init.AsynchPrediv = PREDIV_A; // RTC_ASYNCH_PREDIV;
   -    RtcHandle.Init.SynchPrediv = PREDIV_S;  // RTC_SYNCH_PREDIV;
   +    RtcHandle.Init.AsynchPrediv = PREDIV_A; /* RTC_ASYNCH_PREDIV; */
   +    RtcHandle.Init.SynchPrediv = PREDIV_S;  /* RTC_SYNCH_PREDIV; */
        RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
        RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
        RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
   @@ -160,33 +164,29 @@
    
        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;
        }
   @@ -194,11 +194,13 @@
        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_EnableBypassShadow( &RtcHandle );
   +    /*
   +       Enable Direct Read of the calendar registers (not through Shadow registers)
   +       HAL_RTCEx_EnableBypassShadow( &RtcHandle );
   +     */
    
    #ifdef RTC_ALARM_TEST
   -    //setup alarm
   +    /*setup alarm */
        RtcAlarm.AlarmTime.Hours = 0;
        RtcAlarm.AlarmTime.Minutes = 0;
        RtcAlarm.AlarmTime.Seconds = 1;
   @@ -229,98 +231,95 @@
    static uint32_t clk_srce_sel;
    static uint16_t wkup_autoreload_timer;
    
   -void hal_rtc_enable_wakeup(uint32_t time_ms)
   +void
   +hal_rtc_enable_wakeup(uint32_t time_ms)
    {
        /* Enable and set RTC_WKUP_IRQ */
    
   -    //this NVIC setup doesn't work ....
   -    //TODO : find out why ...
   -    //HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   -    //HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -    //HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +    /*
   +       this NVIC setup doesn't work ....
   +       TODO : find out why ...
   +       HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   +       HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +       HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +     */
    
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
    
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
    
        /*
   -    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)) {
            clk_srce_sel = RTC_WAKEUPCLOCK_RTCCLK_DIV16;
            wkup_autoreload_timer = (uint32_t)((float)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))   {
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
            wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))
   -    {
   +    } else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))   {
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
            wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else
   -    {
   +    } else   {
            /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -        */
   +           TODO : setup wakeup with ALARM feature istead of wakeup
   +         */
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   -        /* 
   -       for now, set the maximum possible time
   -       */
   +        /*
   +           for now, set the maximum possible time
   +         */
            wkup_autoreload_timer = 0xFFFF;
        }
    
        HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, (uint32_t)wkup_autoreload_timer, clk_srce_sel);
    
   -    //NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   -    //NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   -    //NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -}
   -
   -uint32_t hal_rtc_get_remaining_time_before_wakeup(void)
   +    /*
   +       NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   +       NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   +       NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +     */
   +}
   +
   +uint32_t
   +hal_rtc_get_remaining_time_before_wakeup(void)
    {
        uint32_t time_ms, elapsed_time = HAL_RTCEx_GetWakeUpTimer(&RtcHandle);
    
   -    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16)
   -    {
   +    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16) {
            time_ms = (uint32_t)(((float)elapsed_time) * (MIN_RTC_PERIOD_MSEC));
   -    }
   -    else //if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS )
   -    {
   +    } else   { /*if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS ) */
            time_ms = (elapsed_time * 1000);
        }
        /*
   -    else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   -    {   
   +       else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   +       {
            time_ms = (elapsed_time * 1000);
   -    }
   -    */
   -    /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -       
   -    else{
   +       }
   +     */
   +    /*
   +        TODO : setup wakeup with ALARM feature istead of wakeup
   +
   +       else{
            time_ms = (elapsed_time * 1000) + (36 * 60 * 60 * 1000);
    
   -    }
   -    */
   +       }
   +     */
    
        return time_ms;
    }
    
   -void hal_rtc_disable_wakeup(void)
   +void
   +hal_rtc_disable_wakeup(void)
    {
        HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32_common/src/hal_os_tick.c
   <details>
   
   ```diff
   @@ -39,10 +39,11 @@
    #if defined(STM32F405xx) || defined(STM32F407xx) || \
        defined(STM32F415xx) || defined(STM32F417xx)
    #undef __WFI
   -__attribute__((aligned(8), naked)) void static __WFI(void)
   +__attribute__((aligned(8), naked)) void static
   +__WFI(void)
    {
   -    __ASM volatile("wfi\n"
   -                   "bx lr");
   +    __ASM volatile ("wfi\n"
   +                    "bx lr");
    }
    #endif
    
   @@ -51,7 +52,8 @@
    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);
   @@ -77,18 +79,21 @@
        DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
    #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
    
   -void os_tick_idle(os_time_t ticks)
   +void
   +os_tick_idle(os_time_t ticks)
    {
        /* default mode will enter in WFI */
        int power_mode = HAL_BSP_POWER_WFI;
   @@ -96,8 +101,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;
   @@ -124,7 +128,8 @@
    #endif
    }
    
   -void os_tick_init(uint32_t os_ticks_per_sec, int prio)
   +void
   +os_tick_init(uint32_t os_ticks_per_sec, int prio)
    {
        stm32_tick_init(os_ticks_per_sec, prio);
    }
   ```
   
   </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

[GitHub] [mynewt-core] brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-573068569
 
 
   @andrzej-kaczmarek Ok, but the idle task calling hal functions may depend on the BSP used (eg to de-init/init drivers for board specific periphs. The required stack size is then dependant not just on the MCU but also on the BSP... The only thing I found that lets the BSP alter the OS config like this (without patching the mynewt-core files) is the syscfg mechanism? Or is there another way to do it?

----------------------------------------------------------------
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

[GitHub] [mynewt-core] apache-mynewt-bot commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-578512183
 
 
   
   <!-- style-bot -->
   
   ## Style check summary
   
   #### hw/mcu/stm/stm32l1xx/src/hal_power_mgnt.c
   <details>
   
   ```diff
   @@ -32,22 +32,25 @@
    extern void hal_rtc_init(RTC_DateTypeDef *date, RTC_TimeTypeDef *time);
    
    /* 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 */
        /* power watchdog off */
        /* Be in lowest power mode forever */
   -    while (1)
   -    {
   -        //        HAL_PWR_EnterSTANDBYMode();
   -        // TEST : don't lose RAM so can debug low powerness
   +    while (1) {
   +        /*
   +                  HAL_PWR_EnterSTANDBYMode();
   +           TEST : don't lose RAM so can debug low powerness
   +         */
            HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
            /* debug breakpoint */
        }
    }
    
   -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 */
   @@ -79,23 +82,25 @@
        hal_rtc_init(NULL, NULL);
    #endif
    }
   -void stm32_tickless_start(uint32_t timeMS)
   +void
   +stm32_tickless_start(uint32_t timeMS)
    {
        /* Start RTC alarm for in this amount of time */
        hal_rtc_enable_wakeup(timeMS);
        /* Stop SYSTICK */
        NVIC_DisableIRQ(SysTick_IRQn);
   -    //HAL_SuspendTick();
   +    /*HAL_SuspendTick(); */
    }
    
   -void stm32_tickless_stop(uint32_t timeMS)
   +void
   +stm32_tickless_stop(uint32_t timeMS)
    {
        /* disable RTC */
        hal_rtc_disable_wakeup();
    
        /* reenable systick */
        NVIC_EnableIRQ(SysTick_IRQn);
   -    //HAL_ResumeTick();
   +    /*HAL_ResumeTick(); */
    
        /* add asleep duration to tick counter : how long we should have slept for minus any remaining time */
        int asleep_ticks = os_time_ms_to_ticks32(timeMS - hal_rtc_get_remaining_time_before_wakeup());
   @@ -103,11 +108,11 @@
        os_time_advance(asleep_ticks);
    }
    
   -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;
        }
   @@ -116,8 +121,7 @@
        stm32_tickless_start(durationMS);
    #endif
    
   -    switch (power_mode)
   -    {
   +    switch (power_mode) {
        case HAL_BSP_POWER_OFF:
        {
            HAL_PWR_EnterSTANDBYMode();
   ```
   
   </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.
   -*/
   + */
    
    /**
     * Hal for rtc management
   @@ -23,19 +23,19 @@
    #include "stm32l1xx_hal_pwr.h"
    #include "bsp.h"
    
   -// sub-second number of bits
   +/* sub-second number of bits */
    #define N_PREDIV_S 10
    
   -// Synchronous prediv
   +/* Synchronous prediv */
    #define PREDIV_S ((1 << N_PREDIV_S) - 1)
    
   -// Asynchronous prediv
   +/* Asynchronous prediv */
    #define PREDIV_A (1 << (15 - N_PREDIV_S)) - 1
    
   -// Sub-second mask definition
   +/* Sub-second mask definition */
    #define ALARM_SUBSECOND_MASK (N_PREDIV_S << RTC_ALRMASSR_MASKSS_Pos)
    
   -// RTC Time base in us
   +/* RTC Time base in us */
    #define USEC_NUMBER 1000000
    #define MSEC_NUMBER (USEC_NUMBER / 1000)
    
   @@ -74,48 +74,49 @@
    #define MAX_RTC_PERIOD_MSEC (1000.0f * MAX_RTC_PERIOD_SEC)
    
    /*!
   - * 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
   + * 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 =
   -    {
   -        .Instance = NULL,
   -        .Init =
   -            {
   -                .HourFormat = 0,
   -                .AsynchPrediv = 0,
   -                .SynchPrediv = 0,
   -                .OutPut = 0,
   -                .OutPutPolarity = 0,
   -                .OutPutType = 0},
   -        .Lock = HAL_UNLOCKED,
   -        .State = HAL_RTC_STATE_RESET};
   -
   -/**
   -  * @brief  This function handles  WAKE UP TIMER  interrupt request.
   -  * @retval None
   -  */
   -void RTC_WKUP_IRQHandler(void)
   +static RTC_HandleTypeDef RtcHandle = {
   +    .Instance = NULL,
   +    .Init = {
   +        .HourFormat = 0,
   +        .AsynchPrediv = 0,
   +        .SynchPrediv = 0,
   +        .OutPut = 0,
   +        .OutPutPolarity = 0,
   +        .OutPutType = 0
   +    },
   +    .Lock = HAL_UNLOCKED,
   +    .State = HAL_RTC_STATE_RESET
   +};
   +
   +/**
   + * @brief  This function handles  WAKE UP TIMER  interrupt request.
   + * @retval None
   + */
   +void
   +RTC_WKUP_IRQHandler(void)
    {
        HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
    }
    
    /**
   -  * @brief  Wake Up Timer callback.
   -  * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   -  *                the configuration information for RTC.
   -  * @retval None
   -  */
   -void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
   + * @brief  Wake Up Timer callback.
   + * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   + *                the configuration information for RTC.
   + * @retval None
   + */
   +void
   +HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
    {
    }
    
   @@ -124,25 +125,28 @@
    #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;
    
   @@ -151,8 +155,8 @@
    
        RtcHandle.Instance = RTC;
        RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
   -    RtcHandle.Init.AsynchPrediv = PREDIV_A; // RTC_ASYNCH_PREDIV;
   -    RtcHandle.Init.SynchPrediv = PREDIV_S;  // RTC_SYNCH_PREDIV;
   +    RtcHandle.Init.AsynchPrediv = PREDIV_A; /* RTC_ASYNCH_PREDIV; */
   +    RtcHandle.Init.SynchPrediv = PREDIV_S;  /* RTC_SYNCH_PREDIV; */
        RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
        RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
        RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
   @@ -160,33 +164,29 @@
    
        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;
        }
   @@ -194,11 +194,13 @@
        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_EnableBypassShadow( &RtcHandle );
   +    /*
   +       Enable Direct Read of the calendar registers (not through Shadow registers)
   +       HAL_RTCEx_EnableBypassShadow( &RtcHandle );
   +     */
    
    #ifdef RTC_ALARM_TEST
   -    //setup alarm
   +    /*setup alarm */
        RtcAlarm.AlarmTime.Hours = 0;
        RtcAlarm.AlarmTime.Minutes = 0;
        RtcAlarm.AlarmTime.Seconds = 1;
   @@ -229,98 +231,95 @@
    static uint32_t clk_srce_sel;
    static uint16_t wkup_autoreload_timer;
    
   -void hal_rtc_enable_wakeup(uint32_t time_ms)
   +void
   +hal_rtc_enable_wakeup(uint32_t time_ms)
    {
        /* Enable and set RTC_WKUP_IRQ */
    
   -    //this NVIC setup doesn't work ....
   -    //TODO : find out why ...
   -    //HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   -    //HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -    //HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +    /*
   +       this NVIC setup doesn't work ....
   +       TODO : find out why ...
   +       HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   +       HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +       HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +     */
    
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
    
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
    
        /*
   -    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)) {
            clk_srce_sel = RTC_WAKEUPCLOCK_RTCCLK_DIV16;
            wkup_autoreload_timer = (uint32_t)((float)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))   {
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
            wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))
   -    {
   +    } else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))   {
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
            wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else
   -    {
   +    } else   {
            /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -        */
   +           TODO : setup wakeup with ALARM feature istead of wakeup
   +         */
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   -        /* 
   -       for now, set the maximum possible time
   -       */
   +        /*
   +           for now, set the maximum possible time
   +         */
            wkup_autoreload_timer = 0xFFFF;
        }
    
        HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, (uint32_t)wkup_autoreload_timer, clk_srce_sel);
    
   -    //NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   -    //NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   -    //NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -}
   -
   -uint32_t hal_rtc_get_remaining_time_before_wakeup(void)
   +    /*
   +       NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   +       NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   +       NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +     */
   +}
   +
   +uint32_t
   +hal_rtc_get_remaining_time_before_wakeup(void)
    {
        uint32_t time_ms, elapsed_time = HAL_RTCEx_GetWakeUpTimer(&RtcHandle);
    
   -    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16)
   -    {
   +    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16) {
            time_ms = (uint32_t)(((float)elapsed_time) * (MIN_RTC_PERIOD_MSEC));
   -    }
   -    else //if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS )
   -    {
   +    } else   { /*if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS ) */
            time_ms = (elapsed_time * 1000);
        }
        /*
   -    else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   -    {   
   +       else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   +       {
            time_ms = (elapsed_time * 1000);
   -    }
   -    */
   -    /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -       
   -    else{
   +       }
   +     */
   +    /*
   +        TODO : setup wakeup with ALARM feature istead of wakeup
   +
   +       else{
            time_ms = (elapsed_time * 1000) + (36 * 60 * 60 * 1000);
    
   -    }
   -    */
   +       }
   +     */
    
        return time_ms;
    }
    
   -void hal_rtc_disable_wakeup(void)
   +void
   +hal_rtc_disable_wakeup(void)
    {
        HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32_common/src/hal_os_tick.c
   <details>
   
   ```diff
   @@ -39,10 +39,11 @@
    #if defined(STM32F405xx) || defined(STM32F407xx) || \
        defined(STM32F415xx) || defined(STM32F417xx)
    #undef __WFI
   -__attribute__((aligned(8), naked)) void static __WFI(void)
   +__attribute__((aligned(8), naked)) void static
   +__WFI(void)
    {
   -    __ASM volatile("wfi\n"
   -                   "bx lr");
   +    __ASM volatile ("wfi\n"
   +                    "bx lr");
    }
    #endif
    
   @@ -51,7 +52,8 @@
    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);
   @@ -77,18 +79,21 @@
        DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
    #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
    
   -void os_tick_idle(os_time_t ticks)
   +void
   +os_tick_idle(os_time_t ticks)
    {
        /* default mode will enter in WFI */
        int power_mode = HAL_BSP_POWER_WFI;
   @@ -96,8 +101,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;
   @@ -124,7 +128,8 @@
    #endif
    }
    
   -void os_tick_init(uint32_t os_ticks_per_sec, int prio)
   +void
   +os_tick_init(uint32_t os_ticks_per_sec, int prio)
    {
        stm32_tick_init(os_ticks_per_sec, prio);
    }
   ```
   
   </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

[GitHub] [mynewt-core] andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-568212746
 
 
   idle stack size is used by idle task, not by interrupts, and I do not think it needs to be configurable (unless you can prove otherwise)

----------------------------------------------------------------
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

[GitHub] [mynewt-core] andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-572958942
 
 
   @brianwyld no, that patch was to fix build errors due to usage of `t_stacktop` which was removed by another PR.
   
   regarding configuration of idle stack size: I think your use case is valid (i.e. need to adjust stack due to idle task calling HAL function) however I still do not agree that having syscfg to configure idle stack size makes sense. Having syscfg suggests this can be adjusted by user which is not true. I think a better way to handle this would be to allow MCU (or BSP?) define idle stack size. For example, place `#define` with stack size in `mcu.h` and `os.c` will just use either that value or default one if not defined. I did not think this through nor looked through the code so perhaps there's better way to do this.

----------------------------------------------------------------
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

[GitHub] [mynewt-core] apache-mynewt-bot commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-585166638
 
 
   
   <!-- 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
   @@ -32,22 +32,25 @@
    extern void hal_rtc_init(RTC_DateTypeDef *date, RTC_TimeTypeDef *time);
    
    /* 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 */
        /* power watchdog off */
        /* Be in lowest power mode forever */
   -    while (1)
   -    {
   -        //        HAL_PWR_EnterSTANDBYMode();
   -        // TEST : don't lose RAM so can debug low powerness
   +    while (1) {
   +        /*
   +                  HAL_PWR_EnterSTANDBYMode();
   +           TEST : don't lose RAM so can debug low powerness
   +         */
            HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
            /* debug breakpoint */
        }
    }
    
   -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 */
   @@ -79,23 +82,25 @@
        hal_rtc_init(NULL, NULL);
    #endif
    }
   -void stm32_tickless_start(uint32_t timeMS)
   +void
   +stm32_tickless_start(uint32_t timeMS)
    {
        /* Start RTC alarm for in this amount of time */
        hal_rtc_enable_wakeup(timeMS);
        /* Stop SYSTICK */
        NVIC_DisableIRQ(SysTick_IRQn);
   -    //HAL_SuspendTick();
   +    /*HAL_SuspendTick(); */
    }
    
   -void stm32_tickless_stop(uint32_t timeMS)
   +void
   +stm32_tickless_stop(uint32_t timeMS)
    {
        /* disable RTC */
        hal_rtc_disable_wakeup();
    
        /* reenable systick */
        NVIC_EnableIRQ(SysTick_IRQn);
   -    //HAL_ResumeTick();
   +    /*HAL_ResumeTick(); */
    
        /* add asleep duration to tick counter : how long we should have slept for minus any remaining time */
        int asleep_ticks = os_time_ms_to_ticks32(timeMS - hal_rtc_get_remaining_time_before_wakeup());
   @@ -103,11 +108,11 @@
        os_time_advance(asleep_ticks);
    }
    
   -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;
        }
   @@ -116,8 +121,7 @@
        stm32_tickless_start(durationMS);
    #endif
    
   -    switch (power_mode)
   -    {
   +    switch (power_mode) {
        case HAL_BSP_POWER_OFF:
        {
            HAL_PWR_EnterSTANDBYMode();
   ```
   
   </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.
   -*/
   + */
    
    /**
     * Hal for rtc management
   @@ -23,19 +23,19 @@
    #include "stm32l1xx_hal_pwr.h"
    #include "bsp.h"
    
   -// sub-second number of bits
   +/* sub-second number of bits */
    #define N_PREDIV_S 10
    
   -// Synchronous prediv
   +/* Synchronous prediv */
    #define PREDIV_S ((1 << N_PREDIV_S) - 1)
    
   -// Asynchronous prediv
   +/* Asynchronous prediv */
    #define PREDIV_A (1 << (15 - N_PREDIV_S)) - 1
    
   -// Sub-second mask definition
   +/* Sub-second mask definition */
    #define ALARM_SUBSECOND_MASK (N_PREDIV_S << RTC_ALRMASSR_MASKSS_Pos)
    
   -// RTC Time base in us
   +/* RTC Time base in us */
    #define USEC_NUMBER 1000000
    #define MSEC_NUMBER (USEC_NUMBER / 1000)
    
   @@ -74,48 +74,49 @@
    #define MAX_RTC_PERIOD_MSEC (1000.0f * MAX_RTC_PERIOD_SEC)
    
    /*!
   - * 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
   + * 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 =
   -    {
   -        .Instance = NULL,
   -        .Init =
   -            {
   -                .HourFormat = 0,
   -                .AsynchPrediv = 0,
   -                .SynchPrediv = 0,
   -                .OutPut = 0,
   -                .OutPutPolarity = 0,
   -                .OutPutType = 0},
   -        .Lock = HAL_UNLOCKED,
   -        .State = HAL_RTC_STATE_RESET};
   -
   -/**
   -  * @brief  This function handles  WAKE UP TIMER  interrupt request.
   -  * @retval None
   -  */
   -void RTC_WKUP_IRQHandler(void)
   +static RTC_HandleTypeDef RtcHandle = {
   +    .Instance = NULL,
   +    .Init = {
   +        .HourFormat = 0,
   +        .AsynchPrediv = 0,
   +        .SynchPrediv = 0,
   +        .OutPut = 0,
   +        .OutPutPolarity = 0,
   +        .OutPutType = 0
   +    },
   +    .Lock = HAL_UNLOCKED,
   +    .State = HAL_RTC_STATE_RESET
   +};
   +
   +/**
   + * @brief  This function handles  WAKE UP TIMER  interrupt request.
   + * @retval None
   + */
   +void
   +RTC_WKUP_IRQHandler(void)
    {
        HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
    }
    
    /**
   -  * @brief  Wake Up Timer callback.
   -  * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   -  *                the configuration information for RTC.
   -  * @retval None
   -  */
   -void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
   + * @brief  Wake Up Timer callback.
   + * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   + *                the configuration information for RTC.
   + * @retval None
   + */
   +void
   +HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
    {
    }
    
   @@ -124,25 +125,28 @@
    #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;
    
   @@ -151,8 +155,8 @@
    
        RtcHandle.Instance = RTC;
        RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
   -    RtcHandle.Init.AsynchPrediv = PREDIV_A; // RTC_ASYNCH_PREDIV;
   -    RtcHandle.Init.SynchPrediv = PREDIV_S;  // RTC_SYNCH_PREDIV;
   +    RtcHandle.Init.AsynchPrediv = PREDIV_A; /* RTC_ASYNCH_PREDIV; */
   +    RtcHandle.Init.SynchPrediv = PREDIV_S;  /* RTC_SYNCH_PREDIV; */
        RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
        RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
        RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
   @@ -160,33 +164,29 @@
    
        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;
        }
   @@ -194,11 +194,13 @@
        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_EnableBypassShadow( &RtcHandle );
   +    /*
   +       Enable Direct Read of the calendar registers (not through Shadow registers)
   +       HAL_RTCEx_EnableBypassShadow( &RtcHandle );
   +     */
    
    #ifdef RTC_ALARM_TEST
   -    //setup alarm
   +    /*setup alarm */
        RtcAlarm.AlarmTime.Hours = 0;
        RtcAlarm.AlarmTime.Minutes = 0;
        RtcAlarm.AlarmTime.Seconds = 1;
   @@ -229,98 +231,95 @@
    static uint32_t clk_srce_sel;
    static uint16_t wkup_autoreload_timer;
    
   -void hal_rtc_enable_wakeup(uint32_t time_ms)
   +void
   +hal_rtc_enable_wakeup(uint32_t time_ms)
    {
        /* Enable and set RTC_WKUP_IRQ */
    
   -    //this NVIC setup doesn't work ....
   -    //TODO : find out why ...
   -    //HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   -    //HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -    //HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +    /*
   +       this NVIC setup doesn't work ....
   +       TODO : find out why ...
   +       HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   +       HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +       HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +     */
    
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
    
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
    
        /*
   -    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)) {
            clk_srce_sel = RTC_WAKEUPCLOCK_RTCCLK_DIV16;
            wkup_autoreload_timer = (uint32_t)((float)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))   {
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
            wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))
   -    {
   +    } else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))   {
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
            wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else
   -    {
   +    } else   {
            /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -        */
   +           TODO : setup wakeup with ALARM feature istead of wakeup
   +         */
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   -        /* 
   -       for now, set the maximum possible time
   -       */
   +        /*
   +           for now, set the maximum possible time
   +         */
            wkup_autoreload_timer = 0xFFFF;
        }
    
        HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, (uint32_t)wkup_autoreload_timer, clk_srce_sel);
    
   -    //NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   -    //NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   -    //NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -}
   -
   -uint32_t hal_rtc_get_remaining_time_before_wakeup(void)
   +    /*
   +       NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   +       NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   +       NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +     */
   +}
   +
   +uint32_t
   +hal_rtc_get_remaining_time_before_wakeup(void)
    {
        uint32_t time_ms, elapsed_time = HAL_RTCEx_GetWakeUpTimer(&RtcHandle);
    
   -    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16)
   -    {
   +    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16) {
            time_ms = (uint32_t)(((float)elapsed_time) * (MIN_RTC_PERIOD_MSEC));
   -    }
   -    else //if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS )
   -    {
   +    } else   { /*if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS ) */
            time_ms = (elapsed_time * 1000);
        }
        /*
   -    else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   -    {   
   +       else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   +       {
            time_ms = (elapsed_time * 1000);
   -    }
   -    */
   -    /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -       
   -    else{
   +       }
   +     */
   +    /*
   +        TODO : setup wakeup with ALARM feature istead of wakeup
   +
   +       else{
            time_ms = (elapsed_time * 1000) + (36 * 60 * 60 * 1000);
    
   -    }
   -    */
   +       }
   +     */
    
        return time_ms;
    }
    
   -void hal_rtc_disable_wakeup(void)
   +void
   +hal_rtc_disable_wakeup(void)
    {
        HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32_common/src/hal_os_tick.c
   <details>
   
   ```diff
   @@ -39,10 +39,11 @@
    #if defined(STM32F405xx) || defined(STM32F407xx) || \
        defined(STM32F415xx) || defined(STM32F417xx)
    #undef __WFI
   -__attribute__((aligned(8), naked)) void static __WFI(void)
   +__attribute__((aligned(8), naked)) void static
   +__WFI(void)
    {
   -    __ASM volatile("wfi\n"
   -                   "bx lr");
   +    __ASM volatile ("wfi\n"
   +                    "bx lr");
    }
    #endif
    
   @@ -51,7 +52,8 @@
    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);
   @@ -77,18 +79,21 @@
        DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
    #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
    
   -void os_tick_idle(os_time_t ticks)
   +void
   +os_tick_idle(os_time_t ticks)
    {
        /* default mode will enter in WFI */
        int power_mode = HAL_BSP_POWER_WFI;
   @@ -96,8 +101,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;
   @@ -124,7 +128,8 @@
    #endif
    }
    
   -void os_tick_init(uint32_t os_ticks_per_sec, int prio)
   +void
   +os_tick_init(uint32_t os_ticks_per_sec, int prio)
    {
        stm32_tick_init(os_ticks_per_sec, prio);
    }
   ```
   
   </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

[GitHub] [mynewt-core] apache-mynewt-bot commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-593882823
 
 
   
   <!-- 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

[GitHub] [mynewt-core] andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-571655862
 
 
   > hal_rtc.c is not final and has issues with the stm32 clock config perhaps due to the latest update for syscfg config of the clock...
   
   there should be no `hal_rtc.c` file since we do not have `hal_rtc` defined anywhere. use different name for internal APIs, check da1469x MCU which has a lot internal APIs defined in addition to HALs.

----------------------------------------------------------------
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

[GitHub] [mynewt-core] brianwyld commented on a change in pull request #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
brianwyld commented on a change in pull request #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#discussion_r363813594
 
 

 ##########
 File path: hw/mcu/stm/stm32_common/src/hal_os_tick.c
 ##########
 @@ -1,78 +1,135 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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 language governing permissions and limitations
- * under the License.
- */
-
-#include <assert.h>
-#include "os/mynewt.h"
-#include <hal/hal_os_tick.h>
-
-/*
- * XXX implement tickless mode.
- */
-
-/*
- * Errata for STM32F405, STM32F407, STM32F415, STM32F417.
- * When WFI instruction is placed at address like 0x080xxxx4
- * (also seen for addresses ending with xxx2). System may
- * crash.
- * __WFI function places WFI instruction at address ending with x0 or x8
- * for affected MCUs.
- */
-#if defined(STM32F405xx) || defined(STM32F407xx) || \
-    defined(STM32F415xx) || defined(STM32F417xx)
-#undef __WFI
-__attribute__((aligned(8), naked)) void static
-__WFI(void)
-{
-     __ASM volatile("wfi\n"
-                    "bx lr");
-}
-#endif
-
-void
-os_tick_idle(os_time_t ticks)
-{
-    OS_ASSERT_CRITICAL();
-    __DSB();
-    __WFI();
-}
-
-void
-os_tick_init(uint32_t os_ticks_per_sec, int prio)
-{
-    uint32_t reload_val;
-
-    reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
-
-    /* Set the system time ticker up */
-    SysTick->LOAD = reload_val;
-    SysTick->VAL = 0;
-    SysTick->CTRL = 0x0007;
-
-    /* Set the system tick priority */
-    NVIC_SetPriority(SysTick_IRQn, prio);
-
-    /*
-     * Keep clocking debug even when CPU is sleeping, stopped or in standby.
-     */
-#if !MYNEWT_VAL(MCU_STM32F0)
-    DBGMCU->CR |= (DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
-#else
-    DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
-#endif
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include "os/mynewt.h"
+#include <hal/hal_os_tick.h>
+#include <hal/hal_bsp.h>
+#include "bsp/bsp.h"
+#include "system_stm32l1xx.h"
 
 Review comment:
   There are already a bunch of STM32 processor specific includes in this file?! eg
   #if defined(STM32F405xx) || defined(STM32F407xx) || \
       defined(STM32F415xx) || defined(STM32F417xx)
   Otherwise, what is the 'good' way to have the processor specific function for the stm32_tick_init/stm32_power_enter functions for the STML1? (these need to be specific as the low power mode/tickless operation for a L1 will use RTC, but a L0 will use its specific low power timer...)
   For the diff, not sure what you mean - github diff shows me just the lines I changed (a lot for hal_os_tick.c I agree)

----------------------------------------------------------------
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

[GitHub] [mynewt-core] apache-mynewt-bot removed a comment on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-585166638
 
 
   
   <!-- 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
   @@ -32,22 +32,25 @@
    extern void hal_rtc_init(RTC_DateTypeDef *date, RTC_TimeTypeDef *time);
    
    /* 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 */
        /* power watchdog off */
        /* Be in lowest power mode forever */
   -    while (1)
   -    {
   -        //        HAL_PWR_EnterSTANDBYMode();
   -        // TEST : don't lose RAM so can debug low powerness
   +    while (1) {
   +        /*
   +                  HAL_PWR_EnterSTANDBYMode();
   +           TEST : don't lose RAM so can debug low powerness
   +         */
            HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
            /* debug breakpoint */
        }
    }
    
   -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 */
   @@ -79,23 +82,25 @@
        hal_rtc_init(NULL, NULL);
    #endif
    }
   -void stm32_tickless_start(uint32_t timeMS)
   +void
   +stm32_tickless_start(uint32_t timeMS)
    {
        /* Start RTC alarm for in this amount of time */
        hal_rtc_enable_wakeup(timeMS);
        /* Stop SYSTICK */
        NVIC_DisableIRQ(SysTick_IRQn);
   -    //HAL_SuspendTick();
   +    /*HAL_SuspendTick(); */
    }
    
   -void stm32_tickless_stop(uint32_t timeMS)
   +void
   +stm32_tickless_stop(uint32_t timeMS)
    {
        /* disable RTC */
        hal_rtc_disable_wakeup();
    
        /* reenable systick */
        NVIC_EnableIRQ(SysTick_IRQn);
   -    //HAL_ResumeTick();
   +    /*HAL_ResumeTick(); */
    
        /* add asleep duration to tick counter : how long we should have slept for minus any remaining time */
        int asleep_ticks = os_time_ms_to_ticks32(timeMS - hal_rtc_get_remaining_time_before_wakeup());
   @@ -103,11 +108,11 @@
        os_time_advance(asleep_ticks);
    }
    
   -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;
        }
   @@ -116,8 +121,7 @@
        stm32_tickless_start(durationMS);
    #endif
    
   -    switch (power_mode)
   -    {
   +    switch (power_mode) {
        case HAL_BSP_POWER_OFF:
        {
            HAL_PWR_EnterSTANDBYMode();
   ```
   
   </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.
   -*/
   + */
    
    /**
     * Hal for rtc management
   @@ -23,19 +23,19 @@
    #include "stm32l1xx_hal_pwr.h"
    #include "bsp.h"
    
   -// sub-second number of bits
   +/* sub-second number of bits */
    #define N_PREDIV_S 10
    
   -// Synchronous prediv
   +/* Synchronous prediv */
    #define PREDIV_S ((1 << N_PREDIV_S) - 1)
    
   -// Asynchronous prediv
   +/* Asynchronous prediv */
    #define PREDIV_A (1 << (15 - N_PREDIV_S)) - 1
    
   -// Sub-second mask definition
   +/* Sub-second mask definition */
    #define ALARM_SUBSECOND_MASK (N_PREDIV_S << RTC_ALRMASSR_MASKSS_Pos)
    
   -// RTC Time base in us
   +/* RTC Time base in us */
    #define USEC_NUMBER 1000000
    #define MSEC_NUMBER (USEC_NUMBER / 1000)
    
   @@ -74,48 +74,49 @@
    #define MAX_RTC_PERIOD_MSEC (1000.0f * MAX_RTC_PERIOD_SEC)
    
    /*!
   - * 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
   + * 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 =
   -    {
   -        .Instance = NULL,
   -        .Init =
   -            {
   -                .HourFormat = 0,
   -                .AsynchPrediv = 0,
   -                .SynchPrediv = 0,
   -                .OutPut = 0,
   -                .OutPutPolarity = 0,
   -                .OutPutType = 0},
   -        .Lock = HAL_UNLOCKED,
   -        .State = HAL_RTC_STATE_RESET};
   -
   -/**
   -  * @brief  This function handles  WAKE UP TIMER  interrupt request.
   -  * @retval None
   -  */
   -void RTC_WKUP_IRQHandler(void)
   +static RTC_HandleTypeDef RtcHandle = {
   +    .Instance = NULL,
   +    .Init = {
   +        .HourFormat = 0,
   +        .AsynchPrediv = 0,
   +        .SynchPrediv = 0,
   +        .OutPut = 0,
   +        .OutPutPolarity = 0,
   +        .OutPutType = 0
   +    },
   +    .Lock = HAL_UNLOCKED,
   +    .State = HAL_RTC_STATE_RESET
   +};
   +
   +/**
   + * @brief  This function handles  WAKE UP TIMER  interrupt request.
   + * @retval None
   + */
   +void
   +RTC_WKUP_IRQHandler(void)
    {
        HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
    }
    
    /**
   -  * @brief  Wake Up Timer callback.
   -  * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   -  *                the configuration information for RTC.
   -  * @retval None
   -  */
   -void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
   + * @brief  Wake Up Timer callback.
   + * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   + *                the configuration information for RTC.
   + * @retval None
   + */
   +void
   +HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
    {
    }
    
   @@ -124,25 +125,28 @@
    #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;
    
   @@ -151,8 +155,8 @@
    
        RtcHandle.Instance = RTC;
        RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
   -    RtcHandle.Init.AsynchPrediv = PREDIV_A; // RTC_ASYNCH_PREDIV;
   -    RtcHandle.Init.SynchPrediv = PREDIV_S;  // RTC_SYNCH_PREDIV;
   +    RtcHandle.Init.AsynchPrediv = PREDIV_A; /* RTC_ASYNCH_PREDIV; */
   +    RtcHandle.Init.SynchPrediv = PREDIV_S;  /* RTC_SYNCH_PREDIV; */
        RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
        RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
        RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
   @@ -160,33 +164,29 @@
    
        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;
        }
   @@ -194,11 +194,13 @@
        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_EnableBypassShadow( &RtcHandle );
   +    /*
   +       Enable Direct Read of the calendar registers (not through Shadow registers)
   +       HAL_RTCEx_EnableBypassShadow( &RtcHandle );
   +     */
    
    #ifdef RTC_ALARM_TEST
   -    //setup alarm
   +    /*setup alarm */
        RtcAlarm.AlarmTime.Hours = 0;
        RtcAlarm.AlarmTime.Minutes = 0;
        RtcAlarm.AlarmTime.Seconds = 1;
   @@ -229,98 +231,95 @@
    static uint32_t clk_srce_sel;
    static uint16_t wkup_autoreload_timer;
    
   -void hal_rtc_enable_wakeup(uint32_t time_ms)
   +void
   +hal_rtc_enable_wakeup(uint32_t time_ms)
    {
        /* Enable and set RTC_WKUP_IRQ */
    
   -    //this NVIC setup doesn't work ....
   -    //TODO : find out why ...
   -    //HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   -    //HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -    //HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +    /*
   +       this NVIC setup doesn't work ....
   +       TODO : find out why ...
   +       HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   +       HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +       HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +     */
    
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
    
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
    
        /*
   -    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)) {
            clk_srce_sel = RTC_WAKEUPCLOCK_RTCCLK_DIV16;
            wkup_autoreload_timer = (uint32_t)((float)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))   {
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
            wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))
   -    {
   +    } else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))   {
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
            wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else
   -    {
   +    } else   {
            /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -        */
   +           TODO : setup wakeup with ALARM feature istead of wakeup
   +         */
            clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   -        /* 
   -       for now, set the maximum possible time
   -       */
   +        /*
   +           for now, set the maximum possible time
   +         */
            wkup_autoreload_timer = 0xFFFF;
        }
    
        HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, (uint32_t)wkup_autoreload_timer, clk_srce_sel);
    
   -    //NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   -    //NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   -    //NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -}
   -
   -uint32_t hal_rtc_get_remaining_time_before_wakeup(void)
   +    /*
   +       NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   +       NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   +       NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +     */
   +}
   +
   +uint32_t
   +hal_rtc_get_remaining_time_before_wakeup(void)
    {
        uint32_t time_ms, elapsed_time = HAL_RTCEx_GetWakeUpTimer(&RtcHandle);
    
   -    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16)
   -    {
   +    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16) {
            time_ms = (uint32_t)(((float)elapsed_time) * (MIN_RTC_PERIOD_MSEC));
   -    }
   -    else //if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS )
   -    {
   +    } else   { /*if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS ) */
            time_ms = (elapsed_time * 1000);
        }
        /*
   -    else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   -    {   
   +       else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   +       {
            time_ms = (elapsed_time * 1000);
   -    }
   -    */
   -    /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -       
   -    else{
   +       }
   +     */
   +    /*
   +        TODO : setup wakeup with ALARM feature istead of wakeup
   +
   +       else{
            time_ms = (elapsed_time * 1000) + (36 * 60 * 60 * 1000);
    
   -    }
   -    */
   +       }
   +     */
    
        return time_ms;
    }
    
   -void hal_rtc_disable_wakeup(void)
   +void
   +hal_rtc_disable_wakeup(void)
    {
        HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
        NVIC_DisableIRQ(RTC_WKUP_IRQn);
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32_common/src/hal_os_tick.c
   <details>
   
   ```diff
   @@ -39,10 +39,11 @@
    #if defined(STM32F405xx) || defined(STM32F407xx) || \
        defined(STM32F415xx) || defined(STM32F417xx)
    #undef __WFI
   -__attribute__((aligned(8), naked)) void static __WFI(void)
   +__attribute__((aligned(8), naked)) void static
   +__WFI(void)
    {
   -    __ASM volatile("wfi\n"
   -                   "bx lr");
   +    __ASM volatile ("wfi\n"
   +                    "bx lr");
    }
    #endif
    
   @@ -51,7 +52,8 @@
    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);
   @@ -77,18 +79,21 @@
        DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
    #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
    
   -void os_tick_idle(os_time_t ticks)
   +void
   +os_tick_idle(os_time_t ticks)
    {
        /* default mode will enter in WFI */
        int power_mode = HAL_BSP_POWER_WFI;
   @@ -96,8 +101,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;
   @@ -124,7 +128,8 @@
    #endif
    }
    
   -void os_tick_init(uint32_t os_ticks_per_sec, int prio)
   +void
   +os_tick_init(uint32_t os_ticks_per_sec, int prio)
    {
        stm32_tick_init(os_ticks_per_sec, prio);
    }
   ```
   
   </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

[GitHub] [mynewt-core] brianwyld closed pull request #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
brianwyld closed pull request #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138
 
 
   

----------------------------------------------------------------
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

[GitHub] [mynewt-core] utzig commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
utzig commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-576655766
 
 
   @brianwyld Please update your editor to use Unix line endings (`\n` only), instead of DOS.

----------------------------------------------------------------
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

[GitHub] [mynewt-core] brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-593877583
 
 
   I have removed the config of idle task stack size by syscfg as suggested, and added the include of the bsp_defs.h in os.c, which allows a BSP to re-define the size of the idle stack based on its requirements (in particular if bsp is called to deinit peripherals in preparation for low power sleep)
   If this method of configuring the idle task stack size if acceptable then I will split the PR to have 1 change per PR :
   - idle task stack size config via bsp_defs.h
   - don't call any watchdog fns if watchdog is disabled (interval=0)
   - add deep low power mode operation for STM32L1xx including tickless RTC in STOP mode, BSP peripheral de-init callbacks)

----------------------------------------------------------------
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

[GitHub] [mynewt-core] brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-568296870
 
 
   I'm out of the office for the next 2 weeks, so will come back on this once I'm back and have access to devices!

----------------------------------------------------------------
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

[GitHub] [mynewt-core] apache-mynewt-bot commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-593442659
 
 
   
   <!-- 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

[GitHub] [mynewt-core] andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-593894597
 
 
   you need to clean up this PR, otherwise I doubt anyone will take a look on this anytime soon.
   
   you need to create series of commits with each change separated and described in commit message and obviously rebase your branch so there are no conflicts with upstream branch and there are no merges from other repos in history.
   
   

----------------------------------------------------------------
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

[GitHub] [mynewt-core] brianwyld commented on a change in pull request #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
brianwyld commented on a change in pull request #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#discussion_r363814624
 
 

 ##########
 File path: hw/mcu/stm/stm32_common/src/hal_os_tick.c
 ##########
 @@ -1,78 +1,135 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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 language governing permissions and limitations
- * under the License.
- */
-
-#include <assert.h>
-#include "os/mynewt.h"
-#include <hal/hal_os_tick.h>
-
-/*
- * XXX implement tickless mode.
- */
-
-/*
- * Errata for STM32F405, STM32F407, STM32F415, STM32F417.
- * When WFI instruction is placed at address like 0x080xxxx4
- * (also seen for addresses ending with xxx2). System may
- * crash.
- * __WFI function places WFI instruction at address ending with x0 or x8
- * for affected MCUs.
- */
-#if defined(STM32F405xx) || defined(STM32F407xx) || \
-    defined(STM32F415xx) || defined(STM32F417xx)
-#undef __WFI
-__attribute__((aligned(8), naked)) void static
-__WFI(void)
-{
-     __ASM volatile("wfi\n"
-                    "bx lr");
-}
-#endif
-
-void
-os_tick_idle(os_time_t ticks)
-{
-    OS_ASSERT_CRITICAL();
-    __DSB();
-    __WFI();
-}
-
-void
-os_tick_init(uint32_t os_ticks_per_sec, int prio)
-{
-    uint32_t reload_val;
-
-    reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
-
-    /* Set the system time ticker up */
-    SysTick->LOAD = reload_val;
-    SysTick->VAL = 0;
-    SysTick->CTRL = 0x0007;
-
-    /* Set the system tick priority */
-    NVIC_SetPriority(SysTick_IRQn, prio);
-
-    /*
-     * Keep clocking debug even when CPU is sleeping, stopped or in standby.
-     */
-#if !MYNEWT_VAL(MCU_STM32F0)
-    DBGMCU->CR |= (DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
-#else
-    DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
-#endif
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include "os/mynewt.h"
+#include <hal/hal_os_tick.h>
+#include <hal/hal_bsp.h>
+#include "bsp/bsp.h"
+#include "system_stm32l1xx.h"
 
 Review comment:
   for the diff it only seems to have affected this file... sorry...

----------------------------------------------------------------
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

[GitHub] [mynewt-core] apache-mynewt-bot removed a comment on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-576345926
 
 
   
   <!-- style-bot -->
   
   ## Style check summary
   
   #### hw/mcu/stm/stm32_common/src/hal_os_tick.c
   <details>
   
   ```diff
   @@ -1,135 +1,138 @@
   -/*
   - * Licensed to the Apache Software Foundation (ASF) under one
   - * or more contributor license agreements.  See the NOTICE file
   - * distributed with this work for additional information
   - * regarding copyright ownership.  The ASF licenses this file
   - * to you 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 language governing permissions and limitations
   - * under the License.
   - */
   -
   -#include <assert.h>
   -#include "os/mynewt.h"
   -#include <hal/hal_os_tick.h>
   -#include <hal/hal_bsp.h>
   -#include "bsp/bsp.h"
   -#include "system_stm32l1xx.h"
   -#include "core_cm3.h"
   -#include "stm32l151xc.h"
   -
   -/*
   - * Errata for STM32F405, STM32F407, STM32F415, STM32F417.
   - * When WFI instruction is placed at address like 0x080xxxx4
   - * (also seen for addresses ending with xxx2). System may
   - * crash.
   - * __WFI function places WFI instruction at address ending with x0 or x8
   - * for affected MCUs.
   - */
   -#include "stm32l1xx_hal.h"
   -
   -#if defined(STM32F405xx) || defined(STM32F407xx) || \
   -    defined(STM32F415xx) || defined(STM32F417xx)
   -#undef __WFI
   -__attribute__((aligned(8), naked)) void static
   -__WFI(void)
   -{
   -     __ASM volatile("wfi\n"
   -                    "bx lr");
   -}
   -#endif
   -
   -/* implementation of different power modes available on STM32 processors */
   -#ifdef STM32L151xC
   -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 */
   -    assert(os_ticks_per_sec == OS_TICKS_PER_SEC);
   -    
   -    uint32_t reload_val;
   -
   -    reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
   -
   -    /* Set the system time ticker up */
   -    SysTick->LOAD = reload_val;
   -    SysTick->VAL = 0;
   -    SysTick->CTRL = 0x0007;
   -
   -    /* Set the system tick priority */
   -    NVIC_SetPriority(SysTick_IRQn, prio);
   -
   -    /*
   -     * Keep clocking debug even when CPU is sleeping, stopped or in standby.
   -     */
   -#if !MYNEWT_VAL(MCU_STM32F0)
   -    DBGMCU->CR |= (DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   -#else
   -    DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   -#endif
   -
   -}
   -static void stm32_power_enter(int power_mode, uint32_t durationMS)
   -{
   -    __DSB();
   -    __WFI();
   -}
   -void stm32_tickless_init() {
   -}
   -
   -#endif
   -
   -
   -void
   -os_tick_idle(os_time_t ticks)
   -{
   -    /* default mode will enter in 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) { 
   -        __DSB();
   -        __WFI();
   -        return;
   -    }
   -
   -
   -    /* Convert to ms */
   -    volatile uint32_t timeMS = os_time_ticks_to_ms32(ticks);
   -
   -#if MYNEWT_VAL(BSP_POWER_SETUP)
   -    /* ask bsp for lowest power mode that is possible */
   -    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();
   -
   -#endif
   -
   -    /* setup the appropriate mcu power mode during timeMs asked by os scheduling */
   -    stm32_power_enter(power_mode, timeMS);
   -
   -#if MYNEWT_VAL(BSP_POWER_SETUP)
   -    /* bsp exits the actual power mode */
   -    hal_bsp_power_handler_sleep_exit();
   -#endif
   -
   -
   -}
   -
   -void
   -os_tick_init(uint32_t os_ticks_per_sec, int prio)
   -{
   -    stm32_tick_init(os_ticks_per_sec, prio);
   -}
   +/*
   + * Licensed to the Apache Software Foundation (ASF) under one
   + * or more contributor license agreements.  See the NOTICE file
   + * distributed with this work for additional information
   + * regarding copyright ownership.  The ASF licenses this file
   + * to you 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 language governing permissions and limitations
   + * under the License.
   + */
   +
   +#include <assert.h>
   +#include "os/mynewt.h"
   +#include <hal/hal_os_tick.h>
   +#include <hal/hal_bsp.h>
   +#include "bsp/bsp.h"
   +#include "system_stm32l1xx.h"
   +#include "core_cm3.h"
   +#include "stm32l151xc.h"
   +
   +/*
   + * Errata for STM32F405, STM32F407, STM32F415, STM32F417.
   + * When WFI instruction is placed at address like 0x080xxxx4
   + * (also seen for addresses ending with xxx2). System may
   + * crash.
   + * __WFI function places WFI instruction at address ending with x0 or x8
   + * for affected MCUs.
   + */
   +#include "stm32l1xx_hal.h"
   +
   +#if defined(STM32F405xx) || defined(STM32F407xx) || \
   +    defined(STM32F415xx) || defined(STM32F417xx)
   +#undef __WFI
   +__attribute__((aligned(8), naked)) void static
   +__WFI(void)
   +{
   +    __ASM volatile ("wfi\n"
   +                    "bx lr");
   +}
   +#endif
   +
   +/* implementation of different power modes available on STM32 processors */
   +#ifdef STM32L151xC
   +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 */
   +    assert(os_ticks_per_sec == OS_TICKS_PER_SEC);
   +
   +    uint32_t reload_val;
   +
   +    reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
   +
   +    /* Set the system time ticker up */
   +    SysTick->LOAD = reload_val;
   +    SysTick->VAL = 0;
   +    SysTick->CTRL = 0x0007;
   +
   +    /* Set the system tick priority */
   +    NVIC_SetPriority(SysTick_IRQn, prio);
   +
   +    /*
   +     * Keep clocking debug even when CPU is sleeping, stopped or in standby.
   +     */
   +#if !MYNEWT_VAL(MCU_STM32F0)
   +    DBGMCU->CR |= (DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   +#else
   +    DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   +#endif
   +
   +}
   +static void
   +stm32_power_enter(int power_mode, uint32_t durationMS)
   +{
   +    __DSB();
   +    __WFI();
   +}
   +void
   +stm32_tickless_init() {
   +}
   +
   +#endif
   +
   +
   +void
   +os_tick_idle(os_time_t ticks)
   +{
   +    /* default mode will enter in 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) {
   +        __DSB();
   +        __WFI();
   +        return;
   +    }
   +
   +
   +    /* Convert to ms */
   +    volatile uint32_t timeMS = os_time_ticks_to_ms32(ticks);
   +
   +#if MYNEWT_VAL(BSP_POWER_SETUP)
   +    /* ask bsp for lowest power mode that is possible */
   +    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();
   +
   +#endif
   +
   +    /* setup the appropriate mcu power mode during timeMs asked by os scheduling */
   +    stm32_power_enter(power_mode, timeMS);
   +
   +#if MYNEWT_VAL(BSP_POWER_SETUP)
   +    /* bsp exits the actual power mode */
   +    hal_bsp_power_handler_sleep_exit();
   +#endif
   +
   +
   +}
   +
   +void
   +os_tick_init(uint32_t os_ticks_per_sec, int prio)
   +{
   +    stm32_tick_init(os_ticks_per_sec, prio);
   +}
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32l1xx/src/hal_power_mgnt.c
   <details>
   
   ```diff
   @@ -1,145 +1,150 @@
   -/*
   - * Licensed to the Apache Software Foundation (ASF) under one
   - * or more contributor license agreements.  See the NOTICE file
   - * distributed with this work for additional information
   - * regarding copyright ownership.  The ASF licenses this file
   - * to you 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 language governing permissions and limitations
   - * under the License.
   - */
   -
   -#include <string.h>
   -#include <assert.h>
   -#include <os/mynewt.h>
   -#include <syscfg/syscfg.h>
   -#include <mcu/stm32_hal.h>
   -#include <hal/hal_bsp.h>
   -#include "stm32l1xx_hal_pwr.h"
   -#include "stm32l1xx_hal_rtc.h"
   -
   -
   -extern void hal_rtc_enable_wakeup(uint32_t time_ms);
   -extern void hal_rtc_disable_wakeup(void);
   -extern uint32_t hal_rtc_get_remaining_time_before_wakeup(void);
   -extern void hal_rtc_init(RTC_DateTypeDef *date, RTC_TimeTypeDef *time);
   -
   -/* Put MCU  in lowest power stop state, exit only via POR or reset pin */
   -void hal_mcu_halt() {
   -    /* all interupts and exceptions off */
   -    /* PVD off */
   -    /* power watchdog off */
   -    /* Be in lowest power mode forever */
   -    while(1) {
   -//        HAL_PWR_EnterSTANDBYMode();
   -        // TEST : don't lose RAM so can debug low powerness
   -        HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
   -        /* debug breakpoint */
   -
   -    }
   -}
   -
   -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);
   -    
   -    uint32_t reload_val;
   -
   -    reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
   -
   -    /* Set the system time ticker up */
   -    SysTick->LOAD = reload_val;
   -    SysTick->VAL = 0;
   -    SysTick->CTRL = 0x0007;
   -
   -    /* Set the system tick priority */
   -    NVIC_SetPriority(SysTick_IRQn, prio);
   -
   -    /*
   -     * Keep clocking debug even when CPU is sleeping, stopped or in standby.
   -     */
   -#if !MYNEWT_VAL(MCU_STM32F0)
   -    DBGMCU->CR |= (DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   -#else
   -    DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   -#endif
   -
   -#if MYNEWT_VAL(OS_TICKLESS_RTC)
   -    /* initialise RTC for tickless code if required */
   -    hal_rtc_init(NULL, NULL);
   -#endif
   -
   -}
   -void stm32_tickless_start(uint32_t timeMS) {
   -    /* Start RTC alarm for in this amount of time */
   -    hal_rtc_enable_wakeup(timeMS);
   -    /* Stop SYSTICK */
   -    NVIC_DisableIRQ(SysTick_IRQn);
   -    //HAL_SuspendTick();
   -}
   -
   -void stm32_tickless_stop(uint32_t timeMS) {
   -    /* disable RTC */
   -    hal_rtc_disable_wakeup();
   -
   -    /* reenable systick */
   -    NVIC_EnableIRQ(SysTick_IRQn);
   -    //HAL_ResumeTick();
   -
   -    /* add asleep duration to tick counter : how long we should have slept for minus any remaining time */ 
   -    int asleep_ticks = os_time_ms_to_ticks32(timeMS - hal_rtc_get_remaining_time_before_wakeup());
   -    assert(asleep_ticks>=0);
   -    os_time_advance(asleep_ticks);
   -}
   -
   -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) {
   -        HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   -        return;
   -    }
   -    /* begin tickless */
   -#if MYNEWT_VAL(OS_TICKLESS_RTC)
   -    stm32_tickless_start(durationMS);
   -#endif
   -
   -    switch(power_mode) {
   -        case HAL_BSP_POWER_OFF: {
   -            HAL_PWR_EnterSTANDBYMode();
   -            break;
   -        }
   -        case HAL_BSP_POWER_DEEP_SLEEP: {
   -            HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
   -            break;
   -        }
   -        case HAL_BSP_POWER_SLEEP: {
   -            HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   -            break;
   -        }
   -        case HAL_BSP_POWER_WFI: {
   -            HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   -            break;
   -        }
   -        case HAL_BSP_POWER_ON:
   -        default: {
   -            
   -            break;
   -        }
   -    }
   -
   -#if MYNEWT_VAL(OS_TICKLESS_RTC)
   -    /* exit tickless low power mode */
   -    stm32_tickless_stop(durationMS);
   -#endif
   -
   +/*
   + * Licensed to the Apache Software Foundation (ASF) under one
   + * or more contributor license agreements.  See the NOTICE file
   + * distributed with this work for additional information
   + * regarding copyright ownership.  The ASF licenses this file
   + * to you 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 language governing permissions and limitations
   + * under the License.
   + */
   +
   +#include <string.h>
   +#include <assert.h>
   +#include <os/mynewt.h>
   +#include <syscfg/syscfg.h>
   +#include <mcu/stm32_hal.h>
   +#include <hal/hal_bsp.h>
   +#include "stm32l1xx_hal_pwr.h"
   +#include "stm32l1xx_hal_rtc.h"
   +
   +
   +extern void hal_rtc_enable_wakeup(uint32_t time_ms);
   +extern void hal_rtc_disable_wakeup(void);
   +extern uint32_t hal_rtc_get_remaining_time_before_wakeup(void);
   +extern void hal_rtc_init(RTC_DateTypeDef *date, RTC_TimeTypeDef *time);
   +
   +/* Put MCU  in lowest power stop state, exit only via POR or reset pin */
   +void
   +hal_mcu_halt() {
   +    /* all interupts and exceptions off */
   +    /* PVD off */
   +    /* power watchdog off */
   +    /* Be in lowest power mode forever */
   +    while (1) {
   +/*        HAL_PWR_EnterSTANDBYMode(); */
   +        /* TEST : don't lose RAM so can debug low powerness */
   +        HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
   +        /* debug breakpoint */
   +
   +    }
   +}
   +
   +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);
   +
   +    uint32_t reload_val;
   +
   +    reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
   +
   +    /* Set the system time ticker up */
   +    SysTick->LOAD = reload_val;
   +    SysTick->VAL = 0;
   +    SysTick->CTRL = 0x0007;
   +
   +    /* Set the system tick priority */
   +    NVIC_SetPriority(SysTick_IRQn, prio);
   +
   +    /*
   +     * Keep clocking debug even when CPU is sleeping, stopped or in standby.
   +     */
   +#if !MYNEWT_VAL(MCU_STM32F0)
   +    DBGMCU->CR |= (DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   +#else
   +    DBGMCU->CR |= (DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY);
   +#endif
   +
   +#if MYNEWT_VAL(OS_TICKLESS_RTC)
   +    /* initialise RTC for tickless code if required */
   +    hal_rtc_init(NULL, NULL);
   +#endif
   +
   +}
   +void
   +stm32_tickless_start(uint32_t timeMS) {
   +    /* Start RTC alarm for in this amount of time */
   +    hal_rtc_enable_wakeup(timeMS);
   +    /* Stop SYSTICK */
   +    NVIC_DisableIRQ(SysTick_IRQn);
   +    /*HAL_SuspendTick(); */
   +}
   +
   +void
   +stm32_tickless_stop(uint32_t timeMS) {
   +    /* disable RTC */
   +    hal_rtc_disable_wakeup();
   +
   +    /* reenable systick */
   +    NVIC_EnableIRQ(SysTick_IRQn);
   +    /*HAL_ResumeTick(); */
   +
   +    /* add asleep duration to tick counter : how long we should have slept for minus any remaining time */
   +    int asleep_ticks = os_time_ms_to_ticks32(timeMS - hal_rtc_get_remaining_time_before_wakeup());
   +    assert(asleep_ticks >= 0);
   +    os_time_advance(asleep_ticks);
   +}
   +
   +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) {
   +        HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   +        return;
   +    }
   +    /* begin tickless */
   +#if MYNEWT_VAL(OS_TICKLESS_RTC)
   +    stm32_tickless_start(durationMS);
   +#endif
   +
   +    switch (power_mode) {
   +    case HAL_BSP_POWER_OFF: {
   +        HAL_PWR_EnterSTANDBYMode();
   +        break;
   +    }
   +    case HAL_BSP_POWER_DEEP_SLEEP: {
   +        HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
   +        break;
   +    }
   +    case HAL_BSP_POWER_SLEEP: {
   +        HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   +        break;
   +    }
   +    case HAL_BSP_POWER_WFI: {
   +        HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
   +        break;
   +    }
   +    case HAL_BSP_POWER_ON:
   +    default: {
   +
   +        break;
   +    }
   +    }
   +
   +#if MYNEWT_VAL(OS_TICKLESS_RTC)
   +    /* exit tickless low power mode */
   +    stm32_tickless_stop(durationMS);
   +#endif
   +
    }
   \ No newline at end of file
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32l1xx/src/rtc_utils.c
   <details>
   
   ```diff
   @@ -1,340 +1,341 @@
   -/**
   - * 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. 
   - * 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 
   - * language governing permissions and limitations under the License.
   -*/
   -
   -/**
   - * Hal for rtc management
   - */
   -
   -#include <assert.h>
   -#include "os/mynewt.h"
   -
   -#include "hal/hal_gpio.h"
   -#include "stm32l1xx_hal_rtc.h"
   -#include "stm32l1xx_hal_pwr.h"
   -#include "bsp.h"
   -
   -// sub-second number of bits
   -#define N_PREDIV_S                                  10
   -
   -// Synchronous prediv
   -#define PREDIV_S                                    ( ( 1 << N_PREDIV_S ) - 1 )
   -
   -// Asynchronous prediv
   -#define PREDIV_A                                    ( 1 << ( 15 - N_PREDIV_S ) ) - 1
   -
   -// Sub-second mask definition
   -#define ALARM_SUBSECOND_MASK                        ( N_PREDIV_S << RTC_ALRMASSR_MASKSS_Pos )
   -
   -// RTC Time base in us
   -#define USEC_NUMBER                                 1000000
   -#define MSEC_NUMBER                                 ( USEC_NUMBER / 1000 )
   -
   -#define COMMON_FACTOR                               3
   -#define CONV_NUMER                                  ( MSEC_NUMBER >> COMMON_FACTOR )
   -#define CONV_DENOM                                  ( 1 << ( N_PREDIV_S - COMMON_FACTOR ) )
   -
   -
   -/*!
   - * \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 )
   -
   -/*!
   - * \brief Correction factors
   - */
   -#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 RTC_CLOCK_PRESCALER                         16.0f
   -#define DIVIDED_RTC_FREQUENCY                       (((float)LSE_VALUE)/RTC_CLOCK_PRESCALER)
   -#define DIVIDED_RTC_PERIOD                          (1.0f/DIVIDED_RTC_FREQUENCY)
   -#define MIN_RTC_PERIOD_SEC                          (1.0f*DIVIDED_RTC_PERIOD)
   -#define MAX_RTC_PERIOD_SEC                          (65535.0f*DIVIDED_RTC_PERIOD)
   -#define MIN_RTC_PERIOD_MSEC                         (1000.0f*MIN_RTC_PERIOD_SEC)
   -#define MAX_RTC_PERIOD_MSEC                         (1000.0f*MAX_RTC_PERIOD_SEC)
   -
   -/*!
   - * 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 = 
   -{
   -    .Instance = NULL,
   -    .Init = 
   -    { 
   -        .HourFormat = 0,
   -        .AsynchPrediv = 0,
   -        .SynchPrediv = 0,
   -        .OutPut = 0,
   -        .OutPutPolarity = 0,
   -        .OutPutType = 0
   -    },
   -    .Lock = HAL_UNLOCKED,
   -    .State = HAL_RTC_STATE_RESET
   -};
   -
   -
   -/**
   -  * @brief  This function handles  WAKE UP TIMER  interrupt request.
   -  * @retval None
   -  */
   -void RTC_WKUP_IRQHandler(void)
   -{
   -  HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
   -}
   -
   -/**
   -  * @brief  Wake Up Timer callback.
   -  * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   -  *                the configuration information for RTC.
   -  * @retval None
   -  */
   -void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
   -{
   -
   -}
   -
   -#ifdef RTC_ALARM_TEST
   -static RTC_AlarmTypeDef RtcAlarm;
   -#endif
   -
   -/**
   -  * @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)
   -{
   -    int rc;
   -
   -    NVIC_DisableIRQ(RTC_Alarm_IRQn);
   -    NVIC_DisableIRQ(RTC_WKUP_IRQn);
   -
   -
   -    RtcHandle.Instance            = RTC;
   -    RtcHandle.Init.HourFormat     = RTC_HOURFORMAT_24;
   -    RtcHandle.Init.AsynchPrediv   = PREDIV_A;  // RTC_ASYNCH_PREDIV;
   -    RtcHandle.Init.SynchPrediv    = PREDIV_S;  // RTC_SYNCH_PREDIV;
   -    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);
   -
   -    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,
   -        };
   -        
   -        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_EnableBypassShadow( &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);
   -    NVIC_EnableIRQ(RTC_Alarm_IRQn);
   -
   -    rc = HAL_RTC_SetAlarm_IT(&RtcHandle, &RtcAlarm, FORMAT_BIN);
   -#endif
   -
   -    HAL_RTC_DeactivateAlarm( &RtcHandle, RTC_ALARM_A );
   -    HAL_RTC_DeactivateAlarm( &RtcHandle, RTC_ALARM_B );
   -    HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
   -    
   -    assert(rc == 0);
   -}
   -
   -static uint32_t clk_srce_sel;
   -static uint16_t wkup_autoreload_timer;
   -
   -void hal_rtc_enable_wakeup(uint32_t time_ms)
   -{    
   -    /* Enable and set RTC_WKUP_IRQ */
   -
   -    //this NVIC setup doesn't work .... 
   -    //TODO : find out why ...
   -    //HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   -    //HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -    //HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   -
   -    
   -    NVIC_DisableIRQ(RTC_WKUP_IRQn);
   -
   -    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
   -
   -    /*
   -    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) )
   -    {
   -        clk_srce_sel = RTC_WAKEUPCLOCK_RTCCLK_DIV16;
   -        wkup_autoreload_timer = (uint32_t)((float)time_ms / (MIN_RTC_PERIOD_MSEC));
   -    }
   -    else if(time_ms < (uint32_t)(18 * 60 * 60 * 1000) )
   -    {   
   -        clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
   -        wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else if(time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)) )
   -    {   
   -        clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   -        wkup_autoreload_timer = (time_ms / 1000);
   -    }
   -    else{
   -        /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -        */
   -       clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   -       /* 
   -       for now, set the maximum possible time
   -       */
   -       wkup_autoreload_timer = 0xFFFF;
   -
   -    }
   -
   -    HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, (uint32_t)wkup_autoreload_timer, clk_srce_sel);
   -
   -    //NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   -    //NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   -    //NVIC_EnableIRQ(RTC_WKUP_IRQn);
   -
   -}
   -
   -uint32_t hal_rtc_get_remaining_time_before_wakeup(void)
   -{
   -    uint32_t time_ms, elapsed_time = HAL_RTCEx_GetWakeUpTimer(&RtcHandle);
   -
   -    if(clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16)
   -    {
   -        time_ms = (uint32_t)(((float)elapsed_time) * (MIN_RTC_PERIOD_MSEC));
   -    }
   -    else //if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS )
   -    {   
   -        time_ms = (elapsed_time * 1000);
   -    }
   -    /*
   -    else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   -    {   
   -        time_ms = (elapsed_time * 1000);
   -    }
   -    */
   -    /*
   -        TODO : setup wakeup with ALARM feature istead of wakeup     
   -       
   -    else{
   -        time_ms = (elapsed_time * 1000) + (36 * 60 * 60 * 1000);
   -
   -    }
   -    */
   -    
   -
   -    return time_ms;
   -}
   -
   -void hal_rtc_disable_wakeup(void)
   -{
   -    HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
   -    NVIC_DisableIRQ(RTC_WKUP_IRQn);
   -}
   +/**
   + * 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.
   + * 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
   + * language governing permissions and limitations under the License.
   + */
   +
   +/**
   + * Hal for rtc management
   + */
   +
   +#include <assert.h>
   +#include "os/mynewt.h"
   +
   +#include "hal/hal_gpio.h"
   +#include "stm32l1xx_hal_rtc.h"
   +#include "stm32l1xx_hal_pwr.h"
   +#include "bsp.h"
   +
   +/* sub-second number of bits */
   +#define N_PREDIV_S                                  10
   +
   +/* Synchronous prediv */
   +#define PREDIV_S                                    ((1 << N_PREDIV_S) - 1)
   +
   +/* Asynchronous prediv */
   +#define PREDIV_A                                    (1 << (15 - N_PREDIV_S)) - 1
   +
   +/* Sub-second mask definition */
   +#define ALARM_SUBSECOND_MASK                        (N_PREDIV_S << RTC_ALRMASSR_MASKSS_Pos)
   +
   +/* RTC Time base in us */
   +#define USEC_NUMBER                                 1000000
   +#define MSEC_NUMBER                                 (USEC_NUMBER / 1000)
   +
   +#define COMMON_FACTOR                               3
   +#define CONV_NUMER                                  (MSEC_NUMBER >> COMMON_FACTOR)
   +#define CONV_DENOM                                  (1 << (N_PREDIV_S - COMMON_FACTOR))
   +
   +
   +/*!
   + * \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)
   +
   +/*!
   + * \brief Correction factors
   + */
   +#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 RTC_CLOCK_PRESCALER                         16.0f
   +#define DIVIDED_RTC_FREQUENCY                       (((float)LSE_VALUE) / RTC_CLOCK_PRESCALER)
   +#define DIVIDED_RTC_PERIOD                          (1.0f / DIVIDED_RTC_FREQUENCY)
   +#define MIN_RTC_PERIOD_SEC                          (1.0f * DIVIDED_RTC_PERIOD)
   +#define MAX_RTC_PERIOD_SEC                          (65535.0f * DIVIDED_RTC_PERIOD)
   +#define MIN_RTC_PERIOD_MSEC                         (1000.0f * MIN_RTC_PERIOD_SEC)
   +#define MAX_RTC_PERIOD_MSEC                         (1000.0f * MAX_RTC_PERIOD_SEC)
   +
   +/*!
   + * 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 = {
   +    .Instance = NULL,
   +    .Init = {
   +        .HourFormat = 0,
   +        .AsynchPrediv = 0,
   +        .SynchPrediv = 0,
   +        .OutPut = 0,
   +        .OutPutPolarity = 0,
   +        .OutPutType = 0
   +    },
   +    .Lock = HAL_UNLOCKED,
   +    .State = HAL_RTC_STATE_RESET
   +};
   +
   +
   +/**
   + * @brief  This function handles  WAKE UP TIMER  interrupt request.
   + * @retval None
   + */
   +void
   +RTC_WKUP_IRQHandler(void)
   +{
   +    HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
   +}
   +
   +/**
   + * @brief  Wake Up Timer callback.
   + * @param  hrtc: pointer to a RTC_HandleTypeDef structure that contains
   + *                the configuration information for RTC.
   + * @retval None
   + */
   +void
   +HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
   +{
   +
   +}
   +
   +#ifdef RTC_ALARM_TEST
   +static RTC_AlarmTypeDef RtcAlarm;
   +#endif
   +
   +/**
   + * @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)
   +{
   +    int rc;
   +
   +    NVIC_DisableIRQ(RTC_Alarm_IRQn);
   +    NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +
   +
   +    RtcHandle.Instance            = RTC;
   +    RtcHandle.Init.HourFormat     = RTC_HOURFORMAT_24;
   +    RtcHandle.Init.AsynchPrediv   = PREDIV_A;  /* RTC_ASYNCH_PREDIV; */
   +    RtcHandle.Init.SynchPrediv    = PREDIV_S;  /* RTC_SYNCH_PREDIV; */
   +    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);
   +
   +    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,
   +        };
   +
   +        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_EnableBypassShadow( &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);
   +    NVIC_EnableIRQ(RTC_Alarm_IRQn);
   +
   +    rc = HAL_RTC_SetAlarm_IT(&RtcHandle, &RtcAlarm, FORMAT_BIN);
   +#endif
   +
   +    HAL_RTC_DeactivateAlarm( &RtcHandle, RTC_ALARM_A );
   +    HAL_RTC_DeactivateAlarm( &RtcHandle, RTC_ALARM_B );
   +    HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
   +
   +    assert(rc == 0);
   +}
   +
   +static uint32_t clk_srce_sel;
   +static uint16_t wkup_autoreload_timer;
   +
   +void
   +hal_rtc_enable_wakeup(uint32_t time_ms)
   +{
   +    /* Enable and set RTC_WKUP_IRQ */
   +
   +    /*
   +       this NVIC setup doesn't work ....
   +       TODO : find out why ...
   +       HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 6, 0);
   +       HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +       HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +     */
   +
   +
   +    NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +
   +    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
   +
   +    /*
   +       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)) {
   +        clk_srce_sel = RTC_WAKEUPCLOCK_RTCCLK_DIV16;
   +        wkup_autoreload_timer = (uint32_t)((float)time_ms / (MIN_RTC_PERIOD_MSEC));
   +    } else if (time_ms < (uint32_t)(18 * 60 * 60 * 1000))   {
   +        clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
   +        wkup_autoreload_timer = (time_ms / 1000);
   +    } else if (time_ms < (uint32_t)(MYNEWT_VAL(OS_IDLE_TICKLESS_MS_MAX)))   {
   +        clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   +        wkup_autoreload_timer = (time_ms / 1000);
   +    } else   {
   +        /*
   +           TODO : setup wakeup with ALARM feature istead of wakeup
   +         */
   +        clk_srce_sel = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
   +        /*
   +           for now, set the maximum possible time
   +         */
   +        wkup_autoreload_timer = 0xFFFF;
   +
   +    }
   +
   +    HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, (uint32_t)wkup_autoreload_timer, clk_srce_sel);
   +
   +    /*
   +       NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_WKUP_IRQHandler);
   +       NVIC_SetPriority(RTC_WKUP_IRQn, 10);
   +       NVIC_EnableIRQ(RTC_WKUP_IRQn);
   +     */
   +
   +}
   +
   +uint32_t
   +hal_rtc_get_remaining_time_before_wakeup(void)
   +{
   +    uint32_t time_ms, elapsed_time = HAL_RTCEx_GetWakeUpTimer(&RtcHandle);
   +
   +    if (clk_srce_sel == RTC_WAKEUPCLOCK_RTCCLK_DIV16) {
   +        time_ms = (uint32_t)(((float)elapsed_time) * (MIN_RTC_PERIOD_MSEC));
   +    } else   { /*if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_16BITS ) */
   +        time_ms = (elapsed_time * 1000);
   +    }
   +    /*
   +       else if(clk_srce_sel == RTC_WAKEUPCLOCK_CK_SPRE_17BITS )
   +       {
   +        time_ms = (elapsed_time * 1000);
   +       }
   +     */
   +    /*
   +        TODO : setup wakeup with ALARM feature istead of wakeup
   +
   +       else{
   +        time_ms = (elapsed_time * 1000) + (36 * 60 * 60 * 1000);
   +
   +       }
   +     */
   +
   +
   +    return time_ms;
   +}
   +
   +void
   +hal_rtc_disable_wakeup(void)
   +{
   +    HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
   +    NVIC_DisableIRQ(RTC_WKUP_IRQn);
   +}
   ```
   
   </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

[GitHub] [mynewt-core] brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-593347993
 
 
   > @brianwyld that's why I suggested it should be configured by either MCU or BSP. OS code can e.g. include some file from BSP where proper definitions can be expected. I did not look through the code to see what is the best way to do this now, perhaps we need to add something.
   
   So, I'm trying to find a place to set OS_IDLE_STACK_SIZE linked to the case where we want to ask the BSP to take actions pre/post entry to os_tick_idle() [to power off external peripherals for example]
   But this needs to be including a file from BSP as only the BSP knows what code its going to have to call (and hence what impact on the stack will be). 
   Is it legitimate to include <bsp_defs.h> from the BPSs in os.c after assert.h (so it can set OS_IDLE_STACK_SIZE to override the value in arch/common.h?)

----------------------------------------------------------------
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

[GitHub] [mynewt-core] andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-571654809
 
 
   > Hi Andrzej,
   > I haven't replicated my ISR stack since. However, I do get the stack overflow detection code asserting on the idle task.
   > This might be due to my extra code I call in os_tick_idle() which I'm updating to do low power management on STM32L1xx (tickless mode, BSP periph power down)...
   > I note commits in the master related to the stack check code by yourself in december which I don't have in this fork - are these to fix bugs in this check code?
   > thanks
   
   which commits you are referring to?

----------------------------------------------------------------
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

[GitHub] [mynewt-core] brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-571590832
 
 
   Commit of code for tickless mode on STM32L1xx using RTC wakeup.

----------------------------------------------------------------
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

[GitHub] [mynewt-core] brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml

Posted by GitBox <gi...@apache.org>.
brianwyld commented on issue #2138: Add possibility to configure idle task stack size in syscfg.yml
URL: https://github.com/apache/mynewt-core/pull/2138#issuecomment-571071984
 
 
   Hi Andrzej, 
   I haven't replicated my ISR stack since. However, I do get the stack overflow detection code asserting on the idle task.
   This might be due to my extra code I call in os_tick_idle()  which I'm updating to do low power management on STM32L1xx (tickless mode, BSP periph power down)... 
   I note commits in the master related to the stack check code by yourself in december which I don't have in this fork - are these to fix bugs in this check code? 
   thanks

----------------------------------------------------------------
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