glambert Posted Monday at 02:19 PM Posted Monday at 02:19 PM Hello, I am trying to connect a ds3231 module to get time during boot (dns does'nt like 1970) and without internet connexion. I load a recent build UBUNTU 26.2.1 on the M5 but unfortunatly after 2 days of research with chatgpt , I ask to knowledge experience people if they know if it's possible and which kind of dts can make this module up and running. I did'nt identify a dtbo on the distribution , a made a lot of investigation , pin 3 and 5 og the 40pins connector is connect to the cpu with pullup resistor , i try a lot dts conf and nothing gave result. If some one did this kind of connexion thanks in advance. Gérard 0 Quote
tparys Posted 18 hours ago Posted 18 hours ago (edited) So, I went through this recently on an NVidia device, and device tree overlays really aren't that hard. But there's a few things you'll need to get set up first, and not having an M5 to check, you'll probably have to do some reading / verification. I make no claim this will work out of the box for you. But I imagine this will save you a lot of reading. There's an example .dtbo at https://github.com/KF0ARE/i2c0-rtc.dtbo/blob/main/i2c0-rtc.dtbo you should look at, and you can decompile it with the following: dtc -O dts -o i2c0-rtc.dts i2c0-rtc.dtbo Which contains a fragment you'll be interested in, explicitly for the DS3231 ... /dts-v1/; / { compatible = "brcm,bcm2708"; ... snip ... fragment@3 { target = <0xffffffff>; __dormant__ { #address-cells = <0x01>; #size-cells = <0x00>; status = "okay"; ds3231@68 { compatible = "maxim,ds3231"; reg = <0x68>; status = "okay"; phandle = <0x04>; }; }; }; ... snip ... }; But you can't use this directly, because "compatible" doesn't include your M5, and "target" doesn't point anywhere useful in your DT. But it does call out the ds3231, and that it's at I2C address 0x68, so you can use that to find where the kernel thinks your RTC is. Take a look at where your I2C buses are (/dev/i2c-*) and just scan each of them like this to see if you can find it: tparys@pebble:~$ sudo i2cdetect -y -r 0 # NOTE: I2C bus #0 is /dev/i2c-0 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- In the above, address 0x10 is unusable as there's something else bound at that register. But check your buses to see if you can find 0x68. If you see something other than "--" or "UU" there, that's probably it. If you can't find it, double check that it's connected, powered on, and that your I2C bus has been enabled (might need to enable via DTB). Once you find it, you should be able to register it by doing something similar to the below as root (driver and I2C bus may be different): echo ds3231 0x68 > /sys/bus/i2c/devices/i2c-0/new_device If that works, and creates a /dev/rtc0 device, test that it's working with "hwclock". Once it's working, it's time to make your .dtbo. You'll probably want to dump your main .dtb with the same dtc command above, and look for i2c-0 (or whatever other bus you found), as well as a .dtbo or two for your M5 to find text to enter for "compatible". And you'll end up with something like this, saved as "m5-ds3231.dts" (or whatever): /dts-v1/; /plugin/; / { compatible = "brcm,bcm2708"; // <---- Change this fragment@0 { target = "i2c-0"; // <---- Change this __overlay__ { #address-cells = <0x01>; #size-cells = <0x00>; status = "okay"; ds3231@68 { compatible = "maxim,ds3231"; reg = <0x68>; status = "okay"; phandle = <0x04>; }; }; }; }; And you'll compile it like this: dtc -@ -O dtb -o m5-ds3231.dtbo m5-ds3231.dts And check it against your M5's DTB like below. Note that "target" or "target-path" has some odd syntax requirements. Quotes with a leading slash is a full path to your I2C device. Quotes without a leading slash is an alias. And angle brackets with an ampersand is a label (not everything has an explicit label). Worst case scenariou, call out the whole path in "target-path" with a leading slash, and call it a day. I beat my head against a wall for a while here before I realized I could test this without rebooting ... fdtoverlay -i /path/to/your/used.dtb -o modified.dtb m5-ds3231.dtbo And then add it to your overlay directory (/boot/dtb/CHIPNAME/overlays), enable it armbianEnv.txt, and give it a go? There's also two kernel build configs that may be of interest as well: CONFIG_RTC_HCTOSYS_DEVICE="rtc0" CONFIG_RTC_SYSTOHC_DEVICE="rtc0" The first triggers the kernel to load time from a given RTC when it first shows up. The second will tell the system to update RTC when locked against NTP. FYI, it seems that you can change these only with a new kernel build. Edited 18 hours ago by tparys 0 Quote
glambert Posted 1 hour ago Author Posted 1 hour ago Thanks for your help. Unfortunatly there are few progress. I change in the global dts of the board the state of all the i2c descriptor from disable to okay and the device i2c-0 to 3 appear in linux, unfortunatly i2cdetect does'nt see the device on address 68 i2c@1c000 { compatible = "amlogic,meson-axg-i2c"; status = "disabled"; reg = <0x00 0x1c000 0x00 0x20>; interrupts = <0x00 0x27 0x01>; #address-cells = <0x01>; #size-cells = <0x00>; clocks = <0x02 0x18>; phandle = <0x12d>; }; I try a lot of tracks with the overlay but nothing change. And it's very difficult to debug and understand what is missing dtoverlay is not available nothing in syslog during boot and quite frankly I have'nt experience in dts design. the only information is the schematic of the board which describe pin3(40pins connector) =GPIOX_17 and pin5 =GPIOX_18 of the processor. inside the processor the route between the ports and the software is a mystery for me (mux adress of register ...) and how to link all that in the dtbo. Thanks if you can give me some direction ? 0 Quote
c0rnelius Posted 45 minutes ago Posted 45 minutes ago Here is an example of an overlay for adding an RTC to the radxa zero /dts-v1/; /plugin/; / { compatible = "radxa,zero", "amlogic,g12a"; fragment@0 { target-path = "/"; __overlay__ { aliases { rtc0 = &rtc; }; }; }; fragment@1 { target = <&i2c3>; __overlay__ { #address-cells = <1>; #size-cells = <0>; rtc: rtc@68 { compatible = "dallas,ds1307"; reg = <0x68>; wakeup-source; }; }; }; __overrides__ { rtc = <0>,"+0"; addr = <&rtc>, "reg:0"; }; }; Key bits here: * aliases (some of these AML units have vrtc on rtc0, so it may need to be set to rtc1) * i2c# (this should be obvious) * compatible string * wakeup-source The i2c-dev module must be force loaded in some cases. If it isn't hard coded into the kernel, you can add it to /etc/modules 0 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.