Armadilloフォーラム

SPI通信について

n.yamamoto

2014年12月17日 21時33分

Yamamotoです。

以前、SPI設定がうまくいかないと投稿させていただいたのですが、今回新規にコンフィグレーションして実行してみました。

エラーにはなっていないように思えるのですが、/dev/spidev1.0が登録されていません。

以下は起動時の状態です。
-------------------------------------------------------------------------------------------------------
Doing console=ttymxc3
Linux version 2.6.26-at20 (2.6.26) (atmark@atde3) (gcc version 4.3.2 (Debian 4.3.2-1.1) ) #3 PREEMPT Wed Dec 17 18:01:21 JST 2014
CPU: ARM926EJ-S [41069264] revision 4 (ARMv5TEJ), cr=00053177
Machine: Armadillo-460
Memory policy: ECC disabled, Data cache writeback
CPU0: D VIVT write-back cache
CPU0: I cache: 16384 bytes, associativity 4, 32 byte lines, 128 sets
CPU0: D cache: 16384 bytes, associativity 4, 32 byte lines, 128 sets
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32512
Kernel command line: console=ttymxc3
MXC IRQ initialized
PID hash table entries: 512 (order: 9, 2048 bytes)
MXC GPT timer initialized, rate = 133000000
Console: colour dummy device 80x30
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory: 128MB = 128MB total
Memory: 102860KB available (3016K code, 221K data, 128K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 480 bytes
NET: Registered protocol family 16
MXC WDOG1 Enabled
CPU is i.MX25 Revision 1.2
Clock input source is 24000000
MXC GPIO hardware
GPIO-56 autorequested
Initializing CPLD: v2
Using SDMA I.API
MXC DMA API initialized
SCSI subsystem initialized
CSPI: mxc_spi-0 probed
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
MXC I2C driver
MXC I2C driver
MXC I2C driver
MC34704 regulator successfully probed
mc34704 0-0054: Loaded
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP reno registered
NET: Registered protocol family 1
checking if image is initramfs...it isn't (bad gzip magic numbers); looks like an initrd
Freeing initrd memory: 23604K
usb: Host 2 host (serial) registered
usb: DR host (utmi) registered
msgmni has been set to 247
io scheduler noop registered
io scheduler cfq registered (default)
mx2fb: Unable to set clock to 0
Console: switching to colour frame buffer device 60x17
mxc_sdc_fb mxc_sdc_fb.0: fb0: DISP0 BG fb device registered successfully.
mxc_sdc_fb mxc_sdc_fb.0: fb1: DISP0 FG fb device registered successfully.
Serial: MXC Internal UART driver
mxcintuart.1: ttymxc1 at MMIO 0x43f94000 (irq = 32) is a Freescale MXC
mxcintuart.2: ttymxc2 at MMIO 0x5000c000 (irq = 18) is a Freescale MXC
mxcintuart.3: ttymxc3 at MMIO 0x50008000 (irq = 5) is a Freescale MXC
console [ttymxc3] enabled
mxcintuart.4: ttymxc4 at MMIO 0x5002c000 (irq = 40) is a Freescale MXC
brd: module loaded
loop: module loaded
Freescale FlexCAN Driver
FEC Ethernet Driver
PPP generic driver version 2.4.2
Linux video capture interface: v2.00
usbcore: registered new interface driver uvcvideo
USB Video Class driver (v0.1.0)
Driver 'sd' needs updating - please use bus_type methods
armadillo-nor: Found 1 x16 devices at 0x0 in 16-bit bank
Intel/Sharp Extended Query Table at 0x010A
Intel/Sharp Extended Query Table at 0x010A
Intel/Sharp Extended Query Table at 0x010A
Intel/Sharp Extended Query Table at 0x010A
Intel/Sharp Extended Query Table at 0x010A
Using buffer write method
Using auto-unlock on power-up/resume
cfi_cmdset_0001: Erase suspend on write enabled
armadillo-nor: use default partitions(4)
Creating 4 MTD partitions on "armadillo-nor":
0x00000000-0x00020000 : "nor.bootloader"
0x00020000-0x00220000 : "nor.kernel"
0x00220000-0x01fe0000 : "nor.userland"
0x01fe0000-0x02000000 : "nor.config"
fsl-ehci fsl-ehci.0: Freescale On-Chip EHCI Host Controller
fsl-ehci fsl-ehci.0: new USB bus registered, assigned bus number 1
fsl-ehci fsl-ehci.0: irq 35, io mem 0x53ff4400
fsl-ehci fsl-ehci.0: USB 2.0 started, EHCI 1.00, driver 10 Dec 2004
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
fsl-ehci fsl-ehci.1: Freescale On-Chip EHCI Host Controller
fsl-ehci fsl-ehci.1: new USB bus registered, assigned bus number 2
fsl-ehci fsl-ehci.1: irq 37, io mem 0x53ff4000
fsl-ehci fsl-ehci.1: USB 2.0 started, EHCI 1.00, driver 10 Dec 2004
usb usb2: configuration #1 chosen from 1 choice
hub 2-0:1.0: USB hub found
hub 2-0:1.0: 1 port detected
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
input: gpio-keys as /devices/platform/gpio-keys.0/input/input0
i2c /dev entries driver
rtc-s35390a 3-0030: rtc core: registered rtc-s35390a as rtc0
i2c-gpio i2c-gpio.3: using pins 128 (SDA) and 129 (SCL, no clock stretching)
mxsdhci: MXC Secure Digital Host Controller Interface driver
mxsdhci: MXC SDHCI Controller Driver.
mmc0: SDHCI detect irq 159 irq 9 INTERNAL DMA
Registered led device: red
Registered led device: green
Registered led device: yellow
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
i.MX ADC at 0x50030000 irq 46
ip_tables: (C) 2000-2006 Netfilter Core Team
TCP cubic registered
NET: Registered protocol family 17
NET: Registered protocol family 15
can: controller area network core (rev 20071116 abi 8)
NET: Registered protocol family 29
can: raw protocol (rev 20071116)
can: broadcast manager protocol (rev 20080415)
Static Power Management for Freescale i.MX25
input: imx_adc_ts as /devices/virtual/input/input1
i.MX ADC input touchscreen loaded.
rtc-s35390a 3-0030: setting system clock to 2014-12-17 12:05:31 UTC (1418817931)
RAMDISK: ext2 filesystem found at block 0
RAMDISK: Loading 23604KiB [1 disk] into ram disk... done.
VFS: Mounted root (ext2 filesystem).
Freeing init memory: 128K
init started: BusyBox v1.00 (2014.12.14-05:38+0000) multi-call binary
mmc0: new high speed SDHC card at address 0007
mmcblk0: mmc0:0007 SD04G 3858432KiB
mmcblk0: p1
Starting fsck for root filesystem.
fsck 1.25 (20-Sep-2001)
ext2fs_check_if_mount: No such file or directory while determining whether /dev/ram0 is mounted.
/dev/ram0: clean, 1019/1248 files, 21326/23604 blocks
Checking root filesystem: done
Remounting root rw: done
Mounting proc: done
Mounting usbfs: done
Mounting sysfs: done
Cleaning up system: done
Running local start scripts.
Starting udevd: done
Loading /etc/config: done
Changing file permissions: done
Configure /home/ftp: done
Starting syslogd: done
Starting klogd: done
Starting basic firewall: done
Setting hostname: done
Configuring network interfaces: fec: PHY @ 0x0, ID 0x0007c0f1 -- LAN8720
eth0: link down
done
Starting inetd: done
Setting at-cgi: done
Starting lighttpd: done
Creating avahi.services: eth0: link up, 100Mbps, full-duplex
done
Starting avahi.daemon: done
Mounting ramfs /home/ftp/pub: done
-------------------------------------------------------------------------------------------------------

あとLinux kernelの設定は以下のようになっていました。
-------------------------------------------------------------------------------------------------------
[root@armadillo460-0 (ttymxc3) /home/guest]# zcat /proc/config.gz | grep SPI | grep =y
CONFIG_RWSEM_GENERIC_SPINLOCK=y
CONFIG_SPI_MXC_SELECT1=y
CONFIG_ARMADILLO400_SPI1_CON9=y
CONFIG_ARMADILLO400_SPI1_SS0_CON9_25=y
CONFIG_ARMADILLO400_SPI1_SS1_CON9_11=y
CONFIG_ARMADILLO400_CON9_3_CSPI1_MOSI=y
CONFIG_ARMADILLO400_CON9_5_CSPI1_MISO=y
CONFIG_ARMADILLO400_CON9_11_CSPI1_SS1=y
CONFIG_ARMADILLO400_CON9_13_CSPI1_SCLK=y
CONFIG_ARMADILLO400_CON9_25_CSPI1_SS0=y
CONFIG_ARMADILLO400_CON9_26_CSPI1_RDY=y
CONFIG_SPI=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_BITBANG=y
CONFIG_SPI_MXC=y
-------------------------------------------------------------------------------------------------------

何か確認すべき点がありましたら教えていただけませんでしょうか?

よろしくお願いいたします。

コメント

at_takashi.sasayama

2014年12月18日 8時31分

笹山です。

> 何か確認すべき点がありましたら教えていただけませんでしょうか?

下記に該当する修正は行っているでしょうか?

Armadillo実践開発ガイド 第3部 2.3. SPI接続A/Dコンバーター
図2.37「CSPI3、SS0をspidevで使用する修正」
http://manual.atmark-techno.com/armadillo-guide/armadillo-guide-3_ja-2…

この修正を行っていない場合、/dev/spidev1.0 が登録されない現象が発生します。

CSPI1を使用する場合は、以下の様な修正になります。

linux-2.6.x/arch/arm/mach-mx25/armadillo400.c:713行目付近

static struct spi_board_info armadillo400_spi1_board_info[] __initdata = {
+       {
+               .modalias = "spidev",
+               .max_speed_hz = 1000000,
+               .bus_num = 1,
+               .chip_select = 0,
+       },
 };

n.yamamoto

2014年12月18日 11時46分

Yamamotoです。

下記修正を行ったのですが、コンパイルエラーになりました。
arch/arm/mach-mx25/armadillo400.c:740: error: field name not in recors or union initializer
arch/arm/mach-mx25/armadillo400.c:740: error: (near initialization for 'armadillo400_spi3_bord_info')
(上記は実践ガイドに従いSPI3にコンフィグも変更したうえで、spi3用に変更した結果です)

確か、以前に420(?)で確認した時もコンパイルエラーになり、修正せずにコンフィグだけでドライバーが登録されるのを確認できたような気がするのですが・・・

> 笹山です。
>
> > 何か確認すべき点がありましたら教えていただけませんでしょうか?
>
> 下記に該当する修正は行っているでしょうか?
>
> Armadillo実践開発ガイド 第3部 2.3. SPI接続A/Dコンバーター
> 図2.37「CSPI3、SS0をspidevで使用する修正」
> http://manual.atmark-techno.com/armadillo-guide/armadillo-guide-3_ja-2…
>
> この修正を行っていない場合、/dev/spidev1.0 が登録されない現象が発生します。
>
> CSPI1を使用する場合は、以下の様な修正になります。
>
> linux-2.6.x/arch/arm/mach-mx25/armadillo400.c:713行目付近
>

> static struct spi_board_info armadillo400_spi1_board_info[] __initdata = {
> +       {
> +               .modalias = "spidev",
> +               .max_speed_hz = 1000000,
> +               .bus_num = 1,
> +               .chip_select = 0,
> +       },
>  };
> 

y.nakamura

2014年12月18日 16時47分

中村です。

すでに笹山さんの差し替えファイルで解決かもしれませんが、
単なる興味本位で・・・

> 下記修正を行ったのですが、コンパイルエラーになりました。
> arch/arm/mach-mx25/armadillo400.c:740: error: field name not in recors or union initializer
> arch/arm/mach-mx25/armadillo400.c:740: error: (near initialization for 'armadillo400_spi3_bord_info')
> (上記は実践ガイドに従いSPI3にコンフィグも変更したうえで、spi3用に変更した結果です)

どうやったらこのエラーがでるのかを調べてみました。

> > linux-2.6.x/arch/arm/mach-mx25/armadillo400.c:713行目付近
> >

> > static struct spi_board_info armadillo400_spi1_board_info[] __initdata = {
> > +       {
> > +               .modalias = "spidev",
> > +               .max_speed_hz = 1000000,
> > +               .bus_num = 1,
> > +               .chip_select = 0,
> > +       },
> >  };
> > 

中カッコが2重にかかっていますが、ソース編集のミスか何かで、
たとえば次のように1つを消してしまうと、このエラーになるようです。

static struct spi_board_info armadillo400_spi1_board_info[] __initdata = 
      {
               .modalias = "spidev",

とか

static struct spi_board_info armadillo400_spi1_board_info[] __initdata = {
               .modalias = "spidev",

とか。

--
なかむら

n.yamamoto

2014年12月18日 16時57分

Yamamotoです。

下記、ご指摘の通り間違えて中{}なしのロジックだけをコピペしたと思います。

失礼しました。

> 中村です。
>
> すでに笹山さんの差し替えファイルで解決かもしれませんが、
> 単なる興味本位で・・・
>
> > 下記修正を行ったのですが、コンパイルエラーになりました。
> > arch/arm/mach-mx25/armadillo400.c:740: error: field name not in recors or union initializer
> > arch/arm/mach-mx25/armadillo400.c:740: error: (near initialization for 'armadillo400_spi3_bord_info')
> > (上記は実践ガイドに従いSPI3にコンフィグも変更したうえで、spi3用に変更した結果です)
>
> どうやったらこのエラーがでるのかを調べてみました。
>
> > > linux-2.6.x/arch/arm/mach-mx25/armadillo400.c:713行目付近
> > >

> > > static struct spi_board_info armadillo400_spi1_board_info[] __initdata = {
> > > +       {
> > > +               .modalias = "spidev",
> > > +               .max_speed_hz = 1000000,
> > > +               .bus_num = 1,
> > > +               .chip_select = 0,
> > > +       },
> > >  };
> > > 

>
> 中カッコが2重にかかっていますが、ソース編集のミスか何かで、
> たとえば次のように1つを消してしまうと、このエラーになるようです。
>
>

> static struct spi_board_info armadillo400_spi1_board_info[] __initdata = 
>       {
>                .modalias = "spidev",
> 

> とか
>

> static struct spi_board_info armadillo400_spi1_board_info[] __initdata = {
>                .modalias = "spidev",
> 

> とか。
>
> --
> なかむら
>

at_takashi.sasayama

2014年12月18日 8時50分

> あとLinux kernelの設定は以下のようになっていました。
> -------------------------------------------------------------------------------------------------------
> [root@armadillo460-0 (ttymxc3) /home/guest]# zcat /proc/config.gz | grep SPI | grep =y
> CONFIG_RWSEM_GENERIC_SPINLOCK=y
> CONFIG_SPI_MXC_SELECT1=y
> CONFIG_ARMADILLO400_SPI1_CON9=y
> CONFIG_ARMADILLO400_SPI1_SS0_CON9_25=y
> CONFIG_ARMADILLO400_SPI1_SS1_CON9_11=y
> CONFIG_ARMADILLO400_CON9_3_CSPI1_MOSI=y
> CONFIG_ARMADILLO400_CON9_5_CSPI1_MISO=y
> CONFIG_ARMADILLO400_CON9_11_CSPI1_SS1=y
> CONFIG_ARMADILLO400_CON9_13_CSPI1_SCLK=y
> CONFIG_ARMADILLO400_CON9_25_CSPI1_SS0=y
> CONFIG_ARMADILLO400_CON9_26_CSPI1_RDY=y
> CONFIG_SPI=y
> CONFIG_SPI_MASTER=y
> CONFIG_SPI_BITBANG=y
> CONFIG_SPI_MXC=y
> -------------------------------------------------------------------------------------------------------

CONFIG_SPI_SPIDEV が有効になっていないようなので、
カーネルコンフィギュレーションで以下も有効にする必要がありますね。

Device Drivers  --->  
    [*] SPI support  --->  
        <*>   User mode SPI device driver support

=======
参考情報
=======
Armadillo実践開発ガイド 第3部 2.3. SPI接続A/Dコンバーター 2.3.5. カーネルコンフィギュレーション
http://manual.atmark-techno.com/armadillo-guide/armadillo-guide-3_ja-2…

n.yamamoto

2014年12月18日 11時53分

Yamamotoです。

実践ガイドに従いSPI3で設定して実施してみましたが同じでした。
笹山さんにも返信したのですが、以前420で試した時は指示いただいたドライバー登録を忘れなければいけていたと思うのですが・・・

以下今回の起動時抜粋とKernelの確認です。
------------------------------------------------------------------------------------------------------------
Hermit-At v2.1.4 (armadillo4x0) compiled at 20:49:45, Feb 23 2012
Uncompressing kernel.......................................................................................................done.
Uncompressing ramdisk..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................done.
Doing console=ttymxc3
Linux version 2.6.26-at20 (2.6.26) (atmark@atde3) (gcc version 4.3.2 (Debian 4.3.2-1.1) ) #6 PREEMPT Thu Dec 18 11:19:41 JST 2014
CPU: ARM926EJ-S [41069264] revision 4 (ARMv5TEJ), cr=00053177
Machine: Armadillo-460
Memory policy: ECC disabled, Data cache writeback
CPU0: D VIVT write-back cache
CPU0: I cache: 16384 bytes, associativity 4, 32 byte lines, 128 sets
CPU0: D cache: 16384 bytes, associativity 4, 32 byte lines, 128 sets
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32512
Kernel command line: console=ttymxc3
MXC IRQ initialized
PID hash table entries: 512 (order: 9, 2048 bytes)
MXC GPT timer initialized, rate = 133000000
Console: colour dummy device 80x30
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory: 128MB = 128MB total
Memory: 102852KB available (3020K code, 221K data, 128K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 480 bytes
NET: Registered protocol family 16
MXC WDOG1 Enabled
CPU is i.MX25 Revision 1.2
Clock input source is 24000000
MXC GPIO hardware
GPIO-56 autorequested
Initializing CPLD: v2
Using SDMA I.API
MXC DMA API initialized
SCSI subsystem initialized
CSPI: mxc_spi-0 probed
CSPI: mxc_spi-2 probed
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
MXC I2C driver
MXC I2C driver
MXC I2C driver
MC34704 regulator successfully probed
mc34704 0-0054: Loaded
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP reno registered
NET: Registered protocol family 1
  :
省略

[root@armadillo460-0 (ttymxc3) /home/guest]# zcat /proc/config.gz | grep SPI | grep =y
CONFIG_RWSEM_GENERIC_SPINLOCK=y
CONFIG_SPI_MXC_SELECT1=y
CONFIG_SPI_MXC_SELECT3=y
CONFIG_ARMADILLO400_SPI3_CON9=y
CONFIG_ARMADILLO400_SPI3_SS0_CON9_16=y
CONFIG_ARMADILLO400_CON9_4_CSPI3_MOSI=y
CONFIG_ARMADILLO400_CON9_6_CSPI3_MISO=y
CONFIG_ARMADILLO400_CON9_12_CSPI3_SCLK=y
CONFIG_ARMADILLO400_CON9_14_CSPI3_RDY=y
CONFIG_ARMADILLO400_CON9_16_CSPI3_SS0=y
CONFIG_SPI=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_BITBANG=y
CONFIG_SPI_MXC=y
CONFIG_SPI_SPIDEV=y
------------------------------------------------------------------------------------------------------------

> > あとLinux kernelの設定は以下のようになっていました。
> > -------------------------------------------------------------------------------------------------------
> > [root@armadillo460-0 (ttymxc3) /home/guest]# zcat /proc/config.gz | grep SPI | grep =y
> > CONFIG_RWSEM_GENERIC_SPINLOCK=y
> > CONFIG_SPI_MXC_SELECT1=y
> > CONFIG_ARMADILLO400_SPI1_CON9=y
> > CONFIG_ARMADILLO400_SPI1_SS0_CON9_25=y
> > CONFIG_ARMADILLO400_SPI1_SS1_CON9_11=y
> > CONFIG_ARMADILLO400_CON9_3_CSPI1_MOSI=y
> > CONFIG_ARMADILLO400_CON9_5_CSPI1_MISO=y
> > CONFIG_ARMADILLO400_CON9_11_CSPI1_SS1=y
> > CONFIG_ARMADILLO400_CON9_13_CSPI1_SCLK=y
> > CONFIG_ARMADILLO400_CON9_25_CSPI1_SS0=y
> > CONFIG_ARMADILLO400_CON9_26_CSPI1_RDY=y
> > CONFIG_SPI=y
> > CONFIG_SPI_MASTER=y
> > CONFIG_SPI_BITBANG=y
> > CONFIG_SPI_MXC=y
> > -------------------------------------------------------------------------------------------------------
>
> CONFIG_SPI_SPIDEV が有効になっていないようなので、
> カーネルコンフィギュレーションで以下も有効にする必要がありますね。
>

> Device Drivers  --->  
>     [*] SPI support  --->  
>         <*>   User mode SPI device driver support
> 

>
> =======
> 参考情報
> =======
> Armadillo実践開発ガイド 第3部 2.3. SPI接続A/Dコンバーター 2.3.5. カーネルコンフィギュレーション
> http://manual.atmark-techno.com/armadillo-guide/armadillo-guide-3_ja-2…

at_takashi.sasayama

2014年12月18日 12時54分

笹山です。

添付ファイルと差し替えて、ビルドしたイメージでは
/dev/spidev1.0 が確認できないでしょうか?

添付ファイル
armadillo400.c
linux-2.6.x/arch/arm/mach-mx25/armadillo400.c と差し替えます。

config-a460-spidev1.txt
linux-2.6.x/.config と差し替えます。

ファイル ファイルの説明
armadillo400.c spidev1.0 を追加
config-a460-spidev1.txt linux-26.26-at20 Armadillo-460用 spidev 有効

n.yamamoto

2014年12月18日 15時07分

Yamamotoです。

頂いたファイルで差し替えると無事にspidev1.0がdevに登録されました。

差分を見るとSS信号を有効にしていないためにコンパイルエラーになっていたように見えるのですが、如何でしょうか?

あと、.configはmenuconfigで設定している内容が登録されているファイルなのでしょうか?

> 笹山です。
>
> 添付ファイルと差し替えて、ビルドしたイメージでは
> /dev/spidev1.0 が確認できないでしょうか?
>
> 添付ファイル
> armadillo400.c
> linux-2.6.x/arch/arm/mach-mx25/armadillo400.c と差し替えます。
>
> config-a460-spidev1.txt
> linux-2.6.x/.config と差し替えます。