大樹底下好乘涼 ︰ 《本根變》

□︰打開電燈,需要知道電路學嗎?

○︰不需要;

□︰那為什麼要學…

○︰燈不亮時可能需要。

假使你閱讀《 Raspberry Pi 2 ; GPIO not working 》論壇,請注意

【一】 by FTrevorGowen » Sat Feb 14, 2015 3:36 pm
This may be a “red herring” (esp. as I don’t know exactly how the Python code/wrappers work) but if, as on the new Pi 2 B, the 3.18 kernel is in use and the mechanism uses (wiring Pi’s) “gpio export” and “gpio unexport” methods or similar, then the “unexport” behaviour has changed with the new kernel** – all unexported pins now revert to being inputs ~1 second after being unexported since they’re regarded “as no longer in use“.

這事雖在《春雷早發︰樹莓派 2 Model B ︰早鳥篇》一文中談及,那時作者卻也不知 kernel 內部已將『 unexport 』意義改為

by notro » Sun Feb 08, 2015 1:01 am
With Device Tree a new gpio driver is used: pinctrl-bcm2835.
When you unexport, the pin is set back as input. If you want to keep it, don’t unexport it. Unexporting tells Linux that you don’t use the pin anymore.

Call cain:
unexport_store() => gpiod_free() => __gpiod_free() => chip->free():bcm2835_gpio_free() => pinctrl_free_gpio() => pinmux_free_gpio() => pin_free() => ops->gpio_disable_free():bcm2835_pmx_gpio_disable_free()

【二】by croston » Fri Feb 13, 2015 8:09 pm
There is a problem recognising pins > 26 when using BOARD numbers. It is fixed in the development version and I am looking to release 0.5.11 later tonight.

作者曾見網路上很多議論『該不該』作 GPIO 軟體『 upgrade 』的問題,事實上到目前為止,有關『樹莓派 2B 』官方公佈的軟硬體『資訊』都還很少,『嚐鮮者』最好的辦法就是閱讀『原始碼』,就目前所知, 0.5.11 版的 GPIO 軟體已經如期發行,請用︰

 

# 安裝 GPIO 最新版
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

pi@raspberrypi ~ $ apt-cache show RPI.GPIO
Package: python-rpi.gpio
Source: rpi.gpio
Version: 0.5.11-1
Architecture: armhf
Maintainer: Ben Croston <ben@croston.org>
Installed-Size: 174
Depends: libc6 (>= 2.13-28), libgcc1 (>= 1:4.4.0), python (>= 2.6.6-7~), python (<< 2.8)
Homepage: http://sourceforge.net/projects/raspberry-gpio-python/
Priority: optional
Section: python
Filename: pool/main/r/rpi.gpio/python-rpi.gpio_0.5.11-1_armhf.deb
Size: 45508
SHA256: b8e69b7eead05797378628b814f36e2af788a1abfaf32f1a175233766d3bea20
SHA1: fea86e3a5aebde912066c9d42039ff11a4b42a62
MD5sum: 074cbe6da329fec1f4a4993319987285
Description: Python GPIO module for Raspberry Pi
 This is the RPi.GPIO Python module, for supporting GPIO on a
 Raspberry Pi

Package: python3-rpi.gpio
Source: rpi.gpio
Version: 0.5.11-1
Architecture: armhf
Maintainer: Ben Croston <ben@croston.org>
Installed-Size: 95
Depends: libc6 (>= 2.13-28), libgcc1 (>= 1:4.4.0), python3 (>= 3.2.3-3~), python3 (<< 3.3)
Homepage: http://sourceforge.net/projects/raspberry-gpio-python/
Priority: optional
Section: python
Filename: pool/main/r/rpi.gpio/python3-rpi.gpio_0.5.11-1_armhf.deb
Size: 26714
SHA256: 615fe7ce819e991e0f202b901b23c9839f2a19095374e8e289a804bc37e8ae0f
SHA1: 8a336971a040408546d89028241eee6fcf83fc19
MD5sum: 2d8dfaaa3b32ec3e0b1c6cec863e9562
Description: Python 3 GPIO module for Raspberry Pi
 This is the RPi.GPIO Python 3 module, for supporting GPIO on a
 Raspberry Pi

 

如果依據《 Device Trees, Overlays and Parameters 》官方說法︰

Raspberry Pi’s latest kernels and firmware, including Raspbian and NOOBS releases, now by default use Device Tree (DT) to manage some resource allocation and module loading. This change is to alleviate the problem of multiple drivers contending for system resources, and to allow HAT modules to be auto-configured.

The current implementation is not a pure Device Tree system — there is still board support code that creates some platform devices — but the external interfaces (i2c, i2s, spi) and the audio devices that use them must now be instantiated using a Device Tree Blob (DTB) passed to the kernel by the loader (start.elf).

