cancel
Showing results for 
Search instead for 
Did you mean: 

Cubemx 4.4.0 rtc bug

totti001
Associate II
Posted on October 17, 2014 at 21:30

Hello everybody!

I found a bug with the new cubemx and rtc clock code generation. So I set te RTC paramters at cubemx, the first what I see that the sync predivider limited to max 255, but this is a 16bit variable in the mikrocontroller. So second bug, that the generated code:

/**
******************************************************************************
* File Name : RTC.c
* Date : 17/10/2014 21:20:24
* Description : This file provides code for the configuration
* of the RTC instances.
******************************************************************************
*
* COPYRIGHT(c) 2014 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include ''rtc.h''
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
RTC_HandleTypeDef hrtc;
/* RTC init function */
void MX_RTC_Init(void)
{
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
/**Initialize RTC and set the Time and Date 
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
sTime.Hours = 0;
sTime.Minutes = 0;
sTime.Seconds = 0;
sTime.SubSeconds = 0;
sTime.TimeFormat = RTC_HOURFORMAT12_AM;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 1;
sDate.Year = 0;
/**Enable the WakeUp 
*/
}
void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
{
if(hrtc->Instance==RTC)
{
/* USER CODE BEGIN RTC_MspInit 0 */
/* USER CODE END RTC_MspInit 0 */
/* Peripheral interrupt init*/
HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
/* USER CODE BEGIN RTC_MspInit 1 */
/* USER CODE END RTC_MspInit 1 */
}
}
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
{
if(hrtc->Instance==RTC)
{
/* USER CODE BEGIN RTC_MspDeInit 0 */
/* USER CODE END RTC_MspDeInit 0 */
/* Peripheral interrupt Deinit*/
HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
/* USER CODE BEGIN RTC_MspDeInit 1 */
/* USER CODE END RTC_MspDeInit 1 */
}
} 
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

What we see, that te MX_RTC_Init function doesn't do anything. What can I do this sutiation? I use stm32f407ig controller and the latest cubemx softwares. Thanks
4 REPLIES 4
stm32cube-t
Senior III
Posted on November 13, 2014 at 17:39

Hello,

There is a known MX issue (#

272065

will be fixed in 4.6).

Can you please add the following macro to the

HAL_RTC_MspInit

() function:

__HAL_RCC_RTC_ENABLE();

Regarding the Max presync divider value, thank you for pointing this out.

Best regards

totti001
Associate II
Posted on November 14, 2014 at 12:48

Thank you very much. Now the RTC is working well.

One thing about RTC init. I think it will be best, if the RTC init is checking the reset flag before init the time and date to 0.

totti001
Associate II
Posted on November 17, 2014 at 13:37

I've found a new error with RTC. I have an application which uses RTC. I configured a wake up to feed a watchdog. An other function that I can stop the device. I this function I stop all of the tasks, and take device to stop mode. Only the RTC wake up and a user switch can wake up. The requirement that the user need to press the button for 3 seconds to start the device. I wrote the code. It is working well with standard library 1.3.0. But with stm32cube doesn't. The problem is when I get the current seconds, it is working only once. After that all of the readings get the same value. So the elapsed time 0 forever.

What is the problem?

while(Stop_mode == ENABLE /*&& (button_Pressed != ENABLE)*/)
{
/* Disable systick */
Systick_disable();
//Display_BacklightOff();
/* Enter Stop Mode */
//HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
/* Return from stop mode*/
volatile uint8_t start_time;
volatile uint8_t act_time;
/* Get the current time */
HAL_RTC_GetTime(&hrtc,&RTC_TimeStructure,FORMAT_BIN);
start_time = RTC_TimeStructure.Seconds;
/* Read the wake-up pin state*/
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0))
{
/* Get the current time */
HAL_RTC_GetTime(&hrtc,&RTC_TimeStructure,FORMAT_BIN);
act_time = RTC_TimeStructure.Seconds;
/* Calculate the elapsed time*/
volatile int8_t elapsed_time = (int8_t)(act_time - start_time);
/* If start time bigger than act time, add 60 to elapsed time*/
if(elapsed_time < 
0
)
{
elapsed_time+=60;
}
/* If the waiting time is reached, exit from stop mode*/
if(elapsed_time > STOP_MODE_WAIT_TIME)
{
Power_Exit_Stopmode();
break;
}
}
}

totti001
Associate II
Posted on November 17, 2014 at 17:29

I've compared the stm32cube and the standard library RTC_Get_Time functions.

One difference in the cube file is this:

sTime->SubSeconds = (uint32_t)(hrtc->Instance->SSR);

If I comment this line the program is working. Maybe the frequently reading is the bug.