Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

STM32 RTC Hardware Support & User Interface for Watch and Calendar #128

Merged
merged 15 commits into from
Aug 12, 2021

Conversation

northskysl
Copy link
Contributor

Here is an implementation of the STM32 RTC Hardware Support for the retro-go Game and Watch fork. The time can be viewed when pressing the "TIME" button on the main retro-go menu and by selecting Time or Date the aforementioned can be adjusted.

northskysl and others added 10 commits August 9, 2021 14:25
Added a menu to view and configure RTC parameters. It is activated by pressing 'TIME' button in retro-go main menu.
Enable LSE oscillator and enable it as RTC clock source. Additionally enable CRS Sync LSE.
Added time display to RTC menu and also modified RTC initialization code so that it does not set the RTC date and time. Assuming that a fresh RTC has sensible values.
Added date display to time menu
Fixed predivs for LSE clock
Consolidate all RTC functions to rg_rtc. So far getters have been implemented only.
Setters for Time have been implemented and Time setup has been added into the UI to use them.
Date setup with callbacks added
Modified the time menu to display and update in real time.
@kbeckmann
Copy link
Owner

Github doesn't let me comment on unchanged lines, but I think this should be changed as well:

RCC_OscInitStruct.LSIState = RCC_LSI_ON;

to

RCC_OscInitStruct.LSIState = RCC_LSI_OFF;

@northskysl
Copy link
Contributor Author

Need to test with LSI OFF but I would assume it is ok to turn it off too! It works with both LSI and LSE active though, at least in my testing.

Unix time is returned as a 64-bit time_t. Casting to uint32_t will yield time in seconds since 1st Jan 1970.
@northskysl
Copy link
Contributor Author

Did a quick test with RCC_LSI_OFF. Seems to work fine! Clock runs and a game runs.

Fixing warnings about wrong setter return type.
Missed the .h while updating return types of setters.
Add a nicer year display
@kbeckmann
Copy link
Owner

There is a quite annoying migration issue here.

If I go from the main branch to this directly, from a running target, HAL_RCC_OscConfig(&RCC_OscInitStruct) will return an error. However, if I cold boot, it will resolve itself. Alternatively it works if I set RCC_OscInitStruct.LSIState = RCC_LSI_ON;.

This is normally not a problem if you have an open unit and can power cycle easily, but I think many have made mods where they can keep the unit closed.

Not sure what the best way to proceed here, maybe setting RCC_OscInitStruct.LSIState = RCC_LSI_ON;. I am not entirely sure what that means though, if that means that both LSI and LSE are running but that LSE is actually being used for time keeping.

@northskysl
Copy link
Contributor Author

I did run with both on and did not see issues from software perspective. It does mean that LSI is also on and that could have a negative impact on the power consumption of the device. How big of an impact, I do not know, but it does consume some extra power to have both LSI and LSE on at the same time.

@kbeckmann
Copy link
Owner

Ideally we should measure with a µA meter as it may impact standby performance. I don't think it'll be that bad in any case, so let's just set RCC_LSI_ON for now.

This should fix an issue with DACs that causes Brightness control not to work.
@northskysl
Copy link
Contributor Author

Added a commit to restore the LSI bits

@kbeckmann kbeckmann merged commit d9542eb into kbeckmann:main Aug 12, 2021
@northskysl northskysl deleted the rtc branch August 12, 2021 13:34
@kbeckmann kbeckmann linked an issue Aug 14, 2021 that may be closed by this pull request
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use external 32.728kHz crystal (RCC_LSE) for RTC
2 participants