Skip to main content
elias eliatto
Visitor II
January 31, 2018
Question

MX_RTC_Init STM32CubeMX 4.24 error

  • January 31, 2018
  • 9 replies
  • 3246 views
Posted on January 31, 2018 at 13:44

Hello! I've found a bug in RTC adjustment, when I used STM32CubeMX 4.24 for STM32L0.

MX_RTC_Init does not activate RTC because of HAL_RTCEx_BKUPRead/HAL_RTCEx_BKUPWrite 'guard'. For example, 4.23 version did not wrap HAL_RTCEx_SetWakeUpTimer_IT in HAL_RTCEx_BKUPRead/HAL_RTCEx_BKUPWrite 'guard'. Please, compare the attached files.

    This topic has been closed for replies.

    9 replies

    John Smith
    Associate II
    March 13, 2018
    Posted on March 13, 2018 at 13:27

    Hi

    arietto86

    As I see, `if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2){` line moved up and are called before `HAL_RTC_Init(&hrtc)` function. I think new version is better as it checks if the previous RTC data are saved correctly. This tells us that RTS battery are Ok and no need to initialize RTC again. Your RTC settings from previous MCU start will be saved. To change time you must to create custom function, may be based on MX_RTC_Init() and call it when you need to set time.

    John Smith
    Associate II
    March 13, 2018
    Posted on March 13, 2018 at 13:54

    rtc.c generate error when 'Generate peripheral initialization as a pair of '.c/.h' files' are set in Stm32CubeMx 4.0

    Got error when generated RTC initialisation file rtc.c.

    In Project -> Project Settings -> Code Generated

    Checkbox 'Generate peripheral initialization as a pair of '.c/.h' files per peripheral' are set.

    Part of rtc.c content:

    ...

    debuggg

    Expression usedDriverFlag is undefined on line 730, column 75 in ip_c.ftl.

    The problematic instruction:

    ----------

    ==> ${usedDriverFlag} [on line 730, column 73 in ip_c.ftl]

    in user-directive generateServiceCode [on line 1234, column 5 in ip_c.ftl]

    ...

    Full rtc.c file are attached

    For temporary fix I changed ip_c.ftl according to previous file version as shown below

    templates/ip_c.ftl | 8 +-------

    1 file changed, 1 insertion(+), 7 deletions(-)

    diff --git a/templates/ip_c.ftl b/templates/ip_c.ftl

    index 0406aa9..912c4ed 100644

    --- a/templates/ip_c.ftl

    +++ b/templates/ip_c.ftl

    @@ -727,16 +727,10 @@ ETH_TxPacketConfig TxConfig;

    [#if !ipName?contains('I2C')&& !ipName?contains('USB')] [#-- if not I2C --]

    [#if initService.clock??]

    [#if initService.clock!='none']

    - [#if FamilyName=='STM32F1' && ipName=='RTC']debuggg ${usedDriverFlag}

    - [#if usedDriverFlag?? && !usedDriverFlag?contains('LL')]

    + [#if FamilyName=='STM32F1' && ipName=='RTC']

    #t#tHAL_PWR_EnableBkUpAccess();

    #t#t/* Enable BKP CLK enable for backup registers */

    #t#t__HAL_RCC_BKP_CLK_ENABLE();

    - [#else]

    - #t#tLL_PWR_EnableBkUpAccess();

    - #t#t/* Enable BKP CLK enable for backup registers */

    - #t#tLL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_BKP);

    - [/#if]

    [/#if]

    #t#t/* ${ipName} clock enable */

    [#list initService.clock?split(';') as clock]

    Note that LL support are temporary removed.

    STM32F103C8T6

    Stm32CubeMx Version 4.0

    STM32CubeF1 Firmware Package V1.6.0 / 17-May-2017

    https://community.st.com/tags#/?tags=bug%20report

    https://community.st.com/tags#/?tags=cubemx%20v4.24

    https://community.st.com/tags#/?tags=workaround

    ________________

    Attachments :

    rtc.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxu8&d=%2Fa%2F0X0000000b20%2FPVuCKkpsSwU96a35JJ1PcWLvsd8YEP58jA6vCjRjhSg&asPdf=false
    ST Technical Moderator
    March 13, 2018
    Posted on March 13, 2018 at 14:33

    Hello

    smith.john

    ,

    The RTC error in code generation is fixed in the new CubeMX release.

    Could you please update the new version ofSTM32

    http://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-configurators-and-code-generators/stm32cubemx.html

    and checkif this issue is fixed for you.

    Best Regards,

    Imen

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
    John Smith
    Associate II
    March 14, 2018
    Posted on March 14, 2018 at 08:16

    Hi

    In Stm32CubeMx 4.0 rtc.c generate error are fixed and file are generated normally.

    But in rtc.c HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle) starts to use LL functions, HAL_RTC_MspDeInit() uses HAL functions as expected.

    void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle){ if(rtcHandle->Instance==RTC) { /* USER CODE BEGIN RTC_MspInit 0 */ /* USER CODE END RTC_MspInit 0 */ LL_PWR_EnableBkUpAccess(); /* Enable BKP CLK enable for backup registers */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_BKP); /* RTC clock enable */ __HAL_RCC_RTC_ENABLE(); /* USER CODE BEGIN RTC_MspInit 1 */ /* USER CODE END RTC_MspInit 1 */ }}void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle){ if(rtcHandle->Instance==RTC) { /* USER CODE BEGIN RTC_MspDeInit 0 */ /* USER CODE END RTC_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_RTC_DISABLE(); /* USER CODE BEGIN RTC_MspDeInit 1 */ /* USER CODE END RTC_MspDeInit 1 */ }} �?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

    Old (before 4.0) HAL_RTC_MspInit() uses HAL

    void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle){ if(rtcHandle->Instance==RTC) { /* USER CODE BEGIN RTC_MspInit 0 */ /* USER CODE END RTC_MspInit 0 */ HAL_PWR_EnableBkUpAccess(); /* Enable BKP CLK enable for backup registers */ __HAL_RCC_BKP_CLK_ENABLE(); /* RTC clock enable */ __HAL_RCC_RTC_ENABLE(); /* USER CODE BEGIN RTC_MspInit 1 */ /* USER CODE END RTC_MspInit 1 */ }}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

    Also CubeMx 4.0 Help -> Check for updates shows that no updates available. So I downloaded CubeMx 4.0 from ST site.

    Nawres GHARBI
    ST Technical Moderator
    May 2, 2018
    Posted on May 02, 2018 at 12:16

    hello,

    will be fixed next release