Hi,
I would like to use Core and LCD module as a clock, so I’m looking for the way, how I can store current time/date. In SDK, there is a bc_rtc driver, but is blank. So my question is, whether there is RTC available on Core, or I have to use external module, or less precise way without RTC.
In future, I would like use Turris as a source of exact time, so less precise mode should be not an issue. But having RTC makes it easier
yes, the RTC subsytem with 32kHz crystal is running for the needs of scheduler, but there is no implementation yet for date/time.
For now it should be possible to use STM32 HAL library, which is in the BigClown SDK, hovewer we try to avoid these libraries because of the code size and implement the functionality ourselves.
There is only small issue that you need to pass the RTC_HandleTypeDef parameter which has to have set the Instance item in the structure. Or you can search for these functions and implement them without the need of the RTC_HandleTypeDef structure. You can access directly the date register with only RTC->DR.
We try to implement this part in the SDK, it is not the first request and for future crypto we would need know the time anyway.
Let us know if this helped you or you would need some more help.
Martin
I’ve discovered it is quite easy to work with the RTC. It is decribed here:
Date and time are stored as BCD(binary coded decimals) in two 32bit registers:
DR:=ddwwmmyy
TR:=00HHMMSS
Reading them is simple. You have to include file: #include <stm32l0xx.h>
and then you are able to read time register:
RTC->TR;
and date register
RTC->DR;
But writing these registers is tricky, because they are write protected. It has to be done like this:
// Disable write protection
RTC->WPR = 0xca;
RTC->WPR = 0x53;
// Enable initialization mode, this stops the clock
RTC->ISR |= RTC_ISR_INIT;
// Wait for RTC to be in initialization mode...
while ((RTC->ISR & RTC_ISR_INITF) == 0)
{
continue;
}
// Write the values
RTC->DR = date;
RTC->TR = time;
// Exit from initialization mode
RTC->ISR &= ~RTC_ISR_INIT;
// Enable write protection
RTC->WPR = 0xff;
Contents of earlier version of this file were moved to bc_module_core.c, mainly to function _bc_module_core_init_rtc. That is the place, where I got inspiration for code I posted earlier