How to interface DS3234 spi RTC in IMX6ULL ?

I need to interface SPI RTC on IMX6ULL, i configured DS3232/DS3234 on kernel , i interfaced on SPI1 ,please once go through all attachments and suggest a solution.

Dear Sir,

I have already build the kernel with RTC.

The default RTC used I2C protocol ,DS3234 is SPI based RTC, so i think no need to disable the default RTC.

I am using SPI3 pins for RTC DS3234, so i have created an other node with espi3 and configured pins but i am getting the below error .

root@colibri-imx6ull:~# dmesg |grep rtc

[ 2.008961] snvs_rtc 20cc000.snvs:snvs-rtc-lp: registered as rtc0
[ 4.191297] snvs_rtc 20cc000.snvs:snvs-rtc-lp: setting system clock to 1970-01-01 00:00:02 UTC (2)

root@colibri-imx6ull:~# dmesg |grep spi

[ 0.107820] imx6ul-pinctrl 20e0000.iomuxc: Invalid fsl,pins or pins property in node /soc/aips-bus@02000000/iomuxp
[ 0.107913] imx6ul-pinctrl 20e0000.iomuxc: Invalid fsl,pins or pins property in node /soc/aips-bus@02000000/iomuxp

please go through once, let me know if you need any further information.

Thanks & Regards,
chandrashekar.M

Hi Chandrashekar,

Thanks for contacting Toradex community.

One need to build custom kernel with driver support for the particular RTC. Then disable the default rtc and create rtc node for respective chip.

Driver for DS3234 can be found below

Linux Kernel Configuration
└─> Device Drivers
└─> Real Time Clock
└─> Dallas/Maxim DS3232/DS3234

Next add rtc device under right spi bus node in device tree.

Note: We have not tested the mentioned rtc.

Best Regards

Ritesh Kumar

Dear Sir,

I am very greatful for your support in the short span of time.
Thank you very much sir, Now DS3234 is detected as rtc1 .

so now we have two rtcs,

rtc0 – snvs-rtc - internal rtc
rtc1-- DS3234 - external rtc

when I issued Timedatectl command, it is giving response from rtc0 only since in /etc/udev/rules.d/localextra.rules it is Defined as rtc0,
when I changed this from rtc0 to rtc1 and issued timedatectl command it is showing error as failed to read.

My problem: How to get date and time from rtc1 i.e DS3234 whether to change in UDEV rules or is there any separate command

Hi @chandrashekar

Looks like you have done wrong Pin muxing/SPI node DT bindings. Could you check with the below DT changes and let me know?

&ecspi3{
         
        pinctrl-names = "default";
        cs-gpios = <&gpio1 20 GPIO_ACTIVE_HIGH>;	
	    pinctrl-0 = <&pinctrl_ecspi3 &pinctrl_ecspi3_cs>;
        status = "okay";
  
        rtc: ds3234@0 {
		#address-cells = <1>;
		#size-cells = <0>;
		compatible = "dallas,ds3234";
		reg = <0>;
             spi-max-frequency = <4000000>;
             status = "okay";
      };

};

Hi @chandrashekar

Yes, you need to create udev rule. Please refer to the below RTC article.

Dear Sir,

we have changed UDEV rules in /etc/udev/rules.d/localextra.rules from RTC0 to RTC1 . but it showed below error.

root@colibri-imx6ull:~# timedatectl
Failed to query server: Failed to read RTC: Invalid argument for RTC1

So we checked spi clock frequency , we are not getting clock frequency.

Is there anything else we need to do in dtsi file to get clock frequency ?

Generally what will be the frequency we will get ?

please let me know if you need any further information.

Thanks & Regards,
chandrashekar.M

Hi @chandrashekar

Could you provide the changes that you have done? if possible provide the localextra.rules file.

Dear Sir,

Thanks for your support via phone call.

I have updated the UDEV rules as per the link given by you , but I failed to read from RTC1.

I have updated in the aliases part rtc0=&ds3234, but it has given an error of no node is present in that name,
so I updated as rtc0=&rtc but I failed to read from rtc1.

please once check the changes in attachments and suggest me the solution .

Thanks & Regards,
chandrashekar.Mlink text

Dear Sir,

Thanks for your support.

After issuing hwclock -w,hwclock -r and and changing udev rules we are able to configure time in RTC1 .
we are reading the the time value in hwclock -f /dev/rtc1
it is updating correctly and even in the battery backup it worked good but we found one observation.

we are not able to set time below 1970 year and above 2040 year for both internal rtc and external rtc.

please help us in resolving the issue.

Thanks & Regards,
chandrashekar.M

Dear Sir,

Thanks for your support.

After issuing hwclock -w,hwclock -r and and changing udev rules we are able to configure time in RTC1 . we are reading the the time value in hwclock -f /dev/rtc1 it is updating correctly and even in the battery backup it worked good but we found one observation.

we are not able to set time below 1970 year and above 2040 year for both internal rtc and external rtc.

please help us in resolving the issue.

Thanks & Regards, chandrashekar.M

Hi @chandrashekar

Glad it worked.Thanks for confirming.

No, not possible to update the date before 1970 and 2038 problem is still not yet solved. Please refer to the link for more information.