Skip to content

Commit 375bb14

Browse files
committed
Add second example, tweak example1 overlay
1 parent 7302dfc commit 375bb14

File tree

3 files changed

+129
-19
lines changed

3 files changed

+129
-19
lines changed

hardware/computemodule/cm-peri-sw-guide.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ You can include more diagnostics in the output by adding `dtdebug=1` to `config.
148148

149149
Please use the [Device Tree subforum](https://www.raspberrypi.org/forums/viewforum.php?f=107) on the Raspberry Pi forums to ask Device Tree related questions.
150150

151-
##Worked Examples
151+
##Examples
152152

153-
For these simple worked examples I used a CMIO board with peripherals attached via jumper wires.
153+
For these simple examples I used a CMIO board with peripherals attached via jumper wires.
154154

155155
For each of the examples we assume a CM+CMIO board with a clean install of the latest Raspbian version on the CM. See instructions [here](https://www.raspberrypi.org/documentation/hardware/computemodule/cm-emmc-flashing.md).
156156

@@ -162,7 +162,7 @@ If you suspect any issues or bugs with Device Tree it is always best to try a `s
162162

163163
Please post any issues / bugs / questions on the Raspberry Pi [Device Tree subforum](https://www.raspberrypi.org/forums/viewforum.php?f=107).
164164

165-
##Worked Example 1 - attaching an I2C RTC
165+
##Example 1 - attaching an I2C RTC
166166

167167
In this simple example we wire an NXP PCF8523 real time clock (RTC) to the CMIO board GPIO pins (3V3, GND, I2C1_SDA on GPIO44 and I2C1_SCL on GPIO45).
168168

@@ -212,7 +212,41 @@ sudo hwclock
212212

213213
will return with the hardware clock time, and not an error.
214214

215-
##Worked Example 2 - Attaching an ENC28J60 SPI Ethernet Controller
215+
##Example 2 - Attaching an ENC28J60 SPI Ethernet Controller
216216

217-
Coming soon...
217+
In this example we take the first RTC example and add another peripheral - an ENC28J60 SPI Ethernet Controller. The Ethernet controller is connected to SPI pins CE0, MISO, MOSI and SCLK (GPIO8-11 respectively), as well as GPIO12 for a falling edge interrupt, and of course GND and 3V3.
218218

219+
In this example we won't change `dt-blob.bin` (though of course you can if you wish) and we should see that Linux Device Tree correctly sets up the pins.
220+
221+
Grab [example2-overlay.dts](example2-overlay.dts) and put it in `/boot` then compile it:
222+
```
223+
sudo dtc -@ -I dts -O dtb -o /boot/overlays/example2-overlay.dtb /boot/example2-overlay.dts
224+
```
225+
226+
Edit `/boot/config.txt` and add the line:
227+
```
228+
dtoverlay=example2
229+
```
230+
231+
Now save and reboot.
232+
233+
Once rebooted you should see, as before, an rtc0 entry in /dev and running:
234+
```
235+
sudo hwclock
236+
```
237+
238+
will return with the hardware clock time, and not an error.
239+
240+
You should also have Ethernet connectivity:
241+
```
242+
ping 8.8.8.8
243+
```
244+
245+
should work.
246+
247+
finally running:
248+
```
249+
sudo raspi-gpio get
250+
```
251+
252+
should show that GPIO8-11 have changed to ALT0 (SPI) functions.

hardware/computemodule/example1-overlay.dts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,33 @@
1616
brcm,pins = <44 45>;
1717
brcm,function = <6>; /* alt2 */
1818
};
19+
spi0_pins: spi0_pins {
20+
brcm,pins = <7 8 9 10 11>;
21+
brcm,function = <4>; /* alt0 */
22+
};
1923
};
2024
};
2125

2226
//
23-
// I2C at 100KHz
27+
// I2C Device(s)
2428
//
2529
fragment@1 {
2630
target = <&i2c1>;
2731
__overlay__ {
32+
#address-cells = <1>; /* needed to avoid dtc warning */
33+
#size-cells = <0>; /* needed to avoid dtc warning */
2834
pinctrl-names = "default";
2935
pinctrl-0 = <&i2c1_pins>;
3036
clock-frequency = <100000>;
31-
};
32-
};
33-
34-
//
35-
// Add devices to I2C1 Bus:
36-
// PCF8523 RTC device
37-
//
38-
fragment@2 {
39-
target = <&i2c1>;
40-
__overlay__ {
41-
#address-cells = <1>;
42-
#size-cells = <0>;
4337
status = "okay";
44-
pcf8523@68 {
38+
// PCF8523 RTC device
39+
pcf8523@68 {
4540
compatible = "nxp,pcf8523";
4641
reg = <0x68>;
4742
status = "okay";
4843
};
4944
};
5045
};
5146

47+
5248
};
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Example overlay for PCF8523 RTC device + ENC28J60 Ethernet
2+
/dts-v1/;
3+
/plugin/;
4+
5+
/ {
6+
compatible = "brcm,bcm2708";
7+
8+
//
9+
// Set up GPIOs:
10+
// I2C1 on GPIO44,45
11+
// SPI on GPIO8-11
12+
// ENC28J60 interrupt on GPIO12
13+
//
14+
fragment@0 {
15+
target = <&gpio>;
16+
__overlay__ {
17+
i2c1_pins: i2c1 {
18+
brcm,pins = <44 45>;
19+
brcm,function = <6>; /* alt2 */
20+
};
21+
spi0_pins: spi0_pins {
22+
brcm,pins = <8 9 10 11>;
23+
brcm,function = <4>; /* alt0 */
24+
};
25+
// ENC28J60 Ethernet Interrupt GPIO
26+
eth1_pins: eth1_pins {
27+
brcm,pins = <12>;
28+
brcm,function = <0>; /* in */
29+
brcm,pull = <0>; /* none */
30+
};
31+
};
32+
};
33+
34+
//
35+
// I2C Device(s)
36+
//
37+
fragment@1 {
38+
target = <&i2c1>;
39+
__overlay__ {
40+
#address-cells = <1>; /* needed to avoid dtc warning */
41+
#size-cells = <0>; /* needed to avoid dtc warning */
42+
pinctrl-names = "default";
43+
pinctrl-0 = <&i2c1_pins>;
44+
clock-frequency = <100000>;
45+
status = "okay";
46+
// PCF8523 RTC device
47+
pcf8523@68 {
48+
compatible = "nxp,pcf8523";
49+
reg = <0x68>;
50+
status = "okay";
51+
};
52+
};
53+
};
54+
55+
//
56+
// SPI Device(s)
57+
//
58+
fragment@2 {
59+
target = <&spi0>;
60+
__overlay__ {
61+
#address-cells = <1>; /* needed to avoid dtc warning */
62+
#size-cells = <0>; /* needed to avoid dtc warning */
63+
pinctrl-names = "default";
64+
pinctrl-0 = <&spi0_pins>;
65+
status = "okay";
66+
// ENC28J60 SPI Device
67+
eth1: enc28j60@0{
68+
compatible = "microchip,enc28j60";
69+
reg = <0>; /* CE0 */
70+
pinctrl-names = "default";
71+
pinctrl-0 = <&eth1_pins>;
72+
interrupt-parent = <&gpio>;
73+
interrupts = <12 0x2>; /* falling edge */
74+
spi-max-frequency = <12000000>;
75+
status = "okay";
76+
};
77+
};
78+
};
79+
80+
};

0 commit comments

Comments
 (0)