Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task09 #148

Open
wants to merge 3 commits into
base: anton.kotsiubailo
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions 09_dt_rtc/README.md
Original file line number Diff line number Diff line change
@@ -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)

99 changes: 99 additions & 0 deletions 09_dt_rtc/log.txt
Original file line number Diff line number Diff line change
@@ -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 |................|
*
Comment on lines +34 to +38

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to task description:

  1. you should use EEPROM on additional board - i2c2 bus
  2. you should make change to devicetree to override EEPROM model to the one that you use

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have the same RTC as in the task that is why I have task with BeagleBone EEPROM

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
104 changes: 104 additions & 0 deletions 09_dt_rtc/patch/0001-task09-Done.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
From 822cec0e07eaece5e126b71611afab91dc87252e Mon Sep 17 00:00:00 2001
From: alexposukhov <[email protected]>
Date: Mon, 15 Mar 2021 09:16:23 +0200
Subject: [PATCH] task09: Done

Signed-off-by: Anton Kotsiubailo <[email protected]>
---
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
Comment on lines +6 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide correct patch for devicetree.
It should be human readable.
No binary data here.


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+3bcNa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O|p602``XUs<ioSCX%f%g5n7KdG$GZoF7j<#~J?GYio`DIh1zp(A!ARfmmEMX*
z!BAHUYoLX%lo{z8tKLNSK51>oKfYZGaUoVaK}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<!Av3NuExp_6bF`A6K9@sfuC}EVBogaQ
zRk7*rCwaM2-pz)R&d<uB6wDk-(RB_bT>-2dO2N#b6kX?V{o-f54;43u^xEopEGupf
z6*q^f^BijK`;c;sza04TvhF;Gnwvw-&7tl*hxA0@&C7<HL(_Q<4L65|n?uui4lOr_
zmYYM{c@8Z%hnAZ|+j$NnZVn@E4x`R<7;$qLadQ}Tp2L`%!<d`Hxbqyw+#JT-9LAmJ
JaNs!%{sO^NuDbvL

literal 0
HcmV?d00001

diff --git a/scissors/README.md b/scissors/README.md
deleted file mode 100644
index 1182c39e1fe12661c537582fc27381c3cfed8059..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 481
zcmXw0J#WJx5Z(C|Cv}J;HTKlSLzk*UrdCy#P6@#mo7!;b4jT2}_i*C@#DjYucRax8
zGfWilMm(DrMw<~VFuD1VY(hSW^CH9oj-t?lFxr5o;j*B>lyj24>oB%AKl_A(w=MD5
zRn&c`%4t<OZ7O?XKBs>TkcrANzy(2kNDDqfu1{na@B*2@ZE<SI#Pp3W!_DWZ0?nq8
zLeMATL4l0}Nao^lVQk^G9oycV&u8-t?+aQ%a1)VWzjg-=@8JMzI%rZoZyBMHy^>hh
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