Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't change chipSelectHigh #16

Closed
gpelizzo opened this issue Oct 11, 2020 · 13 comments
Closed

can't change chipSelectHigh #16

gpelizzo opened this issue Oct 11, 2020 · 13 comments

Comments

@gpelizzo
Copy link

Looks default chipSelectHigh value is set to true. Updating chipSelectHigh to false either while opening device or using setOptionsSync/setOptions does not change the default and still set to true.

@fivdi
Copy link
Owner

fivdi commented Oct 12, 2020

The example mcp3008-tmp36.js uses an MPC3008 ADC which expects chip select to be pulled low to select the MCP3008. The example functions correctly and reads the temperature indicating that the default value for chipSelectHigh is false which is correct.

If the following program is run:

const spi = require('bindings')('spi');

const mcp3008 = spi.open(0, 0, err => {
  if (err) {
    throw err;
  }

  mcp3008.getOptions((err, options) => {
    if (err) {
      throw err;
    }

    console.log(options);
  });
});

It outputs the following:

{
  mode: 0,
  chipSelectHigh: false,
  lsbFirst: false,
  threeWire: false,
  loopback: false,
  noChipSelect: false,
  ready: false,
  bitsPerWord: 8,
  maxSpeedHz: 125000000
}

As can be seen from the output, the value of chipSelectHigh is false.

This means I can't reproduce the problem that you are seeing. Please provide the following:

  • A description of the SPI device and system being used (Raspberry Pi?)
  • A test program that is as short as possible that can be used to reproduce the problem
  • A photo of the system which shows the wires connecting the SPI device to the Raspberry Pi (or whatever system is being used)

@gpelizzo
Copy link
Author

gpelizzo commented Oct 12, 2020 via email

@fivdi
Copy link
Owner

fivdi commented Nov 14, 2020

Closing as the problem can't be reproduced and no reproduction code is available.

@fivdi fivdi closed this as completed Nov 14, 2020
@bnielsen1965
Copy link

@fivdi Can you reopen this issue, I have a Raspberry Pi Zero W with a Waveshare OLED HAT and I am having the same issue so I can run any tests you need to figure out what is causing the problem.

In my /etc/config.txt I have the following for spi...

dtparam=spi=on
dtoverlay=spi0-1cs

When I use the rpi-gpio library and set the spiCSPolarity to 0 "active low chip select" then I can get the display to work.

When I use spi-device and set chipSelectHigh to false the display does not work, so I get the options and print them out and get...

OPT {
  mode: 0,
  chipSelectHigh: true,
  lsbFirst: false,
  threeWire: false,
  loopback: false,
  noChipSelect: false,
  ready: false,
  bitsPerWord: 8,
  maxSpeedHz: 1000000
}

I have not put a probe on the chip select yet, if the get options is to be believed then an incorrect CS would cause a problem.

@fivdi fivdi reopened this Dec 14, 2020
@fivdi
Copy link
Owner

fivdi commented Dec 14, 2020

Does it work if the following line is removed from /boot/config.txt:

dtparam=spi=on

@bnielsen1965
Copy link

Write is now working, I am getting my display updates, but when I check the options chipSelectHigh is still true even though I set to false.

It also writes very slow and setting speedHz in the messages doesn't seem to change the speed.

@fivdi
Copy link
Owner

fivdi commented Dec 14, 2020

Can you post the following information please:

  • The complete contents of the file /boot/config.txt
  • The complete output of the command dmesg shortly after the Raspberry Pi has been rebooted
  • A short but complete program that can be used to reproduce the error.

@bnielsen1965
Copy link

boot.cfg:

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on
dtoverlay=spi0-1cs

# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
dtoverlay=vc4-fkms-v3d
max_framebuffers=2

[all]
#dtoverlay=vc4-fkms-v3d