The main impact of using Device Tree is to change from everything on, relying on module blacklisting to manage contention, to everything off unless requested by the DTB. In order to continue to use external interfaces and the peripherals that attach to them, you will need to add some new settings to your config.txt.

看來想要更好的掌握樹莓派,對於『設備樹』 Device Tree 這一個『資料結構』── 描述 SoC 以及所構成主板上的各種硬體裝置 ── 之理解也就不可或缺的了!!

讓我們先瞧瞧『樹莓派 2B 』的『骨幹』bcm2709.dtsi︰

/include/ "skeleton.dtsi"

/ {
	compatible = "brcm,bcm2709";
	model = "BCM2709";

	interrupt-parent = <&intc>;

	chosen {
		/* No padding required - the boot loader can do that. */
		bootargs = "";
	};

	soc: soc {
		compatible = "simple-bus";
		#address-cells = <1>;
		#size-cells = <1>;
		ranges = <0x7e000000 0x3f000000 0x01000000>;

		intc: interrupt-controller {
			compatible = "brcm,bcm2708-armctrl-ic";
			reg = <0x7e00b200 0x200>;
			interrupt-controller;
			#interrupt-cells = <2>;
		};

		gpio: gpio {
			compatible = "brcm,bcm2835-gpio";
			reg = <0x7e200000 0xb4>;
			interrupts = <2 17>, <2 18>;

			gpio-controller;
			#gpio-cells = <2>;

			interrupt-controller;
			#interrupt-cells = <2>;
		};

		i2s: i2s@7e203000 {
			compatible = "brcm,bcm2708-i2s";
			reg = <0x7e203000 0x20>,
			      <0x7e101098 0x02>;

			//dmas = <&dma 2>,
			//       <&dma 3>;
			dma-names = "tx", "rx";
			status = "disabled";
		};

		spi0: spi@7e204000 {
			compatible = "brcm,bcm2708-spi";
			reg = <0x7e204000 0x1000>;
			interrupts = <2 22>;
			clocks = <&clk_spi>;
			#address-cells = <1>;
			#size-cells = <0>;
			status = "disabled";
		};

		i2c0: i2c@7e205000 {
			compatible = "brcm,bcm2708-i2c";
			reg = <0x7e205000 0x1000>;
			interrupts = <2 21>;
			clocks = <&clk_i2c>;
			#address-cells = <1>;
			#size-cells = <0>;
			status = "disabled";
		};

		i2c1: i2c@7e804000 {
			compatible = "brcm,bcm2708-i2c";
			reg = <0x7e804000 0x1000>;
			interrupts = <2 21>;
			clocks = <&clk_i2c>;
			#address-cells = <1>;
			#size-cells = <0>;
			status = "disabled";
		};

		leds: leds {
			compatible = "gpio-leds";
		};
	};

	clocks {
		compatible = "simple-bus";
		#address-cells = <1>;
		#size-cells = <0>;

		clk_i2c: i2c {
			compatible = "fixed-clock";
			reg = <1>;
			#clock-cells = <0>;
			clock-frequency = <250000000>;
		};

		clk_spi: clock@2 {
			compatible = "fixed-clock";
			reg = <2>;
			#clock-cells = <0>;
			clock-output-names = "spi";
			clock-frequency = <250000000>;
		};
	};

	timer {
		compatible = "arm,armv7-timer";
		clock-frequency = <19200000>;
		interrupts = <3 0>, // PHYS_SECURE_PPI
			     <3 1>, // PHYS_NONSECURE_PPI
			     <3 3>, // VIRT_PPI
			     <3 2>; // HYP_PPI
		always-on;
	};

	cpus: cpus {
		#address-cells = <1>;
		#size-cells = <0>;

		v7_cpu0: cpu@0 {
			device_type = "cpu";
			compatible = "arm,cortex-a7";
			reg = <0xf00>;
			clock-frequency = <800000000>;
		};

		v7_cpu1: cpu@1 {
			device_type = "cpu";
			compatible = "arm,cortex-a7";
			reg = <0xf01>;
			clock-frequency = <800000000>;
		};

		v7_cpu2: cpu@2 {
			device_type = "cpu";
			compatible = "arm,cortex-a7";
			reg = <0xf02>;
			clock-frequency = <800000000>;
		};

		v7_cpu3: cpu@3 {
			device_type = "cpu";
			compatible = "arm,cortex-a7";
			reg = <0xf03>;
			clock-frequency = <800000000>;
		};
	};

	__overrides__ {
		arm_freq = <&v7_cpu0>, "clock-frequency:0",
		       <&v7_cpu1>, "clock-frequency:0",
		       <&v7_cpu2>, "clock-frequency:0",
		       <&v7_cpu3>, "clock-frequency:0";
	};
};

 

 

─── 果真是不一樣的『裝置異樹』,□!學學學 \\\ ────