我对设备树有一些奇怪的问题。我发现更改.dtbo的名称会更改内核的行为!
我用Angstrom修改了/ lib / firmware中给出的BB-SPIDEV1-00A0.dts:
/*
* Copyright (C) 2013 CircuitCo
*
* Virtual cape for SPI1 on connector pins P9.29 P9.31 P9.30 P9.28
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
/dts-v1/;
/plugin/;
/ {
compatible = "ti,beaglebone", "ti,beaglebone-black";
/* identification */
part-number = "BB-SPI1-01";
version = "00A0";
/* state the resources this cape uses */
exclusive-use =
/* the pin header uses */
"P9.31", /* spi1_sclk */
"P9.29", /* spi1_d0 */
"P9.30", /* spi1_d1 */
"P9.28", /* spi1_cs0 */
"P9.42", /* spi1_cs1 */
/* the hardware ip uses */
"spi1";
fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
/* default state has all gpios released and mode set to uart1 */
bb_spi1_pins: pinmux_bb_spi1_pins {
pinctrl-single,pins = <
0x190 0x13 /* mcasp0_aclkx.spi1_sclk, OUTPUT_PULLUP | MODE3 */
0x194 0x33 /* mcasp0_fsx.spi1_d0, INPUT_PULLUP | MODE3 */
0x198 0x13 /* mcasp0_axr0.spi1_d1, OUTPUT_PULLUP | MODE3 */
0x19c 0x13 /* mcasp0_ahclkr.spi1_cs0, OUTPUT_PULLUP | MODE3 */
0x164 0x12 /* eCAP0_in_PWM0_out.spi1_cs1 OUTPUT_PULLUP | MODE2 */
0x1A0 0x32 /* Other P42 pin, INPUT_PULLUP */
>;
};
};
};
fragment@1 {
target = <&spi1>; /* spi1 is numbered correctly */
__overlay__ {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&bb_spi1_pins>;
#address-cells = <1>;
#size-cells = <0>;
spi1_0{
#address-cells = <1>;
#size-cells = <0>;
compatible = "spidev";
reg = <0>;
spi-max-frequency = <16000000>;
};
spi1_1{
#address-cells = <1>;
#size-cells = <0>;
compatible = "spidev";
reg = <1>;
spi-max-frequency = <16000000>;
};
};
};
};
我将其编译为两个名称:BB-SPIDEV1-00A0.dtbo和BB-SPI1-01-00A0.dtbo
当我在/sys/devices/bone_capemgr.9/slots中加载其中之一时,spidev的行为有所不同!
使用BB-SPIDEV1,spidev1.0可以正常工作,没有任何问题。但是spidev1.1的芯片选择不起作用!引脚42处于错误模式,并且该引脚未分配spi1
另一方面,对于BB-SPI1-01(此名称并不重要,使用另一个名称是相同的,只是必须与BB-SPIDEV1不同),引脚42分配合理:
root@beaglebone:/sys/kernel/debug/pinctrl/44e10800.pinmux# cat pinmux-pins | grep spi
pin 89 (44e10964): 481a0000.spi (GPIO UNCLAIMED) function pinctrl_spi1_pins group pinctrl_spi1_pins
pin 100 (44e10990): 481a0000.spi (GPIO UNCLAIMED) function pinctrl_spi1_pins group pinctrl_spi1_pins
pin 101 (44e10994): 481a0000.spi (GPIO UNCLAIMED) function pinctrl_spi1_pins group pinctrl_spi1_pins
pin 102 (44e10998): 481a0000.spi (GPIO UNCLAIMED) function pinctrl_spi1_pins group pinctrl_spi1_pins
pin 103 (44e1099c): 481a0000.spi (GPIO UNCLAIMED) function pinctrl_spi1_pins group pinctrl_spi1_pins
pin 104 (44e109a0): 481a0000.spi (GPIO UNCLAIMED) function pinctrl_spi1_pins group pinctrl_spi1_pins
并在良好模式下:
root@beaglebone:/sys/kernel/debug/pinctrl/44e10800.pinmux# cat pins | grep 964
pin 89 (44e10964) 00000012 pinctrl-single
但是这次spidev1.0无法正常工作。 MISO行(因此是BBB的输入),即使它是假的,也只能看到0(我用示波器检查过)。
那么可能是什么问题呢?
提前致谢
最佳答案
将P9_42B设置为模式4 w /高阻抗(0x2C)-否则,默认值为模式4快速下拉。除非该引脚被另一个覆盖层修改,否则P9_42B无需进行任何复用。
当我访问它们的寄存器时,SPI1(以及SPI0,I2C和GPIO2)寄存器给我总线错误,尽管在各自的覆盖图中将它们的状态设置为“好”,但这些设备仍被禁用。因此,我检查了CM_PER寄存器,并确定:IDLEST=3 [disabled]
和MODULEMODE=0 [disabled]
。尽管这些测试是在Debian系统上完成的,但我敢肯定Angstrom和所有其他发行版也是如此。
要启用它们,您将需要通过选择的首选语言访问电源和时钟管理的内存地址:
通过PRU组装:
.origin 0
.entrypoint START
START:
MOV r0, 0x44E00050 // CM_PER_SPI1_CLKCTRL Register [reset = 30000h / disabled]
LBBO r1, r0, 0, 4 // load register value
CLR r1.t16 // set IDLEST to FUNC
CLR r1.t17
SET r1.t1 // set MODULEMODE to ENABLE
SBBO r1, r0, 0, 4 // store value
HALT
通过Python:Beaglebone IO using Python mmap
通过C / C ++ :(类似于上面的python示例)
引用自:vabi-robotics.blogspot.com
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdio.h>
#include <iostream>
#define CM_PER 0x44E00000 //PG 157
using namespace std;
int main(){
int fd = open("/dev/mem",O_RDWR | O_SYNC);
ulong* pinconf1 = (ulong*) mmap(NULL, 0x0FFF, PROT_READ | PROT_WRITE, MAP_SHARED, fd, CM_PER);
printf("INFO: %X\n", pinconf1[0x50/4]);
pinconf1[0x50/4] = 0x00000002;
printf("INFO: %X\n", pinconf1[0x50/4]); // conf. initialized
return 0;
}
注意:如果这不是问题,并且实际上一个通道可以使用,请在启用下一个通道之前确保已禁用该通道。同样,请确认MCSPI_MODULCTRL寄存器(SPI1:0x481A0128)中的MS位已清除[主],PIN34位已清除[SPIEN被用作片选],并且SINGLE位被清除了[使用了多个通道]。