RP2040 CLOCK GPIN0 selection

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
adupu044
Posts: 2
Joined: Wed Mar 02, 2022 3:01 pm

RP2040 CLOCK GPIN0 selection

Post by adupu044 » Wed Mar 02, 2022 3:26 pm

Hi,

I would like to use the F8 function of GPIO20 which is Clock GPIN0. Apparently this pin can be used to take in a clock and be used to time the internal RTC. Want I would like to implement is to use an external battery backed RTC such as the DS3231 to store the time when powered off. But instead of having to continuously read the RTC over I2C to get the time I would have the external RTC output a ref clock signal to time the internal RP2040 RTC off of the GPIO20 pin.

Questions I have:

1. how do you access internal RP2040 control registers from MicroPython?

Example need to configure clock reg below to select GPIN0 (GPIO20) as the source.
CLOCKS: CLK_RTC_CTRL Register
Offset: 0x6c

2. Any ideas as to what FUNCSEL value is for Clock GPIN0? The table doesn't really say .

thanks!

adupu044
Posts: 2
Joined: Wed Mar 02, 2022 3:01 pm

Re: RP2040 CLOCK GPIN0 selection

Post by adupu044 » Thu Mar 03, 2022 7:16 pm

After some digging around I found you can use: machine.mem32[Address] to read registers. I use hex(machine.mem32[0x4000806c]). Also need to pay attention to the datasheet for the register sizes. In this case it's a 32 bit access. The results from the command clip the leading 0's.

Other notes.
Base clock address is located here:0x40008000
CLK_RTC_CTRL is offset 0x6C
CLK_RTC_DIV is offset 0x70
RTC source (default looks to be 0x0 → clksrc_pll_usb)

Haven't tried changing it yet. Will update once I figure out the sequences.

Post Reply