dmesg output:

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 5.4.72+ (dom@buildbot) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #1356 Thu Oct 22 13:56:00 BST 2020
[    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] OF: fdt: Machine model: Raspberry Pi Zero W Rev 1.1
[    0.000000] Memory policy: Data cache writeback
[    0.000000] Reserved memory: created CMA memory pool at 0x17c00000, size 64 MiB
[    0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool
[    0.000000] On node 0 totalpages: 114688
[    0.000000]   Normal zone: 1008 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 114688 pages, LIFO batch:31
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0 
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 113680
[    0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 snd_bcm2835.enable_headphones=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 smsc95xx.macaddr=B8:27:EB:6D:0C:B0 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  console=ttyS0,115200 console=tty1 root=PARTUUID=2fca0f1d-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
[    0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes, linear)
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 376112K/458752K available (7858K kernel code, 718K rwdata, 2488K rodata, 512K init, 802K bss, 17104K reserved, 65536K cma-reserved)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] ftrace: allocating 27717 entries in 55 pages
[    0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[    0.000000] random: get_random_bytes called from start_kernel+0x2ac/0x4f0 with crng_init=0
[    0.000025] sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 2147483647500ns
[    0.000091] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns
[    0.000208] bcm2835: system timer (irq = 27)
[    0.000842] Console: colour dummy device 80x30
[    0.001415] printk: console [tty1] enabled
[    0.001510] Calibrating delay loop... 697.95 BogoMIPS (lpj=3489792)
[    0.050404] pid_max: default: 32768 minimum: 301
[    0.050752] LSM: Security Framework initializing
[    0.051125] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.051199] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.053308] Disabling memory control group subsystem
[    0.053634] CPU: Testing write buffer coherency: ok
[    0.055442] Setting up static identity map for 0x8200 - 0x8238
[    0.056698] devtmpfs: initialized
[    0.069998] VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5
[    0.070624] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.070719] futex hash table entries: 256 (order: -1, 3072 bytes, linear)
[    0.079730] pinctrl core: initialized pinctrl subsystem
[    0.081965] NET: Registered protocol family 16
[    0.086771] DMA: preallocated 1024 KiB pool for atomic coherent allocations
[    0.093329] audit: initializing netlink subsys (disabled)
[    0.095644] hw-breakpoint: found 6 breakpoint and 1 watchpoint registers.
[    0.095713] hw-breakpoint: maximum watchpoint size is 4 bytes.
[    0.095921] Serial: AMBA PL011 UART driver
[    0.099771] bcm2835-mbox 2000b880.mailbox: mailbox enabled
[    0.100788] audit: type=2000 audit(0.090:1): state=initialized audit_enabled=0 res=1
[    0.120856] raspberrypi-firmware soc:firmware: Attached to firmware from 2020-10-22 14:06, variant start
[    0.130884] raspberrypi-firmware soc:firmware: Firmware hash is 74e754ff8947c58d2773253f77f6f68a303188f8
[    0.196505] bcm2835-dma 20007000.dma: DMA legacy API manager, dmachans=0x1
[    0.199844] SCSI subsystem initialized
[    0.200172] usbcore: registered new interface driver usbfs
[    0.200329] usbcore: registered new interface driver hub
[    0.200639] usbcore: registered new device driver usb
[    0.203671] clocksource: Switched to clocksource timer
[    1.481302] VFS: Disk quotas dquot_6.6.0
[    1.481527] VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    1.481952] FS-Cache: Loaded
[    1.482401] CacheFiles: Loaded
[    1.503835] thermal_sys: Registered thermal governor 'step_wise'
[    1.504596] NET: Registered protocol family 2
[    1.506147] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes, linear)
[    1.506278] TCP established hash table entries: 4096 (order: 2, 16384 bytes, linear)
[    1.506395] TCP bind hash table entries: 4096 (order: 2, 16384 bytes, linear)
[    1.506499] TCP: Hash tables configured (established 4096 bind 4096)
[    1.506726] UDP hash table entries: 256 (order: 0, 4096 bytes, linear)
[    1.506808] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes, linear)
[    1.507375] NET: Registered protocol family 1
[    1.508809] RPC: Registered named UNIX socket transport module.
[    1.508879] RPC: Registered udp transport module.
[    1.508916] RPC: Registered tcp transport module.
[    1.508950] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    1.510643] hw perfevents: no irqs for PMU, sampling events not supported
[    1.510773] hw perfevents: enabled with armv6_1176 PMU driver, 3 counters available
[    1.516049] Initialise system trusted keyrings
[    1.516649] workingset: timestamp_bits=14 max_order=17 bucket_order=3
[    1.534676] FS-Cache: Netfs 'nfs' registered for caching
[    1.536489] NFS: Registering the id_resolver key type
[    1.536608] Key type id_resolver registered
[    1.536649] Key type id_legacy registered
[    1.536707] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    1.539220] Key type asymmetric registered
[    1.539296] Asymmetric key parser 'x509' registered
[    1.539425] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 249)
[    1.539479] io scheduler mq-deadline registered
[    1.539517] io scheduler kyber registered
[    1.543229] bcm2708_fb soc:fb: FB found 1 display(s)
[    1.556140] Console: switching to colour frame buffer device 82x26
[    1.563936] bcm2708_fb soc:fb: Registered framebuffer for display 0, size 656x416
[    1.577962] bcm2835-rng 20104000.rng: hwrng registered
[    1.581685] vc-mem: phys_addr:0x00000000 mem_base=0x1ec00000 mem_size:0x20000000(512 MiB)
[    1.588931] vc-sm: Videocore shared memory driver
[    1.592893] gpiomem-bcm2835 20200000.gpiomem: Initialised: Registers at 0x20200000
[    1.622351] brd: module loaded
[    1.642042] loop: module loaded
[    1.647466] Loading iSCSI transport class v2.0-870.
[    1.651677] usbcore: registered new interface driver smsc95xx
[    1.654847] dwc_otg: version 3.00a 10-AUG-2012 (platform bus)
[    2.386595] Core Release: 2.80a
[    2.389597] Setting default values for core params
[    2.392522] Finished setting default values for core params
[    2.493676] random: fast init done
[    2.599040] Using Buffer DMA mode
[    2.601897] Periodic Transfer Interrupt Enhancement - disabled
[    2.604825] Multiprocessor Interrupt Enhancement - disabled
[    2.607742] OTG VER PARAM: 0, OTG VER FLAG: 0
[    2.610650] Dedicated Tx FIFOs mode
[    2.614546] WARN::dwc_otg_hcd_init:1072: FIQ DMA bounce buffers: virt = d7d14000 dma = 0x97d14000 len=9024
[    2.620176] FIQ FSM acceleration enabled for :
               Non-periodic Split Transactions
               Periodic Split Transactions
               High-Speed Isochronous Endpoints
               Interrupt/Control Split Transaction hack enabled
[    2.633046] dwc_otg: Microframe scheduler enabled
[    2.633294] WARN::hcd_init_fiq:457: FIQ on core 0
[    2.635930] WARN::hcd_init_fiq:458: FIQ ASM at c05a9d64 length 36
[    2.638504] WARN::hcd_init_fiq:496: MPHI regs_base at dc810000
[    2.641178] dwc_otg 20980000.usb: DWC OTG Controller
[    2.643888] dwc_otg 20980000.usb: new USB bus registered, assigned bus number 1
[    2.646599] dwc_otg 20980000.usb: irq 56, io mem 0x00000000
[    2.649230] Init: Port Power? op_state=1
[    2.651745] Init: Power Port (0)
[    2.654767] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.04
[    2.659944] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    2.662701] usb usb1: Product: DWC OTG Controller
[    2.665487] usb usb1: Manufacturer: Linux 5.4.72+ dwc_otg_hcd
[    2.668257] usb usb1: SerialNumber: 20980000.usb
[    2.672184] hub 1-0:1.0: USB hub found
[    2.675057] hub 1-0:1.0: 1 port detected
[    2.678929] dwc_otg: FIQ enabled
[    2.678947] dwc_otg: NAK holdoff enabled
[    2.678962] dwc_otg: FIQ split-transaction FSM enabled
[    2.678987] Module dwc_common_port init
[    2.679668] usbcore: registered new interface driver usb-storage
[    2.682923] mousedev: PS/2 mouse device common for all mice
[    2.687516] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer
[    2.694196] sdhci: Secure Digital Host Controller Interface driver
[    2.697050] sdhci: Copyright(c) Pierre Ossman
[    2.700631] mmc-bcm2835 20300000.mmcnr: could not get clk, deferring probe
[    2.704864] sdhost-bcm2835 20202000.mmc: could not get clk, deferring probe
[    2.708239] sdhci-pltfm: SDHCI platform and OF driver helper
[    2.712070] ledtrig-cpu: registered to indicate activity on CPUs
[    2.715714] hidraw: raw HID events driver (C) Jiri Kosina
[    2.718972] usbcore: registered new interface driver usbhid
[    2.721867] usbhid: USB HID core driver
[    2.726318] vchiq: vchiq_init_state: slot_zero = (ptrval)
[    2.731654] [vc_sm_connected_init]: start
[    2.742203] [vc_sm_connected_init]: end - returning 0
[    2.748100] Initializing XFRM netlink socket
[    2.750935] NET: Registered protocol family 17
[    2.753874] Key type dns_resolver registered
[    2.757971] registered taskstats version 1
[    2.760706] Loading compiled-in X.509 certificates
[    2.779819] uart-pl011 20201000.serial: cts_event_workaround enabled
[    2.782857] 20201000.serial: ttyAMA0 at MMIO 0x20201000 (irq = 81, base_baud = 0) is a PL011 rev2
[    2.791435] bcm2835-power bcm2835-power: Broadcom BCM2835 power domains driver
[    2.796901] mmc-bcm2835 20300000.mmcnr: mmc_debug:0 mmc_debug2:0
[    2.799927] mmc-bcm2835 20300000.mmcnr: DMA channel allocated
[    2.831490] sdhost: log_buf @ (ptrval) (97d13000)
[    2.873256] mmc1: queuing unknown CIS tuple 0x80 (2 bytes)
[    2.878010] mmc1: queuing unknown CIS tuple 0x80 (3 bytes)
[    2.882506] mmc1: queuing unknown CIS tuple 0x80 (3 bytes)
[    2.885230] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1)
[    2.891422] of_cfs_init
[    2.915015] of_cfs_init: OK
[    2.919585] Waiting for root device PARTUUID=2fca0f1d-02...
[    2.923006] mmc1: queuing unknown CIS tuple 0x80 (7 bytes)
[    2.962343] mmc0: host does not support reading read-only switch, assuming write-enable
[    2.969753] mmc0: Problem switching card into high-speed mode!
[    2.973895] mmc0: new SDHC card at address 0001
[    2.978802] mmcblk0: mmc0:0001 SD16G 14.5 GiB (quirks 0x80000000)
[    2.986546]  mmcblk0: p1 p2
[    3.025945] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[    3.031588] VFS: Mounted root (ext4 filesystem) readonly on device 179:2.
[    3.051358] devtmpfs: mounted
[    3.062113] Freeing unused kernel memory: 512K
[    3.065038] This architecture does not have kernel memory protection.
[    3.067852] Run /sbin/init as init process
[    3.078050] mmc1: new high speed SDIO card at address 0001
[    4.373953] systemd[1]: System time before build time, advancing clock.
[    4.627377] NET: Registered protocol family 10
[    4.632932] Segment Routing with IPv6
[    4.708136] systemd[1]: systemd 241 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid)
[    4.720137] systemd[1]: Detected architecture arm.
[    4.760834] systemd[1]: Set hostname to <raspberrypi>.
[    7.659016] random: systemd: uninitialized urandom read (16 bytes read)
[    7.689655] random: systemd: uninitialized urandom read (16 bytes read)
[    7.694541] systemd[1]: Listening on fsck to fsckd communication Socket.
[    7.703342] random: systemd: uninitialized urandom read (16 bytes read)
[    7.707575] systemd[1]: Started Forward Password Requests to Wall Directory Watch.
[    7.720764] systemd[1]: Listening on Journal Audit Socket.
[    7.728903] systemd[1]: Reached target Swap.
[    7.738353] systemd[1]: Listening on udev Control Socket.
[    7.753385] systemd[1]: Created slice system-systemd\x2dfsck.slice.
[    7.762788] systemd[1]: Listening on Journal Socket (/dev/log).
[    9.754455] systemd[1]: Started Apply Kernel Variables.
[    9.966254] systemd[1]: Started File System Check Daemon to report status.
[   10.550489] systemd[1]: Started Journal Service.
[   11.792801] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[   12.467772] systemd-journald[88]: Received request to flush runtime journal from PID 1
[   14.842920] mc: Linux media interface: v0.10
[   14.894105] vc_sm_cma: module is from the staging directory, the quality is unknown, you have been warned.
[   14.897060] bcm2835_vc_sm_cma_probe: Videocore shared memory driver
[   14.897091] [vc_sm_connected_init]: start
[   14.963800] [vc_sm_connected_init]: installed successfully
[   15.088831] videodev: Linux video capture interface: v2.00
[   15.224078] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[   15.228983] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[   15.231890] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[   15.257225] bcm2835_isp: module is from the staging directory, the quality is unknown, you have been warned.
[   15.261970] bcm2835_v4l2: module is from the staging directory, the quality is unknown, you have been warned.
[   15.293466] snd_bcm2835: module is from the staging directory, the quality is unknown, you have been warned.
[   15.324102] bcm2835-isp bcm2835-isp: Device node output[0] registered as /dev/video13
[   15.331683] bcm2835-isp bcm2835-isp: Device node capture[0] registered as /dev/video14
[   15.344043] bcm2835-isp bcm2835-isp: Device node capture[1] registered as /dev/video15
[   15.346393] bcm2835-isp bcm2835-isp: Device node stats[2] registered as /dev/video16
[   15.346452] bcm2835-isp bcm2835-isp: Register output node 0 with media controller
[   15.346489] bcm2835-isp bcm2835-isp: Register capture node 1 with media controller
[   15.346531] bcm2835-isp bcm2835-isp: Register capture node 2 with media controller
[   15.346588] bcm2835-isp bcm2835-isp: Register capture node 3 with media controller
[   15.351873] bcm2835-isp bcm2835-isp: Loaded V4L2 bcm2835-isp
[   15.352248] bcm2835_codec: module is from the staging directory, the quality is unknown, you have been warned.
[   15.405209] bcm2835_audio bcm2835_audio: card created with 8 channels
[   15.455107] bcm2835-codec bcm2835-codec: Device registered as /dev/video10
[   15.455192] bcm2835-codec bcm2835-codec: Loaded V4L2 decode
[   15.469700] bcm2835-codec bcm2835-codec: Device registered as /dev/video11
[   15.469782] bcm2835-codec bcm2835-codec: Loaded V4L2 encode
[   15.501530] bcm2835-codec bcm2835-codec: Device registered as /dev/video12
[   15.501610] bcm2835-codec bcm2835-codec: Loaded V4L2 isp
[   17.398477] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[   17.828497] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[   18.324124] brcmfmac: F1 signature read @0x18000000=0x1541a9a6
[   18.344244] brcmfmac: brcmf_fw_alloc_request: using brcm/brcmfmac43430-sdio for chip BCM43430/1
[   18.344759] usbcore: registered new interface driver brcmfmac
[   18.388134] brcmfmac mmc1:0001:1: Direct firmware load for brcm/brcmfmac43430-sdio.raspberrypi,model-zero-w.txt failed with error -2
[   18.670376] brcmfmac: brcmf_fw_alloc_request: using brcm/brcmfmac43430-sdio for chip BCM43430/1
[   18.670603] brcmfmac: brcmf_c_process_clm_blob: no clm_blob available (err=-2), device may have limited channels available
[   18.671854] brcmfmac: brcmf_c_preinit_dcmds: Firmware: BCM43430/1 wl0: Oct 22 2019 01:59:28 version 7.45.98.94 (r723000 CY) FWID 01-3b33decd
[   27.521755] random: crng init done
[   27.521783] random: 7 urandom warning(s) missed due to ratelimiting
[   28.006645] uart-pl011 20201000.serial: no DMA platform data
[   28.113818] 8021q: 802.1Q VLAN Support v1.8
[   28.911925] Adding 102396k swap on /var/swap.  Priority:-2 extents:2 across:307200k SSFS
[   29.150609] brcmfmac: brcmf_cfg80211_set_power_mgmt: power save enabled
[   30.629785] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
[   32.272543] Bluetooth: Core ver 2.22
[   32.272732] NET: Registered protocol family 31
[   32.272745] Bluetooth: HCI device and connection manager initialized
[   32.272776] Bluetooth: HCI socket layer initialized
[   32.272796] Bluetooth: L2CAP socket layer initialized
[   32.272839] Bluetooth: SCO socket layer initialized
[   32.295126] Bluetooth: HCI UART driver ver 2.3
[   32.295148] Bluetooth: HCI UART protocol H4 registered
[   32.295264] Bluetooth: HCI UART protocol Three-wire (H5) registered
[   32.295551] Bluetooth: HCI UART protocol Broadcom registered
[   33.203884] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   33.203901] Bluetooth: BNEP filters: protocol multicast
[   33.203933] Bluetooth: BNEP socket layer initialized

Short program attempting to set chipSelectHigh:

const SPIDevice = require('spi-device');

const Config = {
  mode: 0,
  chipSelectHigh: false,
  lsbFirst: false,
  threeWire: false,
  loopback: false,
  noChipSelect: false,
  ready: false,
  bitsPerWord: 8,
  maxSpeedHz: 1000000
};

console.log('OPTIONS', Config);

let spiDevice = SPIDevice.open(0, 0, Config, error => {
  console.log('AFTER OPEN', spiDevice.getOptionsSync())
  spiDevice.setOptionsSync(Config)
  if (error) console.log(error);
  console.log('AFTER SET', spiDevice.getOptionsSync())
});

Program Output:

OPTIONS {
  mode: 0,
  chipSelectHigh: false,
  lsbFirst: false,
  threeWire: false,
  loopback: false,
  noChipSelect: false,
  ready: false,
  bitsPerWord: 8,
  maxSpeedHz: 1000000
}
AFTER OPEN {
  mode: 0,
  chipSelectHigh: true,
  lsbFirst: false,
  threeWire: false,
  loopback: false,
  noChipSelect: false,
  ready: false,
  bitsPerWord: 8,
  maxSpeedHz: 1000000
}
AFTER SET {
  mode: 0,
  chipSelectHigh: true,
  lsbFirst: false,
  threeWire: false,
  loopback: false,
  noChipSelect: false,
  ready: false,
  bitsPerWord: 8,
  maxSpeedHz: 1000000
}

