Device Tree overlay debugging (Adafruit DS3231 RTC breakout)

nerves
raspberrypi

#1

Trying to get my very basic Nerves (on RPi3B+) solution talking to an I2C RTC, the Maxim DS3231,
apparently a very supported device for Raspbian 9 !

Followed the steps documented but still no /dev/rtc appears.
The Raspberry Pi doc suggests turning on dtdebug=on in config.txt and then using the VideoCore debug utility to read the resulting logs . . problem is that the nerves_system_rpi3 buildroot image doesn’t carry the /opt/vc/bin or /opt/vc/lib folders !

Tried pushing those bits into rootfs_overlay but then the vcdbg utility still can’t load the shared object /opt/vc/lib/libelftoolchain.so . … and in fact none of the usual ld files seem to be around (/etc/ld.so.cache, /etc/ld.so.conf, etc.)


#2

I don’t actually think you should need an overlay to enable the DS3231.

in make linux-menuconfig
check device drivers -> real time clock support -> Dallas/Maxim DS1307/37/38/39/40/41, ST M41T00, EPSON RX-8025, ISL12057

You can set that to * and you should have rtc0 after booting.


#3

Ok, two quick things about that . .

  1. those menu options don’t actually list the Maxim/Dallas DS3231 chip
  2. the i2c-rtc DTB doco includes the DS3231 which should then provide the /dev/rtc char special link

Thanks anyways :neutral_face:

How do I go about adding that VC optional package to my basic Nerves project ?


#4

Inching toward enlightenment . . :wink:

Worked out how to run /opt/vc/bin/vcdbg and, sure enough, the DT load debugging is there ! (Almost) :frowning:

How do I get the complete output of :os.cmd (below) ?

iex(fb2@fb2-5116)99> :os.cmd 'export LD_LIBRARY_PATH=/opt/vc/lib ; /opt/vc/bin/vcdbg log msg'

'001322.945: brfs: File read: /mfs/sd/config.txt\n001323.887: brfs: File read: 1479 bytes\n001333.499: HDMI:EDID error reading EDID block 0 attempt 0\n001334.804: HDMI:EDID error reading EDID block 0 attempt 1\n001336.101: HDMI:EDID error reading EDID block 0 attempt 2\n001337.399: HDMI:EDID error reading EDID block 0 attempt 3\n001338.694: HDMI:EDID error reading EDID block 0 attempt 4\n001339.992: HDMI:EDID error reading EDID block 0 attempt 5\n001341.287: HDMI:EDID error reading EDID block 0 attempt 6\n001342.586: HDMI:EDID error reading EDID block 0 attempt 7\n001343.882: HDMI:EDID error reading EDID block 0 attempt 8\n001345.180: HDMI:EDID error reading EDID block 0 attempt 9\n001346.239: HDMI:EDID giving up on reading EDID block 0\n001363.125: brfs: File read: /mfs/sd/config.txt\n001363.948: HDMI:Setting property pixel encoding to Default\n001364.006: HDMI:Setting property pixel clock type to PAL\n001364.068: HDMI:Setting property content type flag to No data\n001364.125: HDMI:Setting property fuzzy format match to enabled\n001584.974: gpioman: gpioman_get_pin_num: pin DISPLAY_DSI_PORT not defined\n001586.303: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead\n001586.378: hdmi: HDMI:>>>>>>>>>>>>>Rx sensed, reading EDID<<<<<<<<<<<<<\n001586.721: hdmi: HDMI:EDID error reading EDID block 0 attempt 0\n001588.028: hdmi: HDMI:EDID error reading EDID block 0 attempt 1\n001589.330: hdmi: HDMI:EDID error reading EDID block 0 attempt 2\n001590.632: hdmi: HDMI:EDID error reading EDID block 0 attempt 3\n001591.933: hdmi: HDMI:EDID error reading EDID block 0 attempt 4\n001593.235: hdmi: HDMI:EDID error reading EDID block 0 attempt 5\n001594.537: hdmi: HDMI:EDID error reading EDID block 0 attempt 6\n001595.839: hdmi: HDMI:EDID error reading EDID block 0 attempt 7\n001597.140: hdmi: HDMI:EDID error reading EDID block 0 attempt 8\n001598.442: hdmi: HDMI:EDID error reading EDID block 0 attempt 9\n001599.507: hdmi: HDMI:EDID giving up on reading EDID block 0\n001599.575: hdmi: HDMI: No lookup table for resolution group 0\n001599.637: hdmi: HDMI: hotplug attached with DVI support\n001599.709: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead\n001600.042: hdmi: HDMI:EDID error reading EDID block 0 attempt 0\n001601.348: hdmi: HDMI:EDID error reading EDID block 0 attempt 1\n001602.653: hdmi: HDMI:EDID error reading EDID block 0 attempt 2\n001603.959: hdmi: HDMI:EDID error reading EDID block 0 attempt 3\n001605.264: hdmi: HDMI:EDID error reading EDID block 0 attempt 4\n001606.569: hdmi: HDMI:EDID error reading EDID block 0 attempt 5\n001607.875: hdmi: HDMI:EDID error reading EDID block 0 attempt 6\n001609.180: hdmi: HDMI:EDID error reading EDID block 0 attempt 7\n001610.485: hdmi: HDMI:EDID error reading EDID block 0 attempt 8\n001611.790: hdmi: HDMI:EDID error reading EDID block 0 attempt 9\n001612.858: hdmi: HDMI:EDID giving up on reading EDID block 0\n001612.933: hdmi: HDMI: hotplug deassert\n001612.986: hdmi: HDMI: HDMI is currently off\n001613.037: hdmi: HDMI: changing mode to unplugged\n001613.101: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead\n001614.473: *** Restart logging\n001614.536: brfs: File read: 1479 bytes\n001618.178: brfs: File read: /mfs/sd/cmdline.txt\n001618.346: Read command line from file \'cmdline.txt\':\n001618.402: \'console=tty1 console=serial0,115200 fbcon=scrollback:1024k root=/dev/mmcblk0p2 rootwait consoleblank=0\'\n001618.699: brfs: File read: 341 bytes\n001773.870: brfs: File read: /mfs/sd/zImage\n001773.932: Loading \'zImage\' to 0x8000 size 0x264178\n001778.328: No kernel trailer - assuming DT-capable\n001778.415: brfs: File read: 2507128 bytes\n001781.363: brfs: File read: /mfs/sd/bcm2710-rpi-3-b-plus.dtb\n001781.426: Loading \'bcm2710-rpi-3-b-plus.dtb\' to 0x26c178 size 0x63e6\n001928.628: brfs: File read: 25574 bytes\n001933.099: brfs: File read: /mfs/sd/config.txt\n001933.479: dtparam: i2c_arm=on\n001950.237: dtparam: spi=on\n001964.748: dtparam: audio=on\n001984.044: brfs: File read: 1479 bytes\n001988.189: brfs: File read: /mfs/sd/overlays/rpi-ft5406.dtbo\n002000.911: Loaded overlay \'rpi-ft54' ++ ...
iex(fb2@fb2-5116)100>


