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?

20 REPLIES 20

OK so if you read out the RTC registers, what exactly do you see in those bits, in all three cases?

JW

PK.2
Associate II

I guess i see what i expect.

Case 1

0693W000001rdzSQAQ.png

Case 20693W000001rdz8QAA.png

Case 30693W000001rdzhQAA.png

Indeed looks logical.

Pity you did not show us the registers when the external 1Hz signal is connected to PC13/RTC_TS - according to your description, at least in case 2 that should have effect on the registers.

I wonder, whether in case 3 that does or does not have similar effect on the registers.

[case 3]

> The signal at the TS input has only a voltage of 1.4 volts.

I don't understand. Isn't that your external 1Hz signal? How is it different from case 2?

JW

PK.2
Associate II

The external signal is the same in case 2 and case 3.

The only difference between case 2 and case 3 is that in case 2 only the RTC_TS is configured (see TSE and TSIE bit).

In case 3 RTC_Calib_Out is also active (see COE and COSEL bit).

In case 3 the voltage is 1.4 V instead of 3.3 V. That's the question. This happens when PB2 is active, but why does it change PC13.

This sounds like PC13 is turned to output, in spite of TSE bit being set.

Sounds much like a hardware bug.

@Imen DAHMEN​  , can this please be checked? Thanks.

Jan

PK.2
Associate II

Thank you, @Community member​ .

Here is the complete code generated from the CubeMx.

I wouldn't hold my breath and would work out of the premise that the given combination is simply unavailable. Maybe combination of retaining the tamper function and toggling a pin in RTC interrupt might provide something close to what you intended?

JW

PK.2
Associate II

I wanted to use the RTC_TS for time synchronization because a rising edge triggers an interrupt and at the same time the current time is transferred to the TS register.

With the timestamp I would know how many sub-seconds the RTC of the L4 deviates and could correct this with the shift function.

void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc)
{
  HAL_RTCEx_SetSynchroShift(hrtc, RTC_SHIFTADD1S_RESET, 255 - hrtc->Instance->TSSSR + 1);
 
  HAL_RTCEx_DeactivateTimeStamp(hrtc);
  HAL_RTCEx_SetCalibrationOutPut(hrtc, RTC_CALIBOUTPUT_1HZ);
}

Example

  HAL_RTCEx_SetCalibrationOutPut(&hrtc, RTC_CALIBOUTPUT_1HZ);
  HAL_Delay(3500);
  HAL_RTCEx_DeactivateCalibrationOutPut(&hrtc);
  HAL_Delay(3500);
  HAL_RTCEx_SetTimeStamp_IT(&hrtc, RTC_TIMESTAMPEDGE_RISING, RTC_TIMESTAMPPIN_DEFAULT);

0693W000001s3iXQAQ.png

The blue signal is the calibration output and the red signal is the 1 Hz clock with the RTC is to be synchronized.

So that I get an RTC_TS interrupt, I always have to switch off the caliboutput. If the COE bit is set, as you said, the RTC_TS may be configured as an output.

PK.2
Associate II

@Community member​ 

I have assigned PB2 with RTC_Caliboutput and PC13 as exti input with rising edge.

PC13 cannot be used. The input signal is always 1.4 V.