Unable to calibrate LSE RTC on GIGA R1 WiFi

Hi All,

This is a question directed to @facchinm (Arduino support) however if the community has input please chime in.

I have improved the accuracy of my LSE RTC by driving the LSE harder using the info from this topic Can I access the MEMS_32.768 to run RTC in LSE mode? - #11 by facchinm

The RTC is now running much better but is fast by a few seconds a day. I'd like to improve this using the HAL_RTCEx_SetSmoothCalib function to mask a few ticks over each 32s period.

Rather than trying various values, running for a few hours and then adjusting until I zero in on a setting that gets me close to a perfect 32768, I'm trying to use the LL_RTC_CAL facility to output a 1Hz pulse and then measure over the 32s period with a logic analyser.

As PC_13 is BOOT0 and inaccessible with the analyser, I'm attempting to remap to PB_2 (D47). However, I'm getting no output on the pin.

I notice there is no define for GPIO_AF0_RTC_OUT in stm32h7xx_hal_gpio_ex.h so it's possible that this is not available on the GIGA. However, this report Solved: RTC calibration oputput on STM32H7x with LL driver... - STMicroelectronics Community and the ref manual suggests the chip supports it.

This is the code I'm using to try to generate the signal

void setup() {
  GPIO_InitTypeDef GPIO_InitStruct = {0};

  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_RESET);

  GPIO_InitStruct.Pin = GPIO_PIN_2;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;  // also tried UP/DOWN
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  GPIO_InitStruct.Alternate = 0; // RTC_OUT
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  LL_RTC_DisableWriteProtection(RTC);
  LL_RTC_CAL_SetOutputFreq(RTC, LL_RTC_CALIB_OUTPUT_1HZ);
  LL_RTC_EnableOutRemap(RTC);  // to enable output on PB_2
  LL_RTC_EnableWriteProtection(RTC);  
}

void loop() {

}

It is quite possible that the GPIO pin settings are wrong as I'm not used to operating pins at this lower level.

Any guidance very much appreciated.
Thanks

Hi @facchinm I would very much appreciate your expert opinion wrt to this problem.
Thanks, Steve

Hi @steve9 ,
I got it working by using this.

pinMode(PB_2, OUTPUT); // before HAL_GPIO_Init to enable GPIOB clock

and

LL_RTC_EnableRefClock(RTC);
LL_RTC_CAL_SetPeriod(RTC, LL_RTC_CALIB_PERIOD_32SEC);
LL_RTC_CAL_SetOutputFreq(RTC, LL_RTC_CALIB_OUTPUT_1HZ);
LL_RTC_EnableOutRemap(RTC);  // to enable output on PB_2
LL_RTC_SetAlarmOutputType(RTC, RTC_OUTPUT_TYPE_PUSHPULL); // looks mandatory also for CAL output

(not very well documented on ST libraries, I must admit).
Let me know if it works for you!

@facchinm You are a superstar. It's working. As far as I'm concerned, you can take the rest of the day off. Many, many thanks.