2019-03-06 04:28 AM
Please, answer was anyone trying to use RTC with the G071RB microcontroller? I am powerless now. The code generated by cube does not initialize RTC. I checked the entire initialization procedure if it is consistent with the documentation. Everything is correct and does not seem to be a mistake in HAL. The problem for me in the RTC_EnterInitMode function is the line SET_BIT (hrtc-> Instance-> ICSR, RTC_ICSR_INIT) ;. The INIT bit and the INITF flag are not set so that RTC does not enter the initialization mode. I am asking for an answer because the problem is not in my code only in the code generated by the cube. Is RTC initializing for you or is the problem in my microcontroller? I will add that there is no difference which source of RTC clock will be chosen.
Solved! Go to Solution.
2019-03-07 02:13 AM
Hello @wuio ,
I think RTC APB clock has not been enabled.
For this purpose __HAL_RCC_RTCAPB_CLK_ENABLE(); should be called HAL_RTC_MspInit(), as shown in various examples available in the STM32CubeG0 firmware package.
/**
* @brief RTC MSP Initialization
* This function configures the hardware resources used in this example
* @param hrtc: RTC handle pointer
* @retval None
*/
void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
{
if(hrtc->Instance==RTC)
{
/* USER CODE BEGIN RTC_MspInit 0 */
__HAL_RCC_RTCAPB_CLK_ENABLE();
/* USER CODE END RTC_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_RTC_ENABLE();
/* USER CODE BEGIN RTC_MspInit 1 */
/* USER CODE END RTC_MspInit 1 */
}
}
Kind Regards,
Imen
2019-03-06 06:43 AM
Hello @wuio ,
Please have a look to the STM32G071xx Errata sheet and check if you have the same conditions as described in this device errata and your issue is related to the know limitations.
Kind Regards,
Imen
2019-03-06 07:05 AM
oczywiście czytałem to już i niestety u mnie bit RSF ciągle jest w stanie niskim podobnie jak bit BYPSHAD. Mam jeszcze jedeną dziwną rzecz a mianowicie pomimo braku włączonego wyjścia sygnały zegarowego na pin PA2 ten sygnał ciągle się tam znajduje. Po wyłączeniu w Cube funkcji LSCO na pinie PA2 znajduje sie 32kHz. Dopiero ustawienie tego pinu jako wyjście powoduje zniknięcie tego sygnału. Nawet użycie go jako SPI1_MOSI nic nie zmienia. Co bardzo dziwne. Czy słyszała Pani o takim przypadku?
2019-03-06 07:06 AM
Of course, I have read this already and unfortunately in my case the RSF bit is still in a low state, similar to the BYPSHAD bit. I have one more strange thing: in spite of the lack of the clock signal output on PA2 pin, this signal is still there. After turning off the LSCO function in the Cube, the PA2 pin has 32kHz. Only setting this pin as an output causes the disappearance of this signal. Even using it as SPI1_MOSI does not change anything. Which is very strange. Have you heard of such a case?
2019-03-07 02:13 AM
Hello @wuio ,
I think RTC APB clock has not been enabled.
For this purpose __HAL_RCC_RTCAPB_CLK_ENABLE(); should be called HAL_RTC_MspInit(), as shown in various examples available in the STM32CubeG0 firmware package.
/**
* @brief RTC MSP Initialization
* This function configures the hardware resources used in this example
* @param hrtc: RTC handle pointer
* @retval None
*/
void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
{
if(hrtc->Instance==RTC)
{
/* USER CODE BEGIN RTC_MspInit 0 */
__HAL_RCC_RTCAPB_CLK_ENABLE();
/* USER CODE END RTC_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_RTC_ENABLE();
/* USER CODE BEGIN RTC_MspInit 1 */
/* USER CODE END RTC_MspInit 1 */
}
}
Kind Regards,
Imen
2019-03-07 03:07 AM
Thank you Imen DAHMEN for that matter. Please tell me is nobody testing this software at STmicroelectronics? RTC had no right to act ... By the way, in the documentation there is also no word that to read the time, the date should be read at the same time, and that's the way it is.
2019-04-08 01:35 AM
For the future, STM32G0x requires setting of four bits for RTC to work:
PWR->CR1 |= PWR_CR1_DBP;
RCC->APBENR1 |= RCC_APBENR1_PWREN | RCC_APBENR1_RTCAPBEN;
RCC->BDCR |= RCC_BDCR_RTCEN;
ST, you have a problem with the documentation, there is no information about the RTCAPBEN bit:
RTC domain access
After a system reset, the RTC domain (RTC registers and backup registers) is protected
against possible unwanted write accesses. To enable access to the RTC domain, proceed
as follows:
1. Enable the power interface clock by setting the PWREN bits of the APB peripheral
clock enable register 1 (RCC_APBENR1).
2. Set the DBP bit of the Power control register 1 (PWR_CR1) to enable access to the
RTC domain.
3. Select the RTC clock source in the RTC domain control register (RCC_BDCR).
4. Enable the RTC clock by setting the RTCEN bit in the RTC domain control register
(RCC_BDCR)."
Doc. RM0444, page 101, section 4.1.2 (Battery backup of RTC domain).
Please fix it.
Best regards,
Adrian
2022-06-14 09:12 AM
I have something I wanted to add, because I ran into this problem, too.
In my case RCC_BDCR_RTCEN would have been set in HAL_RTC_MspInit but it stayed zero.
The reason was that RCC_BDCR_BDRST was set (backup domain reset). But I never set this.
My fix: __HAL_RCC_BACKUPRESET_RELEASE(); at the start of HAL_RTC_MspInit
Did someone encounter this issue before, can RCC_BDCR_BDRST be set somehow when a lot of whatchdog resets occure?
2023-07-04 04:24 AM
Dear Imen,
Today the 4th of July 2023 the RM0444 rev 5 is still missing that crucial piece of information about RTCAPBEN.
Even in the AN4759 there are no mention of it.
Please can you ask for a revision of the RM0444 in order to fix it ? Thanks.
Have a nice day,
Kraal
2023-07-04 10:23 AM
It's not just the 'G0.
JW