#5

Roughly and antested:

~c"export LD_LIBRARY_PATH=/opt/vc/lib;\n/opt/vc/bin/vcdbg log msg"
|> :os.cmd()
|> IO.puts

#6

If you end up doing this frequently, take a look at toolshed. It has a number of IEx helper functions. One of them is cmd/1. It deals with Erlang vs. Elixir strings when calling :os.cmd() and also prints stdout as it’s generated rather than waiting until the program exits.

iex> use Toolshed
iex> cmd("LD_LIBRARY_PATH=/opt/vc/lib /opt/vc/bin/vcdbg log msg")

p.s. I didn’t realize that vcdbg could help debug DT issues. That’s really helpful!

p.p.s. I have the feeling that you downloaded a vcdbg binary that was built with the opposite hard float/soft float ABI setting that we use on Nerves and it caused frustration. I don’t think you should change what you’re doing now since you got it to work. However in the future, you can also add vcdbg to nerves_system_rpi3 by setting BR2_PACKAGE_RPI_FIRMWARE_INSTALL_VCDBG=y in the nerves_defconfig. This can also be found via make menuconfig, but it’s kind of buried.


#7

Elegant, useful and now tested :+1: Thanks.


#8

Thanks alot for those details; very helpful for me !

Will investigate the hard/soft float setting on that vcdbg executeable . . though I just copied the exe and two .so from a vanilla RPi3B+ host running Raspbian latest, with kenel 4.14.79+.

I’ll keep on exploring this one until I get that RTC running !
Maybe I first need to health-check the device with some manual probing using an ElixirALE.I2C port . . :neutral_face:
It does respond, as expected, at 0x68.


#9

Both Time and the “water under the bridge” have flowed . .

Next thing I (was) going to try today was to get my bespoke nerves_system_rpi3 working so that I could use linux-menuconfig to add a driver for the ds1307 RTC ( in the vain hope of getting the i2c-rtc.dtbo doing something (anything at all) with my (healthy) Maxim DS3231 RTC I2C device but . . tried this . . now what !? (looks like I still need that linux-menuconfig to get the /dev/rtc to materialize)

iex(fb2@fb2-5116)1> ~c' echo ds3231 0x69 > /sys/class/i2c-adapter/i2c-1/new_device '|>:os.cmd()|>IO.puts

11:33:23.801 [info] [ 32.630303] i2c i2c-1: new_device: Instantiated device ds3231 at 0x69


#10

Indeed ! As soon as I mustered the courage and followed the clear instructions on building a custom rpi3 system the interfaces appeared in /dev/rtc0 , /sys/class/rtc , etc.

Thanks to you, @ConnorRigby

Only thing left for me to understand is how DT Overlays work and whether I still need to add one to get the DS3231-specific differences . . (?) , e.g.

iex(fb2@fb2-5116)1> ~c' cat /sys/devices/platform/soc/3f804000.i2c/i2c-1/1-0068/name '|>:os.cmd()|>IO.puts
ds3231

:ok


#11

Its essentially black magic… Just kidding, they are a little weird though. The kernel docs have a good gist of it: https://www.kernel.org/doc/Documentation/devicetree/overlay-notes.txt

You shouldn’t need to touch any device tree overlays to get any of the DS based real time clocks to work. They work via i2c so as long as you linux device has i2c enabled, you should be good to go.


#12

Love that phrase !! Thanks :grin: