- Muchas notas - Fran Acién

20230711 - Device tree and Linux

Some notes of device tree.

My explanation

Device tree is a way to describe the hardware attached to a computer. It is described on a human readable format .dts, and then is compiled to .dtb or to an overlay .dtbo.

These files needs to be loaded on the system in startup. This can be done in different stages:

  1. By U-Boot. This project is in chage of booting linux and configure everything 20230805 - U-Boot process
  2. By Grub. It needs to be booted with U-Boot, but then the grub. It is used by ubuntu for example. 20230805 - Grub for adding devicetree overlays

Directories

  • /proc/device-tree/ you have the same information you plug with the overlays, that are active. If you wanna know what is activated in your cpu, check this directories.

We can print the whole device tree like:

# dtc -I fs /proc/device-tree

Compile overlay

dtc -O dtb -o enable_led_startup.dtbo enable_led_startup.dts

Compile device tree blob

- [ ] dtc -@ -I dts -O dtb -o test.dtb test.dts

List usable pins by kernel

Here we can see the usable pins:

cat /sys/kernel/debug/pinctrl/2000000.pinctrl/pinmux-pins
cat /sys/kernel/debug/pinctrl/pinctrl-maps

We can print the interrupts:

cat /proc/interrupts

Interrupt

After a lot of hours trying to put the CAN on mango pi I learnt some things.

can0_osc_fixed {
    compatible = "fixed-clock";
    #clock-cells = <0>;
    clock-frequency  = <8000000>;
    phandle = <0x81>;
};

can0_pin_irq {
        pins = "PD17";
        function = "irq";
        phandle = <0x85>;
        bias-pull-up;
};

mcp2515 {
        reg = <0>;		// SPI 1 100% is 0
        compatible = "microchip,mcp2515";
        pinctrl-names = "default";
        pinctrl-0 = <0x85>;
        spi-max-frequency = <10000000>;
        interrupt-parent = <0x22>; // pinctrl@2000000
        interrupts = <3 17 8>; // PD17 IRQ LINE, try with <0 65 2>
        clocks = <0x81>;
        status = "okay";
};

The part of interrupts is like this, :

  • BANK is like, A -> 0, B-> 1, C->2, D->3
  • NUMBER, PD17 -> 17
  • Type, is described here

After enabling the component you should see the interrupt in /proc/interrupts.