cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to seperately use RTC with BLE?

TakenTheBacon
Associate III

Board: STM32WB55

Software: RTC and BLE

Hello,

I am trying to get a project set up on the above board. It needs BLE, USB and RTC seperately. I have the USB running with Bluetooth now thanks to a relatively recent post offering a means to fix the incompatability. Now, I need to get a date running on my RTC but as the init code of bluetooth uses the RTC timing, this does not seem possible (without of course adding a seperate clock chip into the project). 

So, is there a way to init BLE from another internal timing source?

Thanks

6 REPLIES 6
praiselittle
ST Employee

Hello, I don't know which code you are talking about but I was looking into one for bluetooth and it uses the wakeup timer (feature inside the RTC IP) for the timing which is independent of the date and time of the RTC (not 100% independant). Thus you can use RTC to set the date and time and still having Bluetooth working. 

If you have any question don't hesitate.

Have a nice one,

Thank you for your reply. I can set the date and time, but the clock will never increment, and any interrupts, manually set or not, from RTC will end up in the 'unrecognised interrupt ' while loop: 

/** startup_stm32wb55rgvx.s

* @brief This is the code that gets called when the processor receives an
* unexpected interrupt. This simply enters an infinite loop, preserving
* the system state for examination by a debugger.
*
*/
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler

I had checked the interrupt registers to confirm it was the RTC Wakeup IT that set the code into this state. So at the moment, it seems I cannot have a working dateTime whilst using STM32_WPAN

I seem to have it working now. The cause was the WakeUp interrupt firing after RTC initialising, where the interrupt had not actually been set in the code beforehand. This may be a bug?

praiselittle
ST Employee

Hello, 

Can you give me the code of the wakeup timer interruption and the rtc+wakeup intialization part ? In your program, does your wakeup timer trigger before you initialize the RTC (it shouldn't) ? 

I have a few possible ideas in mind. 

Thanks a lot and have a good one,

 

static void MX_RTC_Init(void)
{

/* USER CODE BEGIN RTC_Init 0 */
#ifndef DISABLE_RTC_RESET
/* USER CODE END RTC_Init 0 */

RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};
RTC_AlarmTypeDef sAlarm = {0};

/* USER CODE BEGIN RTC_Init 1 */

/* USER CODE END RTC_Init 1 */

/** Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = CFG_RTC_ASYNCH_PRESCALER;
hrtc.Init.SynchPrediv = CFG_RTC_SYNCH_PRESCALER;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}

/* USER CODE BEGIN Check_RTC_BKUP */

/* USER CODE END Check_RTC_BKUP */

/** Initialize RTC and set the Time and Date
*/
sTime.Hours = 0x12;
sTime.Minutes = 0x00;
sTime.Seconds = 0x0;
sTime.SubSeconds = 0x0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JUNE;
sDate.Date = 0x30;
sDate.Year = 0x23;
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}

/** Enable the Alarm A
*/
sAlarm.AlarmTime.Hours = 0x0;
sAlarm.AlarmTime.Minutes = 0x0;
sAlarm.AlarmTime.Seconds = 0x30;
sAlarm.AlarmTime.SubSeconds = 0x0;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_HOURS
|RTC_ALARMMASK_MINUTES;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmDateWeekDay = 0x1;
sAlarm.Alarm = RTC_ALARM_A;
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}

/** Enable the WakeUp
*/
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN RTC_Init 2 */
#else

hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = CFG_RTC_ASYNCH_PRESCALER;
hrtc.Init.SynchPrediv = CFG_RTC_SYNCH_PRESCALER;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}

RTC_AlarmTypeDef sAlarm = {0};
sAlarm.AlarmTime.Hours = 0x0;
sAlarm.AlarmTime.Minutes = 0x0;
sAlarm.AlarmTime.Seconds = 0x30;
sAlarm.AlarmTime.SubSeconds = 0x0;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_HOURS
|RTC_ALARMMASK_MINUTES;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmDateWeekDay = 0x1;
sAlarm.Alarm = RTC_ALARM_A;

//The Alarm will currently trigger an IT each time the seconds in RTC reach 30. So once per minute.
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}

/*
* WakeUp Timer needs to be set here. It will cause an IT regardless,
* but otherwise it will cause the CPU to hang indefinetly. Wierd ST bug.
*/
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK)
{
Error_Handler();
}
#endif
/* USER CODE END RTC_Init 2 */

}

 

I have the timer and alarm IT running okay now. However, if I do not set the wake up timer interrupt here, via CubeMX or otherwise, it will still trigger the interrupt, sending the code into a while loop for unexpected CPU ITs. I don't remember the exact details, but it was set in the appropriate register for RTC WakeUp found from datasheet. Whether or not this is as expected, I am not sure. Apologies for the late reply

With BLE, in Inc > app_conf.h, you should make sure the value of CFG_RTCCLK_DIVIDER_CONF is set to 16 and not 0, this will allow the RTC to run after being set/generated in main