-
Notifications
You must be signed in to change notification settings - Fork 102
Description
I am using the MCC128 on an RPi4 and occasionally encounter the RESULT_TIMEOUT issue. This error appears to occur randomly, after the successful call of last mcc128_a_in_scan_read in following mcc128_a_in_scan_stop, whereupon the call of mcc128_a_in_scan_cleanup also failed. Then no further SPI communication worked.
Simple C-Program to reproduce
bugtest.c
- Open and then repeat in a loop until crash
Loop:
-
Setup: A_IN_MODE_DIFF, A_IN_RANGE_BIP_10V,
-
scan_start: 2-Channels, 50kHz-Scanrate,OPTS_CONTINUOUS
-
scan_read: 500 Samples(10ms mea-time), 20ms timeout (double time as for 500 Samples)
-
Stop and clean up
-
repeat
Already compiled for aarch64
bugtest.zip
My setup runs on a Buildroot OS with a preemptible kernel (Low-Latency Desktop) and the latest DAQHat release (v1.5.0.0, commit 9d0972d).
In my app the capture process is not controlled by the main thread of the application, but by a dedicated worker thread. The capture is initiated in the worker thread's initialization, and the scan buffer is copied into the larger buffer within the worker thread's loop.
In this error state, neither my application nor the provided examples work correctly.
A reboot does not resolve the issue, but toggling the 5V Power or RESET line (GPIO16) or calling mcc128_firmware_update—which also toggles the reset—does fix it.
The process fails with RESULT_TIMEOUT (-3) on the first call to _spi_transfer, which is usually the initial CMD_ID frame.
I figured it out by adding debug output to a modified version of [mcc128.c] (https://github.com/user-attachments/files/25080445/mcc128.c) and enabling dynamic debug in the SPI kernel module.
I also tried sending the CMD_ID Frame directly using spidev_test. In a normal state, I receive a response, but in the failure state, the result is just zeroes.
- Here is the output from the bash test script in the failure state:
do gpioset gpiochip0 12=0 13=0 26=0
line 12: "GPIO12" "gpioset" output active-high [used]
line 13: "GPIO13" "gpioset" output active-high [used]
line 26: "GPIO26" "gpioset" output active-high [used]
spi mode: 0x1
bits per word: 8
max speed: 18000000 Hz (18000 kHz)
TX | DB 41 00 00 00 00 00 00 00 00 |.A........|
RX | 00 00 00 00 00 00 00 00 00 00 |..........|
- with RESET set to high:
sudo gpioset -m signal gpiochip0 16=1
TX | DB 41 00 00 00 00 00 00 00 00 |.A........|
RX | FF FF FF FF FF FF FF FF FF FF |..........|
- and after RESET is low again
TX | DB 41 00 00 00 00 00 00 00 00 |.A........|
RX | FF DB 41 00 04 00 46 01 01 01 |..A...F...|
Below is the output log from my app with debug output
09:32:05.854 [Debug] [DAQ.Capture_Start]: -> Start capture 10000 samples
09:32:05.854 [Debug] [DAQ.Capture_Start]: <- done
09:32:05.854 [Debug] [HandleCmds_MainLoop]: <--done with succsess
09:32:05.861 [Debug] [DAQ.MccDaqHat_StartScan]: Continuous scan started , ChMask=0b00000011, ScanFreq=50000Hz,
09:32:05.861 [Debug] [DAQ.MccDaqHat_StartScan]: Internal buffer size for 200000 samples (for all active channels)
09:32:05.861 [Debug] [DAQ.Capture_ExecuteInThread]: Read 500 scans fraction, it takes 0.012.6s waittime
09:32:05.861 [Debug] [DAQ.Capture_ExecuteInThread]: Set timeout: 0.0200s
09:32:06.064 [Info] [DAQ.ProcessFraction]: Capture done, 10000 valid Samples captured
(call to mcc128_a_in_scan_read)
09:32:06.064 [Debug] [DAQ.Capture_ExecuteInThread]: Capture finished with success
09:32:06.064 [Debug] [DAQ.MccDaqHat_ScanStopCleanUp]: do stop and cleanup
(call to mcc128_a_in_scan_stop)
call to _spi_transfer in mcc128
[MCC128][SPI][ERROR][120726.084893s]
stage=WAIT_FIRST_BYTE addr=0x00 cmd=0x14 (CMD_AINSCANSTOP)
result=-3 elapsed_us=20044 timeout_us=20000
[MCC128][SPI][ERROR][120726.084952s]
stage=NO_REPLY addr=0x00 cmd=0x14 (CMD_AINSCANSTOP)
result=-3 elapsed_us=20102 timeout_us=20000
exit from mcc128_a_in_scan_stop with -3
09:32:06.085 [Error] [DAQ.DoError]: FAILURE in DAQ.mcc128_a_in_scan_stop: -3 (RESULT_TIMEOUT) There was a timeout accessing a resource.
(call to mcc128_a_in_scan_cleanup)
call to _spi_transfer in mcc128
[MCC128][SPI][ERROR][120726.086151s]
stage=WAIT_FIRST_BYTE addr=0x00 cmd=0x12 (CMD_AINSCANSTATUS)
result=-3 elapsed_us=1016 timeout_us=1000
[MCC128][SPI][ERROR][120726.086195s]
stage=NO_REPLY addr=0x00 cmd=0x12 (CMD_AINSCANSTATUS)
result=-3 elapsed_us=1061 timeout_us=1000
call to _spi_transfer in mcc128
[MCC128][SPI][ERROR][120726.106775s]
stage=WAIT_FIRST_BYTE addr=0x00 cmd=0x14 (CMD_AINSCANSTOP)
result=-3 elapsed_us=20010 timeout_us=20000
[MCC128][SPI][ERROR][120726.106818s]
stage=NO_REPLY addr=0x00 cmd=0x14 (CMD_AINSCANSTOP)
result=-3 elapsed_us=20053 timeout_us=20000
exit from mcc128_a_in_scan_cleanup with -3
09:32:06.110 [Debug] [DAQ.OnCaptureTerminate]: terminated
In this latched state an "single_value_read" example fails
sudo /opt/mccdaq/examples/single_value_read
--- mcc128_open adr= 0
[MCC128][SPI][ERROR][124067.743856s]
stage=WAIT_FIRST_BYTE addr=0x00 cmd=0x41
result=-3 elapsed_us=20018 timeout_us=20000
[MCC128][SPI][ERROR][124067.743964s]
stage=NO_REPLY addr=0x00 cmd=0x41
result=-3 elapsed_us=20127 timeout_us=20000
[MCC128][SPI][ERROR][124067.764192s]
stage=WAIT_FIRST_BYTE addr=0x00 cmd=0x41
result=-3 elapsed_us=20009 timeout_us=20000
[MCC128][SPI][ERROR][124067.764278s]
stage=NO_REPLY addr=0x00 cmd=0x41
result=-3 elapsed_us=20095 timeout_us=20000
Error: There was a timeout accessing a resource.
Error: An incorrect parameter was passed to the function.
Found almost similar closed issue #14
According to esmcc128.pdf, the speed is 18 MHz, but I found some documents listing 10 MHz for the MCC118.
The DAQ HAT is not the first on the hat stack, but the second. Perhaps this pin header distance affects signal integrity.
Should I try reducing the SPI speed, for example to 16 MHz in mcc128.c, to improve long-term stability?
static const uint32_t spi_speed = 16000000;
I would be grateful if anyone could give me advice on diagnosing and fixing this bug.
some more info
``` pi@box:~$ uname -a Linux box 6.12.61-v8 #1 SMP PREEMPT Fri Jan 30 17:02:48 CET 2026 aarch64 GNU/Linux ```/boot/config.txt
#https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README
# See http://buildroot.org/manual.html#rootfs-custom
# and http://elinux.org/RPiconfig for a description of config.txt syntax
start_file=start4.elf
fixup_file=fixup4.dat
kernel=Image
gpu_mem_256=16
gpu_mem_512=16
gpu_mem_1024=16
arm_boost=1
arm_64bit=1
force_turbo=1
core_freq=250
core_freq_min=250
dtoverlay=disable-bt
dtoverlay=disable-wifi
dtparam=spi=on
dtparam=spi_dma4=on
dtoverlay=spi0-1cs
dtparam=i2c1=on
dtparam=i2c1_baudrate=200000
dtparam=audio=off
dtoverlay=pca953x,pca9535,addr=0x20
Kernel 6.12.61 and libdaqhats.so.1.5.0.0 are crosscompiled with buildroot internal GNU Toolchain.
$ ./host/bin/aarch64-buildroot-linux-gnu-gcc --version
aarch64-buildroot-linux-gnu-gcc.br_real (Buildroot 2025.02.9-21-g6829a555b3) 13.4.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Kernlen config fragment
$ grep -E "^CONFIG_(SPI|SPIDEV|SPI_BCM|DMA_ENGINE|DMA_BCM2835)" ./build/linux-custom/.config
CONFIG_SPI=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_MEM=y
CONFIG_SPI_BCM2835=m
CONFIG_SPI_BCM2835AUX=m
CONFIG_SPI_BITBANG=m
CONFIG_SPI_DESIGNWARE=m
CONFIG_SPI_DW_DMA=y
CONFIG_SPI_DW_MMIO=m
CONFIG_SPI_GPIO=m
CONFIG_SPI_RP2040_GPIO_BRIDGE=m
CONFIG_SPI_SPIDEV=m
CONFIG_SPI_SLAVE=y
CONFIG_SPI_DYNAMIC=y
CONFIG_DMA_ENGINE=y
CONFIG_DMA_BCM2835=y
Device-Tree spi fragment
spi@7e204000 {
pinctrl-names = "default";
#address-cells = <0x01>;
pinctrl-0 = <0x0e 0x0f>;
interrupts = <0x00 0x76 0x04>;
clocks = <0x08 0x14>;
#size-cells = <0x00>;
dma-names = "tx", "rx";
compatible = "brcm,bcm2835-spi";
status = "okay";
reg = <0x7e204000 0x200>;
phandle = <0x46>;
dmas = <0x2e 0x06 0x2e 0x07>;
cs-gpios = <0x07 0x08 0x01>;
spidev@0 {
#address-cells = <0x01>;
#size-cells = <0x00>;
spi-max-frequency = <0x7735940>;
compatible = "spidev";
reg = <0x00>;
phandle = <0xbe>;
};
spidev@1 {
#address-cells = <0x01>;
#size-cells = <0x00>;
spi-max-frequency = <0x7735940>;
compatible = "spidev";
status = "disabled";
reg = <0x01>;
phandle = <0xbf>;
};
};
Compiling mcc128.c
/home/BR/Builds/RPI4_64/host/bin/aarch64-buildroot-linux-gnu-gcc -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -g0 -D_FORTIFY_SOURCE=1 -I/home/BR/Builds/RPI4_64/build/mccdaq-9d0972d40cb551240595e7ccc9010416517e07c5/include -I/home/BR/Builds/RPI4_64/build/mccdaq-9d0972d40cb551240595e7ccc9010416517e07c5/lib -MMD -c mcc128.c -o build/mcc128.o
Linking all to lib
/home/BR/Builds/RPI4_64/host/bin/aarch64-buildroot-linux-gnu-gcc -L/opt/vc/lib -zdefs -shared -pthread -Wl,-soname,libdaqhats.so.1 -o build/libdaqhats.so.1.5.0.0 build/util.o build/mcc118.o build/mcc152.o build/mcc152_dac.o build/mcc152_dio.o build/gpio.o build/cJSON.o build/mcc134.o build/mcc134_adc.o build/nist.o build/mcc172.o build/mcc128.o -lm -lgpiod