V10lator
Posts: 39
Joined: Wed Jul 07, 2021 11:18 am

DS3231 interrupt pin?

Sun Sep 26, 2021 9:34 am

Chrony sais it can't use the RTC:
Could not enable RTC interrupt : Invalid argument
So what interrupt is missing? According to https://github.com/torvalds/linux/blob/ ... ds3231.txt we should be able to get alarm interrupts as well as square-wave outputs/interrupts.

Also how to specify the GPIO pin listening for the interrupt / what's the default? I can't find any informations about that online.

Lastly why is the RPI device tree overlay for the RTC completely missing the #clock-cells attribute?

V10lator
Posts: 39
Joined: Wed Jul 07, 2021 11:18 am

Re: DS3231 interrupt pin?

Sun Sep 26, 2021 5:04 pm

V10lator wrote:
Sun Sep 26, 2021 9:34 am
Chrony sais it can't use the RTC:
Could not enable RTC interrupt : Invalid argument
So what interrupt is missing? According to https://github.com/torvalds/linux/blob/ ... ds3231.txt we should be able to get alarm interrupts as well as square-wave outputs/interrupts.

Also how to specify the GPIO pin listening for the interrupt / what's the default? I can't find any informations about that online.

Lastly why is the RPI device tree overlay for the RTC completely missing the #clock-cells attribute?
//EDIT: After hacking the driver ( https://github.com/V10lator/rpi-rt-linu ... c-ds1307.c ) the clock outputs a interrupt signal on the SQW pin. It's just way faster than 1 Hz and I don't know why.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4109
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: DS3231 interrupt pin?

Mon Sep 27, 2021 8:04 am

The dt-bindings for DS3231 that you linked to says that "interrupts" is an optional property. You would probably need to add something like:

Code: Select all

	interrupt-parent = <&gpio>;
	interrupts = <25 2>. // 25 = gpio number, 2 = falling edge
The "#clock-cells" property is only useful if some other Device Tree node is going to refer to it, which is both unusual and non-trivial for an RTC declared in an overlay. How would you use it?

If you want something else in the i2c-rtc overlay to support DS3231 then report it at github.com/raspberrypi/linux/issues.

V10lator
Posts: 39
Joined: Wed Jul 07, 2021 11:18 am

Re: DS3231 interrupt pin?

Mon Sep 27, 2021 9:00 am

PhilE wrote:
Mon Sep 27, 2021 8:04 am
The dt-bindings for DS3231 that you linked to says that "interrupts" is an optional property.
It also says "When this property is selected, clock on the SQW pin cannot be used" but isn't the clock what we want? What exactly would your showed interrupt DT code do?
The "#clock-cells" property is only useful if some other Device Tree node is going to refer to it
It's helpfull outside of the DT, too. For example it creates the folder /sys/kernel/debug/clk/ds3231_clk_sqw/.
How would you use it?
For now I'm trying to force it active without a consumer by adding flags ( https://github.com/V10lator/rpi-rt-linu ... 07.c#L1641 ). That way I get a fast clock on the SQW pin which I'm able to read by connecting it with a GPIO pin on the RPI. Now I just need to figure out how to slow the clock signal down to 1 PPS (should be possible according to the datasheet but all my tries hacking the driver failed so far), then feed it back to the DS1307 driver.
Last edited by V10lator on Mon Sep 27, 2021 9:03 am, edited 1 time in total.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4109
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: DS3231 interrupt pin?

Mon Sep 27, 2021 9:33 am

The ds3231 driver includes the following comment:

Code: Select all

		/*
		 * Interrupt signal due to alarm conditions and square-wave
		 * output share same pin, so don't initialize both.
		 */
In other words, you can either use the pin for interrupts or as a square wave output, but not both. Obviously you could configure the SoC to use the square wave output as a source of interrupts, but that may not be what you want.

The chrony faq (https://github.com/mlichvar/chrony/blob ... ay-disable) says:

Code: Select all

=== When I start `chronyd`, the log says `Could not enable RTC interrupt : Invalid argument` (or it may say `disable`)

Your real-time clock hardware might not support the required ioctl requests:

* `RTC_UIE_ON`
* `RTC_UIE_OFF`

A possible solution could be to build the Linux kernel with support for software
emulation instead; try enabling the following configuration option when building
the Linux kernel:

* `CONFIG_RTC_INTF_DEV_UIE_EMUL`

V10lator
Posts: 39
Joined: Wed Jul 07, 2021 11:18 am

Re: DS3231 interrupt pin?

Wed Sep 29, 2021 11:50 am

PhilE wrote:
Mon Sep 27, 2021 9:33 am
The ds3231 driver includes the following comment:

Code: Select all

		/*
		 * Interrupt signal due to alarm conditions and square-wave
		 * output share same pin, so don't initialize both.
		 */
In other words, you can either use the pin for interrupts or as a square wave output, but not both. Obviously you could configure the SoC to use the square wave output as a source of interrupts, but that may not be what you want.
it is exatl what I want, from the kenel menuconfig for CONFIG_RTC_INTF_DEV_UIE_EMUL:

Code: Select all

Those requests generate
once-per-second update interrupts, used for synchronization.
So we don't need an alarm interrupt but a 1 Hz signal. Software emulation is heavy and not fine ganulated enough to calculate clock drift, also from the kernel option:

Code: Select all

The emulation code will read the time from the hardware
clock several times per second

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4109
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: DS3231 interrupt pin?

Wed Sep 29, 2021 12:55 pm

I think what you really need is PPS support. There is an overlay called "pps-gpio" that may help you:

Code: Select all

pi@raspberrypi:~$ dtoverlay -h pps-gpio
Name:   pps-gpio

Info:   Configures the pps-gpio (pulse-per-second time signal via GPIO).

Usage:  dtoverlay=pps-gpio,<param>=<val>

Params: gpiopin                 Input GPIO (default "18")
        assert_falling_edge     When present, assert is indicated by a falling
                                edge, rather than by a rising edge (default
                                off)
        capture_clear           Generate clear events on the trailing edge
                                (default off)

However, you will need something to enable the DS3231's clock support and request a 1Hz clock (the datasheet says the default is 8KHz, the other options being 4KHz and 1KHz). This would normally be done by another driver, querying the clock either by name or using a reference in Device Tree (which needs the aforementioned "#clock-cells"), but you could hack the driver to do it for you.

Return to “Device Tree”