cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4+: RTC Calib Out (PB2) and RTC Timestamp Input (PC13) at the same time?

PK.2
Associate II

Hello everybody,

i have a problem with the RTC Calib Out (1Hz) on PB2 and TimeStamp Input PC13 (Board: NUCLEO-L4R5ZI).

  • PPS (1 Hz clock) should be on PB2 (RTC_Calib_Out) for time synchronization with other chips.
  • PC13 should be configured as TimeStamp Input for events (e.g. 1 Hz)

Calib Out on PB2

With the following code works the calib out pin fine.

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.OutPutRemap = RTC_OUTPUT_REMAP_POS1;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
HAL_RTC_Init(&hrtc);
 
HAL_RTCEx_SetCalibrationOutPut(&hrtc, RTC_CALIBOUTPUT_1HZ);
HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput)
{
  __HAL_LOCK(hrtc); 
  hrtc->State = HAL_RTC_STATE_BUSY;
  __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 
 
  hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL;   /* Clear flags before config */
  hrtc->Instance->CR |= (uint32_t)CalibOutput;   /* Configure the RTC_CR register */
 
  __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc); // ((hrtc)->Instance->CR |= ((0x1UL << (23U))))
 
  __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);   
  hrtc->State = HAL_RTC_STATE_READY; 
  __HAL_UNLOCK(hrtc);
 
  return HAL_OK;
}

0693W000001rZpTQAU.png

TimeStamp Input on PC13

Is only only the TimeStamp function configured, then it works also as expected. Blue is a clock with e.g. 1 Hz and the red signal is a gpio which will be toggled by the TimeStamp callback function. It works also as expected.

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.OutPutRemap = RTC_OUTPUT_REMAP_POS1;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
HAL_RTC_Init(&hrtc);
 
HAL_RTCEx_SetTimeStamp_IT(&hrtc, RTC_TIMESTAMPEDGE_RISING, RTC_TIMESTAMPPIN_DEFAULT); // default PC13
HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
{
  uint32_t tmpreg;
 
  __HAL_LOCK(hrtc);
  hrtc->State = HAL_RTC_STATE_BUSY;
 
  /* Get the RTC_CR register and clear the bits to be configured */
  tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
 
  tmpreg |= TimeStampEdge;
 
  /* Disable the write protection for RTC registers */
  __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
 
  /* Configure the Time Stamp TSEDGE and Enable bits */
  hrtc->Instance->CR = (uint32_t)tmpreg;
 
  __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
 
  /* Enable IT timestamp */
  __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc, RTC_IT_TS);
 
  /* RTC timestamp Interrupt Configuration: EXTI configuration */
  __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
  __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE();
 
  __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  hrtc->State = HAL_RTC_STATE_READY;
  __HAL_UNLOCK(hrtc);
 
  return HAL_OK;
}

0693W000001rciVQAQ.png

Both together (doesn't work)

If I try both together, the calib out will work, but I won't get any TimeStamp events anymore. The signal at the TS input has only a voltage of 1.4 volts. Only the COE and COSEL bits are changed by the pin calib out. What happens here?

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.OutPutRemap = RTC_OUTPUT_REMAP_POS1;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
HAL_RTC_Init(&hrtc);
 
HAL_RTCEx_SetTimeStamp_IT(&hrtc, RTC_TIMESTAMPEDGE_RISING, RTC_TIMESTAMPPIN_DEFAULT); // default PC13
 
HAL_RTCEx_SetCalibrationOutPut(&hrtc, RTC_CALIBOUTPUT_1HZ);

0693W000001rZqHQAU.png

Can someone explain what changes to PC13 when the COE bit is set to 1?

This discussion is locked. Please start a new topic to ask your question.
20 REPLIES 20

And what's in the RTC registers now?

JW

PK.2
Associate II

Same as in case 2

0693W000001s7mFQAQ.png

0693W000001s7oyQAA.png

So, you set RTC registers as in case 2, and input signal is OK? And then when you change PC13 GPIO_MODER from the default Analog to In, the input signal suddenly changed amplitude, correct?

JW

PK.2
Associate II

Yes i set the RTC registers as in case 2.

The input signal is always a 1 Hz clock with amplitude 3.3 V.

The amplitude changes when COE bit set. If this bit isn't set, then the PC13 works as expected as normal gpio exti or as RTC_TS (see case 1). Always when the COE bit is set, the amplitude of PC13 is 1.4 V.

I guess, when the RTC COE bit is set, the PC13 gpio registers are ignored.

OK, so the bug is, that if RTC_CR.COE=1 and RTC_OR.RTC_OUT_RMP=1, PC13 is *not* controlled by GPIO as it should, and is turned to output.

@Vincent Onde​  , this appears to be a genuine hardware bug, can you please have a look at it.

JW

Piranha
Chief II

Few days ago while calibrating RTC I discovered exactly the same thing. When COE=1 and RTC_OUT_RMP=1 even with OSEL=00b, GPIO settings for PC13 are overriden and it is switched to output with value 0.

I can confirm this behavior on STM32L431CBT6 and STM32L433CCU6.

Thanks for confirming this.

JW

Vincent Onde
ST Employee

​Hello @Community member​,

Thanks for reporting this. I'll have it circulated internally.

Best regards,

Vincent

Thanks, Vincent.

Jan

Imen.D
ST Employee

Hello,

Sorry for the delay in getting back to you.

I confirm this issue and the team is currently working on updating the Errata sheets .

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen