I have been working with programming the BBB's SPI interface in python, and have become aware of a large number of issues others may be interested in; if planning on using the SPI interface, I hope this can save others some time. This is ongoing, so some of these issues may not be real in that they may be caused by something else I am doing wrong, so please verify for yourself. If not interested in using the SPI's please just skip.
Background BBB C: Linux BBB3 3.8.13-bone70 #1 SMP Fri Jan 23 02:15:42 UTC 2015 armv7l GNU/Linux (note tried upgrading to bone 76, but archive wasn't found - afraid to upgrade to 3.14 in case everything breaks). Reason for working with SPI: have developed an interface cape and am verifying everything works: Cape Summary: 4-out I2C mux, 1 SPI, 1 UART, 1CAN, 8-pin GPIO, PRU-base logic analyzer (similar to http://beagleboard.org/project/beaglelogic/), programmable regulator (to allow both 3.3 and 5.0 applications), real-time-clock, temp measurement, output voltage measurement, all outputs buffered plus a CAN driver, 256 kbyte EEPROM. As far as I've gotten, the hardware seems to be working (this is the n'th iteration), but am working on software. Reason for post: many issue re BBB's SPI. Have exercised both Adafruit_BBIO.SPI and spidev. Summary, both drivers can work; both drivers have bugs. I will try to summarise in a top down manner. Most of the issues below were identified using the built-in logic analyzer; I think for most people to use the SPI's, it will be necessary to plan on using a logic analyzer. 1) My board is set up to use SPI1 CS0 (chip select 1 is not available); both HDMI and HDMIN have been disabled. Issue; SPI1 can not be used unless device tree for SPI0 is first loaded (see text placed at end so it doesn't crowd up summary). If SPI0 is not loaded first, then device files for spi1 are not found. Note: that Adafruit_BBIO.SPI automatically loads ADAFRUIT-SPI0-00A0.dtbo when Adafruit_BBIO.SPI.SPI(0,0) is instantiated; this must be done before instantiating Adafruit_BBIO.SPI.SPI(1,0). This means pins for SPI0 are not available for other functions. 2) When using ADAFRUIT-SPI1, the chip select line has glitches (i.e. activates) in between writes, usually just a bit after the write, there are no clock pulses at this time, so I doubt this will cause errors. This does not occur when using spidev. I can add a *.png later showing glitches if interest merits. 3) Both Adafruit_BBIO.SPI and spidev support writing using xfer() and xfer2(). From the documentation; xfer: CS will be released and reactivated between blocks. delay specifies delay in µsec between blocks; xfer2: CS will be held active between blocks. Comments: when writing multiple bytes, CS0 goes low, the bytes are transmitted, and then CS0 goes high. I can not find a definition for a "block" and I can not see any discernible difference between the two transactions (i.e. cfer and xfer 2) when looking at the signals using the Logic Analyzer. Summary, you can use either and documentation needs updating. 4) Loading the device trees for either driver gives similar error messages in the tail of dmesg (see text at end). Despite these error messages, the trees load (verified using sudo cat $SLOTS) and the drivers seem to work. 5) The parameters specified in the device trees for spidev (that is BB-SPIDEV0-00A0.dtbo and BB-SPIDEV1-00A0.dtbo) are not used; for example, spi-max-frequency is left at 16MHz and mode is left at 1; I looked into the main device tree and these are not specified there; I can only guess they come from the drivers themselves. This error does not occur for ADAFRUIT-SPI0-00A0.dtbo and ADAFRUIT-SPI1-00A0.dtbo trees. If using spidev, then these parameters should be set in code at initialization time. I will probably use spidev going forward along with specifying the parameters at initialization as the "1 us glitches" of the Adafruit interface worry me. An example of the SPI waveforms when using spidev with d1 looped back to d0 is shown in the attached file. Some error message codes follow below. I hope this helps save others some time. Error when loading spi1 if spi0 has not been loaded: (Pdb) n > /home/martin/programming/CapeGui/SpiMethods.py(39)__init__() -> self.spi = SPI(1,0) (Pdb) n IOError: (2, 'No such file or directory') > /home/martin/programming/CapeGui/SpiMethods.py(39)__init__() -> self.spi = SPI(1,0) (Pdb) Instantiating SPI(1,0) after instantiating SPI(0,0) without an error: -> super(classSPI, self).__init__() (Pdb) n > /home/martin/programming/CapeGui/SpiMethods.py(37)__init__() -> self.spi = SPI(0,0) (Pdb) n > /home/martin/programming/CapeGui/SpiMethods.py(38)__init__() -> if device == 1: (Pdb) n > /home/martin/programming/CapeGui/SpiMethods.py(39)__init__() -> self.spi = SPI(1,0) (Pdb) n > /home/martin/programming/CapeGui/SpiMethods.py(43)__init__() -> self.device = device (Pdb) Errors when loading device trees from dmesg, but drivers still work. [ 53.458947] bone-capemgr bone_capemgr.9: slot #10: dtbo 'BB-SPIDEV1-00A0.dtbo' loaded; converting to live tree [ 53.459214] bone-capemgr bone_capemgr.9: slot #10: #2 overlays [ 53.481230] edma-dma-engine edma-dma-engine.0: allocated channel for 0:45 [ 53.481330] edma-dma-engine edma-dma-engine.0: allocated channel for 0:44 [ 53.501256] edma-dma-engine edma-dma-engine.0: allocated channel for 0:43 [ 53.501317] edma-dma-engine edma-dma-engine.0: allocated channel for 0:42 [ 53.501929] ------------[ cut here ]------------ [ 53.501962] WARNING: at fs/sysfs/dir.c:536 sysfs_add_one+0x59/0x78() [ 53.501970] sysfs: cannot create duplicate filename '/bus/platform/devices/0.channel@0' [ 53.501978] Modules linked in: g_multi libcomposite arc4 ath9k_htc ath9k_common ath9k_hw ath mac80211 cfg80211 rfkill omap_rng uio_pruss(O) [ 53.502053] [<c00114f1>] (unwind_backtrace+0x1/0x9c) from [<c002f4bb>] (warn_slowpath_common+0x33/0x48) [ 53.502069] [<c002f4bb>] (warn_slowpath_common+0x33/0x48) from [<c002f529>] (warn_slowpath_fmt+0x1d/0x28) [ 53.502085] [<c002f529>] (warn_slowpath_fmt+0x1d/0x28) from [<c00ff13d>] (sysfs_add_one+0x59/0x78) [ 53.502104] [<c00ff13d>] (sysfs_add_one+0x59/0x78) from [<c00ff99f>] (sysfs_do_create_link+0xc7/0x188) [ 53.502120] [<c00ff99f>] (sysfs_do_create_link+0xc7/0x188) from [<c02c6fcb>] (bus_add_device+0x77/0xd0) [ 53.502147] [<c02c6fcb>] (bus_add_device+0x77/0xd0) from [<c02c61c3>] (device_add+0x333/0x3d8) [ 53.502171] [<c02c61c3>] (device_add+0x333/0x3d8) from [<c03da0bb>] (of_platform_device_create_pdata+0x37/0x50) [ 53.502191] [<c03da0bb>] (of_platform_device_create_pdata+0x37/0x50) from [<c03db229>] (of_overlay_device_entry_change.isra.0+0x89/0xd4) [ 53.502207] [<c03db229>] (of_overlay_device_entry_change.isra.0+0x89/0xd4) from [<c03db489>] (of_overlay+0x71/0x130) [ 53.502230] [<c03db489>] (of_overlay+0x71/0x130) from [<c02d8829>] (bone_capemgr_load+0x369/0x478) [ 53.502247] [<c02d8829>] (bone_capemgr_load+0x369/0x478) from [<c02d94e7>] (slots_store+0x19b/0x2e8) [ 53.502262] [<c02d94e7>] (slots_store+0x19b/0x2e8) from [<c02c512b>] (dev_attr_store+0xb/0x14) [ 53.502278] [<c02c512b>] (dev_attr_store+0xb/0x14) from [<c00fe2ad>] (sysfs_write_file+0xa9/0x10c) [ 53.502299] [<c00fe2ad>] (sysfs_write_file+0xa9/0x10c) from [<c00bc323>] (vfs_write+0x67/0xfc) [ 53.502314] [<c00bc323>] (vfs_write+0x67/0xfc) from [<c00bc521>] (sys_write+0x29/0x48) [ 53.502335] [<c00bc521>] (sys_write+0x29/0x48) from [<c000c841>] (ret_fast_syscall+0x1/0x46) [ 53.502343] ---[ end trace f9355f0ec79b9e96 ]--- [ 53.502413] of_overlay_device_entry_change: Failed to create platform device for '/ocp/spi@481a0000/channel@0' [ 53.502497] ------------[ cut here ]------------ [ 53.502512] WARNING: at fs/sysfs/dir.c:536 sysfs_add_one+0x59/0x78() [ 53.502519] sysfs: cannot create duplicate filename '/bus/platform/devices/1.channel@1' [ 53.502526] Modules linked in: g_multi libcomposite arc4 ath9k_htc ath9k_common ath9k_hw ath mac80211 cfg80211 rfkill omap_rng uio_pruss(O) [ 53.502700] [<c00114f1>] (unwind_backtrace+0x1/0x9c) from [<c002f4bb>] (warn_slowpath_common+0x33/0x48) [ 53.502715] [<c002f4bb>] (warn_slowpath_common+0x33/0x48) from [<c002f529>] (warn_slowpath_fmt+0x1d/0x28) [ 53.502730] [<c002f529>] (warn_slowpath_fmt+0x1d/0x28) from [<c00ff13d>] (sysfs_add_one+0x59/0x78) [ 53.502746] [<c00ff13d>] (sysfs_add_one+0x59/0x78) from [<c00ff99f>] (sysfs_do_create_link+0xc7/0x188) [ 53.502761] [<c00ff99f>] (sysfs_do_create_link+0xc7/0x188) from [<c02c6fcb>] (bus_add_device+0x77/0xd0) [ 53.502778] [<c02c6fcb>] (bus_add_device+0x77/0xd0) from [<c02c61c3>] (device_add+0x333/0x3d8) [ 53.502796] [<c02c61c3>] (device_add+0x333/0x3d8) from [<c03da0bb>] (of_platform_device_create_pdata+0x37/0x50) [ 53.502813] [<c03da0bb>] (of_platform_device_create_pdata+0x37/0x50) from [<c03db229>] (of_overlay_device_entry_change.isra.0+0x89/0xd4) [ 53.502829] [<c03db229>] (of_overlay_device_entry_change.isra.0+0x89/0xd4) from [<c03db489>] (of_overlay+0x71/0x130) [ 53.502846] [<c03db489>] (of_overlay+0x71/0x130) from [<c02d8829>] (bone_capemgr_load+0x369/0x478) [ 53.502861] [<c02d8829>] (bone_capemgr_load+0x369/0x478) from [<c02d94e7>] (slots_store+0x19b/0x2e8) [ 53.502875] [<c02d94e7>] (slots_store+0x19b/0x2e8) from [<c02c512b>] (dev_attr_store+0xb/0x14) [ 53.502890] [<c02c512b>] (dev_attr_store+0xb/0x14) from [<c00fe2ad>] (sysfs_write_file+0xa9/0x10c) [ 53.502904] [<c00fe2ad>] (sysfs_write_file+0xa9/0x10c) from [<c00bc323>] (vfs_write+0x67/0xfc) [ 53.502918] [<c00bc323>] (vfs_write+0x67/0xfc) from [<c00bc521>] (sys_write+0x29/0x48) [ 53.502933] [<c00bc521>] (sys_write+0x29/0x48) from [<c000c841>] (ret_fast_syscall+0x1/0x46) [ 53.502941] ---[ end trace f9355f0ec79b9e97 ]--- [ 53.504798] of_overlay_device_entry_change: Failed to create platform device for '/ocp/spi@481a0000/channel@1' [ 53.504822] bone-capemgr bone_capemgr.9: slot #10: Applied #2 overlays. > -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.