diff --git a/09_dt_rtc/README.md b/09_dt_rtc/README.md new file mode 100644 index 0000000..bf4193e --- /dev/null +++ b/09_dt_rtc/README.md @@ -0,0 +1,82 @@ +# RTC DS3231 practice (user space). I2C and device tree basics. + +## Overview + +DS3231 module that is recommended for this task contains two I2C devices: + +* DS3231 RTC clock ([datasheet](https://datasheets.maximintegrated.com/en/ds/DS3231.pdf)) +* AT24C32 32 kbit (4Kb) I2C EEPROM ([datasheet](https://ww1.microchip.com/downloads/en/DeviceDoc/doc0336.pdf)) + +DS3231 has a fixed I2C address 0x68. + +AT24C32 can be assigned to any address in range 0x50..0x57 using solderable jumpers. By default, it has address 0x57. This address is already added to BBB device tree and used for cape configuration. + +BBB has several I2C buses. I2C0 is intended to internal use. I2C1 and I2C2 are routed to P9 connector (see [Beagleboard:Cape Expansion Headers](https://elinux.org/Beagleboard:Cape_Expansion_Headers)). + +In this homework we will use RTC board connected to I2C2 bus: + +| RTC board line | BBB P9 pin | +| -------------- | ---------- | +| GND | 1 (DGND) | +| VCC | 3 (VDD\_3V3) | +| SDA | 20 (I2C2\_SDA) | +| SCL | 19 (I2C2\_SCL) | + +![RTC board to BBB connection](./images/BBB-RTC.jpg) + +:exclamation: BBB configuration EEPROM is placed on I2C0 bus. Beware of changing its contents! + +--- + +## Homework + +* Connect the board as shown above. Do this when the board is turned off. + +### RTC +* Download DS3231 datasheet for reference. +* Using i2ctools (i2cdetect, i2cdump, etc.) read and write date/time registers 00h-06h, start and stop clock using EOSC bit in register 0Eh. +* Add the DS3231 chip as a real-time clock to the kernel: + * Read about device binding (Documentation/devicetree/bindings/common-properties.txt, Documentation/devicetree/bindings/rtc/rtc-ds1307.txt) + * Modify am335x-boneblack.dts to add DS3231 as rtc0. Use only required properties (no interrupts, ...). + * Rebuild am335x-boneblack.dtb file and copy it to network boot directories (do not forget about `/srv/tftp` directory). Reboot BBB. + * Find rtc-related messages in dmesg + * Find ds3231-related files in sysfs + * Use date command to set date/time, off the board for a while and boot it again, check system +* Attach the format-patch of your changes in kernel (am335x-boneblack.dts) + +### EEPROM + +As it is noted above, the EEPROM is already added to the BeagleBone device tree. But in the device this EEPROM is set to AT24C256 type of size 32Kb (see arch/arm/boot/am335x-bone-common.dtsi, cape\_eeprom3). +``` + compatible = "atmel,24c256"; +``` +So that, if we read the EEPROM device file we will get 32 KB of data. + +* Use `find /sys/firmware/devicetree/ | grep cape_eeprom3` to get cape\_eeprom3 placement. +* Use `cat /the/directory/you/found/compatible` to check device type. +* Write some bytes to EEPROM (use `echo` to `/sys/bus/i2c/devices/2-0057/eeprom`) +* Read the whole EEPROM using `cat` from EEPROM device file (pipe `cat` output to `hexdump -C`). As you can see, your input is duplicated four times. +* Override am335x-bone-common.dtsi cape\_eeprom3 `compatible` property in am335x-boneblack.dts +(attach the format-patch of your changes in kernel) +* Rebuild .dtb file and copy it to network boot directories. +* Use `cat /the/directory/you/found/compatible` to check if type is actually changed. +* Read the whole EEPROM device file again and compare results. + +Note: +You can access EEPROM file in different ways because of symlinks in the hierarchy + +* `/sys/bus/i2c/devices/2-0057/eeprom` +* `/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0057/eeprom` +* `/sys/class/i2c-dev/i2c-2/device/2-0057/eeprom` +* `/sys/devices/platform/ocp/4819c000.i2c/i2c-2/device/i2c-2/2-0057/eeprom` + +Also, `/proc/device-tree` now is a symlink to `/sys/firmware/devicetree/base` + +## Literature + +* [I2C short overview](https://www.ti.com/lit/an/slva704/slva704.pdf) +* [I2C specification](https://www.nxp.com/docs/en/user-guide/UM10204.pdf) +* [BBB SRM](https://github.com/beagleboard/beaglebone-black/blob/master/BBB_SRM.pdf) +* [BBB schematic file](https://github.com/beagleboard/beaglebone-black/blob/master/BBB_SCH.pdf) +* [Beagleboard:Cape Expansion Headers](https://elinux.org/Beagleboard:Cape_Expansion_Headers) + diff --git a/09_dt_rtc/log.txt b/09_dt_rtc/log.txt new file mode 100644 index 0000000..2122684 --- /dev/null +++ b/09_dt_rtc/log.txt @@ -0,0 +1,99 @@ +Please press Enter to activate this console. +/ # i2cdetect -r -y 2 + 0 1 2 3 4 5 6 7 8 9 a b c d e f +00: -- -- -- -- -- -- -- -- -- -- -- -- -- +10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- +70: -- -- -- -- -- -- -- -- +/ # date +Sat Jan 1 00:18:43 UTC 2000 +/ # date -s "2021-03-25 1:16" +Thu Mar 25 01:16:00 UTC 2021 +/ # date +Thu Mar 25 01:16:33 UTC 2021 +/ # hwclock +Sat Jan 1 00:21:34 2000 0.000000 seconds +/ # hwclock -w +/ # hwclock -w +/ # hwclock +Thu Mar 25 01:18:09 2021 0.000000 seconds +/ # i2cdetect -r -y 0 + 0 1 2 3 4 5 6 7 8 9 a b c d e f +00: -- -- -- -- -- -- -- -- -- -- -- -- -- +10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +20: -- -- -- -- UU -- -- -- -- -- -- -- -- -- -- -- +30: -- -- -- -- 34 -- -- -- -- -- -- -- -- -- -- -- +40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +70: 70 -- -- -- -- -- -- -- +/ # cat sys/bus/i2c/devices/0-0050/eeprom | hexdump -C +00000000 aa 55 33 ee 41 33 33 35 42 4e 4c 54 30 30 43 30 |.U3.A335BNLT00C0| +00000010 32 34 31 39 42 42 42 4b 30 31 42 42 ff ff ff ff |2419BBBK01BB....| +00000020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00000050 34 30 30 35 32 34 2b 31 33 30 31 2b 30 30 30 34 |400524+1301+0004| +00000060 34 33 2b 31 39 32 34 58 58 58 58 58 58 58 58 58 |43+1924XXXXXXXXX| +00000070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00001000 aa 55 33 ee 41 33 33 35 42 4e 4c 54 30 30 43 30 |.U3.A335BNLT00C0| +00001010 32 34 31 39 42 42 42 4b 30 31 42 42 ff ff ff ff |2419BBBK01BB....| +00001020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00001050 34 30 30 35 32 34 2b 31 33 30 31 2b 30 30 30 34 |400524+1301+0004| +00001060 34 33 2b 31 39 32 34 58 58 58 58 58 58 58 58 58 |43+1924XXXXXXXXX| +00001070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00002000 aa 55 33 ee 41 33 33 35 42 4e 4c 54 30 30 43 30 |.U3.A335BNLT00C0| +00002010 32 34 31 39 42 42 42 4b 30 31 42 42 ff ff ff ff |2419BBBK01BB....| +00002020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00002050 34 30 30 35 32 34 2b 31 33 30 31 2b 30 30 30 34 |400524+1301+0004| +00002060 34 33 2b 31 39 32 34 58 58 58 58 58 58 58 58 58 |43+1924XXXXXXXXX| +00002070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00003000 aa 55 33 ee 41 33 33 35 42 4e 4c 54 30 30 43 30 |.U3.A335BNLT00C0| +00003010 32 34 31 39 42 42 42 4b 30 31 42 42 ff ff ff ff |2419BBBK01BB....| +00003020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00003050 34 30 30 35 32 34 2b 31 33 30 31 2b 30 30 30 34 |400524+1301+0004| +00003060 34 33 2b 31 39 32 34 58 58 58 58 58 58 58 58 58 |43+1924XXXXXXXXX| +00003070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00004000 aa 55 33 ee 41 33 33 35 42 4e 4c 54 30 30 43 30 |.U3.A335BNLT00C0| +00004010 32 34 31 39 42 42 42 4b 30 31 42 42 ff ff ff ff |2419BBBK01BB....| +00004020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00004050 34 30 30 35 32 34 2b 31 33 30 31 2b 30 30 30 34 |400524+1301+0004| +00004060 34 33 2b 31 39 32 34 58 58 58 58 58 58 58 58 58 |43+1924XXXXXXXXX| +00004070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00005000 aa 55 33 ee 41 33 33 35 42 4e 4c 54 30 30 43 30 |.U3.A335BNLT00C0| +00005010 32 34 31 39 42 42 42 4b 30 31 42 42 ff ff ff ff |2419BBBK01BB....| +00005020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00005050 34 30 30 35 32 34 2b 31 33 30 31 2b 30 30 30 34 |400524+1301+0004| +00005060 34 33 2b 31 39 32 34 58 58 58 58 58 58 58 58 58 |43+1924XXXXXXXXX| +00005070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00006000 aa 55 33 ee 41 33 33 35 42 4e 4c 54 30 30 43 30 |.U3.A335BNLT00C0| +00006010 32 34 31 39 42 42 42 4b 30 31 42 42 ff ff ff ff |2419BBBK01BB....| +00006020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00006050 34 30 30 35 32 34 2b 31 33 30 31 2b 30 30 30 34 |400524+1301+0004| +00006060 34 33 2b 31 39 32 34 58 58 58 58 58 58 58 58 58 |43+1924XXXXXXXXX| +00006070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00007000 aa 55 33 ee 41 33 33 35 42 4e 4c 54 30 30 43 30 |.U3.A335BNLT00C0| +00007010 32 34 31 39 42 42 42 4b 30 31 42 42 ff ff ff ff |2419BBBK01BB....| +00007020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00007050 34 30 30 35 32 34 2b 31 33 30 31 2b 30 30 30 34 |400524+1301+0004| +00007060 34 33 2b 31 39 32 34 58 58 58 58 58 58 58 58 58 |43+1924XXXXXXXXX| +00007070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* +00008000 diff --git a/09_dt_rtc/patch/0001-task09-Done.patch b/09_dt_rtc/patch/0001-task09-Done.patch new file mode 100644 index 0000000..4f73db8 --- /dev/null +++ b/09_dt_rtc/patch/0001-task09-Done.patch @@ -0,0 +1,104 @@ +From 822cec0e07eaece5e126b71611afab91dc87252e Mon Sep 17 00:00:00 2001 +From: alexposukhov <33048624+alexposukhov@users.noreply.github.com> +Date: Mon, 15 Mar 2021 09:16:23 +0200 +Subject: [PATCH] task09: Done + +Signed-off-by: Anton Kotsiubailo +--- + 09_dt_rtc/README.md | Bin 0 -> 4065 bytes + 09_dt_rtc/log.txt | Bin 0 -> 7948 bytes + scissors/README.md | Bin 481 -> 0 bytes + 3 files changed, 0 insertions(+), 0 deletions(-) + create mode 100644 09_dt_rtc/README.md + create mode 100644 09_dt_rtc/log.txt + delete mode 100644 scissors/README.md + +diff --git a/09_dt_rtc/README.md b/09_dt_rtc/README.md +new file mode 100644 +index 0000000000000000000000000000000000000000..bf4193ea2d5e7109e34ae2b88cbae3c3f93aa4a0 +GIT binary patch +literal 4065 +zcmb_fU31$u7JXj+3bcNaG7>>ccHDSpA7aVfbdoe3J56UN=~y5Lil|9~3xKAylOMn5 +zf~4f6$!t4YkDW;1#r-_@+{+Vo^LEA7x68%ylr>gJuccy>)+x(eBcz(f?1#mQi8^DM +zdZ35iD#cRav~+P4ot&^Y56V7h)kV>ur!rYvLa-2?X~(RRrm9q(sf^{u;v9!wxO*l| +z?S-!Ktuw()Z^B(h(UZ|B@=umV-m}U3OyF9fl>c>7c;C27&JRZ}uEb7Py7p>og;!Y& +zt6bGQbG-K}ZnAtjh34mP7iX*Gg5mc*)t*hxUZ&Gv|N8o;n>Vk&Y^m!`<4Q|wWTBg& +zJTqNg8UX_^vkuu=8_6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U>2I9p02m4MMHCD<8x~ayI@S-jEJj8YOj3jTUy#@%@gJ +z)VuM0ONLi16xYtTEn1KN{Q5LmBxeUrw8GxrygoXy)xK!c;6!?STj1m8TFpbx@w7B4 +muLNyqwC>(P$tOx3sE$@%8J2~=K>zB+QUB4gzxXvKivA0}#7Ecw + +literal 0 +HcmV?d00001 + +diff --git a/09_dt_rtc/log.txt b/09_dt_rtc/log.txt +new file mode 100644 +index 0000000000000000000000000000000000000000..2122684cb1ccf9747b68a9be4118e7b500e69909 +GIT binary patch +literal 7948 +zcmeH}OK;jh5XbNS6n~|+MuvUbz^z2R^rcD-Qm&5K2-GA**hw0R58qkyFf!OR$wcy@ +zs|79l__I6no1Oi6>ypgjVd=6ApYLT;Ln2$u+7pjs@fn-UZQ0+8@J8ZdwbA|M6^zz|4)Yaj)tfCFyow2J;fh*3Eq4AG{R +z3l3X>B*8W!`*RLu%AP=R3ug}dN*5fqg1ABOaQeS{ib$FIAY&@Q +zuO!EpfD(e@=k!wUFwAhKgp#4qp|X%88J(T3hv0Jdi0{b~q#?Y> +zh&Hy~p`!3Uy_7pVeeKZ|hdb0;8@^$Ov*+}7k^VmVkEeE4ysYF%n~jG>j~wlNojJO) +zr&&Ac!iL)&hR^L5HO+co!KQz1J684bU?hfQL+{}?*sz-QUKMkjBmB>LA?j}F)@ihw +z^(avG*B)&*Ar!nz)@yUj{jE0cuqo^9i|n@>1%1|w#c{heEvy?WE{Bv7RrZqguOG8M +zMNNO|p602``XUsoKfYZGaUoVaK}o|}ftb-GH7qnphAKTZy@=d&-P~YT +zu~J43$K&x=A;;q$l~PcV;BI22Q9rQqBKyS)eylggt4209wEoCj3z6N{$5+?>tc59y +zQ~TeA4gEL0#aD)$rp&q2LY|W=OnKyJBdD-2dO2N#b6kX?V{o-f54;43u^xEopEGupf +z6*q^f^BijK`;c;sza04TvhF;Gnwvw-&7tl*hxA0@&C7lyj24>oB%AKl_A(w=MD5 +zRn&c`%4tTkcrANzy(2kNDDqfu1{na@B*2@ZEhh +z7nM6}B|XA%gDX)hjv6TTcb$ulPu9xS_-<>50e-14h;B}&=A$-urKP6cZLT|G-ct4y +ywf$^m?xFG$Yq5_bgyBi8(all<(6zRnN=Dx4$4ulM>Kw1c2vZ3*>TRGOY|S68wx?16 + +-- +2.7.4 +