OK
Fork of mbed-dev by
Revision 87:444eeba2d452, committed 2016-03-09
- Comitter:
- mbed_official
- Date:
- Wed Mar 09 18:00:10 2016 +0000
- Parent:
- 86:5334467ce342
- Child:
- 88:94022f3bcea9
- Commit message:
- Synchronized with git revision 6501de9044bc77f587f436f343d55a4fb0f5f8f9
Full URL: https://github.com/mbedmicro/mbed/commit/6501de9044bc77f587f436f343d55a4fb0f5f8f9/
[NUCLEO_F446RE] RTC+LSE+init
Changed in this revision
--- a/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_rcc.h Wed Mar 09 08:45:10 2016 +0000 +++ b/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_rcc.h Wed Mar 09 18:00:10 2016 +0000 @@ -1217,7 +1217,7 @@ #define RCC_BDCR_BYTE0_ADDRESS (PERIPH_BASE + RCC_BDCR_OFFSET) #define RCC_DBP_TIMEOUT_VALUE ((uint32_t)100) -#define RCC_LSE_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */ +#define RCC_LSE_TIMEOUT_VALUE ((uint32_t)5000) /* 5000 ms */ #define HSE_TIMEOUT_VALUE HSE_STARTUP_TIMEOUT #define HSI_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */
--- a/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device.h Wed Mar 09 08:45:10 2016 +0000 +++ b/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device.h Wed Mar 09 18:00:10 2016 +0000 @@ -48,6 +48,7 @@ #define DEVICE_SPISLAVE 1 #define DEVICE_RTC 1 +#define DEVICE_RTC_LSI 0 #define DEVICE_PWMOUT 1
--- a/targets/hal/TARGET_STM/TARGET_STM32F4/rtc_api.c Wed Mar 09 08:45:10 2016 +0000 +++ b/targets/hal/TARGET_STM/TARGET_STM32F4/rtc_api.c Wed Mar 09 18:00:10 2016 +0000 @@ -33,7 +33,9 @@ #include "mbed_error.h" +#if DEVICE_RTC_LSI static int rtc_inited = 0; +#endif static RTC_HandleTypeDef RtcHandle; @@ -42,8 +44,9 @@ RCC_OscInitTypeDef RCC_OscInitStruct; uint32_t rtc_freq = 0; - if (rtc_inited) return; +#if DEVICE_RTC_LSI rtc_inited = 1; +#endif RtcHandle.Instance = RTC; @@ -57,6 +60,7 @@ __HAL_RCC_BACKUPRESET_FORCE(); __HAL_RCC_BACKUPRESET_RELEASE(); +#if !DEVICE_RTC_LSI // Enable LSE Oscillator RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; /* Mandatory, otherwise the PLL is reconfigured! */ @@ -66,7 +70,11 @@ __HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSE); __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE); rtc_freq = LSE_VALUE; - } else { + } + else { + error("RTC error: LSE clock initialization failed."); + } +#else // Enable LSI clock RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured! @@ -80,10 +88,7 @@ __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI); // [TODO] This value is LSI typical value. To be measured precisely using a timer input capture rtc_freq = LSI_VALUE; - } - - // Check if RTC is already initialized - if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; +#endif // Enable RTC __HAL_RCC_RTC_ENABLE(); @@ -122,13 +127,19 @@ RCC_OscInitStruct.LSIState = RCC_LSI_OFF; RCC_OscInitStruct.LSEState = RCC_LSE_OFF; HAL_RCC_OscConfig(&RCC_OscInitStruct); - +#if DEVICE_RTC_LSI rtc_inited = 0; +#endif } int rtc_isenabled(void) { +#if DEVICE_RTC_LSI return rtc_inited; +#else + if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return 1; + else return 0; +#endif } /*