kbeckmann / game-and-watch-retro-go

Emulator collection for Nintendo® Game & Watch™
GNU General Public License v2.0
440 stars 133 forks source link

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

Closed northskysl closed 3 years ago

northskysl commented 3 years ago

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.

kbeckmann commented 3 years ago

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 commented 3 years ago

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.

northskysl commented 3 years ago

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

kbeckmann commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.

northskysl commented 3 years ago

Added a commit to restore the LSI bits