How to enable the Real Time Clock

I am trying to use the Real Time Clock of the GD32VF103CB. The first step is just to enable it. I see from the User Manual that after reset the Backup Domain Control register RCU_BDCTL contains 0x18, which the manual says is the default value. But those bits fall in a ‘reserved’ area so I do not know what that means.

The bits I want on are 0x8101, the RTC enable bit, select source LXTAL, and bit 0x01, the LXTALEN enable bit.

I see that bit 0x10000 will force the backup domain to reset. I also see that the Power Management Control Register PMU_CTL has a bit BKPWEN 0x100 that enables writing to the Backup Domain. It would seem that I need to set this bit first. But all my attempts to set it fail. (I am doing this through the Mecrisp-Quintus FORTH language.) I write 0x0100 to PMU_CTL then read it back, getting 0x0000 again.

What is the sequence of operations to enable the RTC?

I have discovered that I need to enable the ‘interface clocks’ in RCU_APB1EN for both the PMU and Backup units before attempting to write to them. Then I can set BPKWEN in PMU_CTL. And Then I need to set the CMF big in RTC_CTL to put it into Configuration Mode. Only then can I change RTC settings. And then clear the CMF flag.
First attempt did not work - I may still be missing somehting.

2 Likes