@fivdi
Copy link
Owner

fivdi commented Dec 14, 2020

@bnielsen1965 Thank you for providing the information, it helped a lot.

The good news is that after updating from Linux version 4.19 to 5.4.79-v7+ I can reproduce the error. A description of the issue can be found at raspberrypi/linux#3745

The bad news is that the use of chipSelectHigh is no longer by supported by the underlying operating system calls.

If you want chipSelectHigh to be false, which appears to be the case, then simply don't set it and leave it at it's default value which is false.

In other words, use this:

const Config = {
  mode: 0,
  lsbFirst: false,
  threeWire: false,
  loopback: false,
  noChipSelect: false,
  ready: false,
  bitsPerWord: 8,
  maxSpeedHz: 1000000
};

rather that this:

const Config = {
  mode: 0,
  chipSelectHigh: false,
  lsbFirst: false,
  threeWire: false,
  loopback: false,
  noChipSelect: false,
  ready: false,
  bitsPerWord: 8,
  maxSpeedHz: 1000000
};

Or even better, in your particular case, use this:

const Config = {
  maxSpeedHz: 1000000
};

If an SPI device genuinely requires chipSelectHigh to be true then, to the best of my knowledge, manual GPIO chip-select control would be required.

@fivdi fivdi mentioned this issue Dec 14, 2020
@bnielsen1965
Copy link

Cool, I'm set. I also figured out the slow writes, it was from some debug code I added while testing.

One last question, any insight as to why adding dtparam=spi=on to the boot.cfg resulted in failure?

I was under the assumption that dtparam=spi=on was needed to enable the spidev0.0 but that was apparently an incorrect assumption.

@fivdi
Copy link
Owner

fivdi commented Dec 15, 2020

One last question, any insight as to why adding dtparam=spi=on to the boot.cfg resulted in failure?

In retrospect, I don't think it's necessary to remove dtparam=spi=on form /boot/config.txt. If you add it back and reboot the Pi I think everything will still work.

@bnielsen1965
Copy link

I added dtparam=spi=on back in and rebooted and definitely still works.

Actually, I'm not sure why it wasn't working before. The non-working chipSelectHigh setting wasn't the issue. I guess maybe it had something to do with a reboot, don't know.

Anyhow, at least we got that invalid setting worked out.

@fivdi
Copy link
Owner

fivdi commented Apr 30, 2021

Fixed by 5ee14a5. @gpelizzo @bnielsen1965 Thank you very much for helping out here.

@fivdi fivdi closed this as completed Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants