diff -Nru spi-tools-0.8.1/configure.ac spi-tools-0.8.4/configure.ac --- spi-tools-0.8.1/configure.ac 2016-01-10 23:07:15.000000000 +0000 +++ spi-tools-0.8.4/configure.ac 2019-12-09 06:13:24.000000000 +0000 @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.60]) -AC_INIT(spi-tools, 0.8.1, Christophe Blaess) +AC_INIT(spi-tools, 0.8.4, Christophe Blaess) AM_INIT_AUTOMAKE([foreign]) AM_MAINTAINER_MODE([disable]) @@ -38,11 +38,9 @@ AC_TYPE_UINT32_T AC_TYPE_UINT64_T AC_TYPE_UINT8_T -AC_FUNC_MALLOC AC_FUNC_STRFTIME AC_FUNC_STRTOD AC_FUNC_ERROR_AT_LINE -AC_FUNC_MALLOC AC_CHECK_FUNCS([memmove memset]) AC_CONFIG_SRCDIR([src]) @@ -68,8 +66,8 @@ AC_MSG_NOTICE([Debug Mode on.]) else AC_DEFINE([NDEBUG],[],[No-debug Mode]) - AM_CFLAGS="$AM_CFLAGS -O0" - AM_CXXFLAGS="$AM_CXXFLAGS -O0" + AM_CFLAGS="-O0 $AM_CFLAGS" + AM_CXXFLAGS="-O0 $AM_CXXFLAGS" AC_MSG_NOTICE([Debug Mode off.]) fi diff -Nru spi-tools-0.8.1/debian/changelog spi-tools-0.8.4/debian/changelog --- spi-tools-0.8.1/debian/changelog 2018-03-24 20:03:44.000000000 +0000 +++ spi-tools-0.8.4/debian/changelog 2020-01-22 09:20:11.000000000 +0000 @@ -1,3 +1,9 @@ +spi-tools (0.8.4-1) unstable; urgency=medium + + * Updated to a newer version + + -- Lubomir Rintel Wed, 22 Jan 2020 10:00:00 +0000 + spi-tools (0.8.1-1) unstable; urgency=medium * Initial release (Closes: #893984) diff -Nru spi-tools-0.8.1/debian/patches/0001-Don-t-override-the-compiler-flags-with-nonsense-ones.patch spi-tools-0.8.4/debian/patches/0001-Don-t-override-the-compiler-flags-with-nonsense-ones.patch --- spi-tools-0.8.1/debian/patches/0001-Don-t-override-the-compiler-flags-with-nonsense-ones.patch 2018-03-24 20:03:44.000000000 +0000 +++ spi-tools-0.8.4/debian/patches/0001-Don-t-override-the-compiler-flags-with-nonsense-ones.patch 2020-01-22 09:23:34.000000000 +0000 @@ -3,24 +3,20 @@ Subject: Don't override the compiler flags with nonsense ones --- - configure.ac | 9 ++------- - 1 file changed, 2 insertions(+), 7 deletions(-) + configure.ac | 4 ---- + 1 file changed, 4 deletions(-) diff --git a/configure.ac b/configure.ac -index 32c834a..234c55e 100644 +index dbf9bbe..a1f9fe2 100644 --- a/configure.ac +++ b/configure.ac -@@ -66,17 +66,12 @@ if test x"$debugit" = x"yes"; then - AM_CFLAGS="-g -Wall -Werror -Wno-uninitialized -O0" - AM_CXXFLAGS="-g -Wall -Werror -Wno-uninitialized -O0" +@@ -66,15 +66,11 @@ if test x"$debugit" = x"yes"; then AC_MSG_NOTICE([Debug Mode on.]) --else -- AC_DEFINE([NDEBUG],[],[No-debug Mode]) -- AM_CFLAGS="$AM_CFLAGS -O0" -- AM_CXXFLAGS="$AM_CXXFLAGS -O0" -- AC_MSG_NOTICE([Debug Mode off.]) -+ CFLAGS="$AM_CFLAGS" -+ CXXFLAGS="$AM_CXXFLAGS" + else + AC_DEFINE([NDEBUG],[],[No-debug Mode]) +- AM_CFLAGS="-O0 $AM_CFLAGS" +- AM_CXXFLAGS="-O0 $AM_CXXFLAGS" + AC_MSG_NOTICE([Debug Mode off.]) fi AC_PATH_PROG(HELP2MAN, help2man, echo No help2man ) @@ -30,3 +26,6 @@ ########################################################################## AC_OUTPUT +-- +2.25.0 + diff -Nru spi-tools-0.8.1/man/spi-config.1 spi-tools-0.8.4/man/spi-config.1 --- spi-tools-0.8.1/man/spi-config.1 2016-01-10 23:07:15.000000000 +0000 +++ spi-tools-0.8.4/man/spi-config.1 2019-12-09 06:13:24.000000000 +0000 @@ -26,6 +26,12 @@ \fB\-s\fR, \fB\-\-speed\fR=\fIFREQUENCY\fR set clock frequency (in Hz). .TP +\fB\-r\fR, \fB\-\-spirdy\fR=\fI{0,1}\fR +set the SPI READY mode flag. +.TP +\fB\-s\fR, \fB\-\-wait +block, keeping the file descriptor open. See \fBWAIT OPTION\fR below. +.TP \fB\-h\fR, \fB\-\-help\fR display the help screen and exit. .TP @@ -45,6 +51,11 @@ .TP mode 3 high iddle level, sample on trailing edge. + +.SS "WAIT OPTION" +On some platforms, the speed is reset to a default value when the file descriptor is closed. +To avoid this, one can use the \fB\-w\fR option that keeps the file descriptor open. See also +last example below. .SH EXAMPLES .TP Get help: @@ -55,6 +66,12 @@ .TP Change clock frequency to 1 MHz: $ \fBspi\-config \-\-device=/dev/spidev0.0 \-\-speed=1000000\fR +.TP +Set a configuration and keep the device open: +$ \fBspi\-config \-\-wait \-\-speed=1000000\fR & PID=$! +.TP +Close device previously open: +$ \fBkill\fP $PID .SH AUTHOR Written by Christophe BLAESS . .SH "REPORTING BUGS" diff -Nru spi-tools-0.8.1/man/spi-pipe.1 spi-tools-0.8.4/man/spi-pipe.1 --- spi-tools-0.8.1/man/spi-pipe.1 2016-01-10 23:07:15.000000000 +0000 +++ spi-tools-0.8.4/man/spi-pipe.1 2019-12-09 06:13:24.000000000 +0000 @@ -13,8 +13,11 @@ \fB\-d\fR, \fB\-\-device\fR=\fIDEVICE\fR use the given Linux spidev character device. .TP +\fB\-s\fR, \fB\-\-speed\fR=\fI\fR +set the target SPI speed for transfer. +.TP \fB\-b\fR, \fB\-\-blocksize\fR=\fI\fR -set the block size (in bytes) for transfert. +set the block size (in bytes) for transfer. .TP \fB\-n\fR, \fB\-\-number\fR=\fI\fR set the number of blocks to transmit (-1 for continuous transfert). diff -Nru spi-tools-0.8.1/README.md spi-tools-0.8.4/README.md --- spi-tools-0.8.1/README.md 2016-01-10 23:07:15.000000000 +0000 +++ spi-tools-0.8.4/README.md 2019-12-09 06:13:24.000000000 +0000 @@ -42,6 +42,8 @@ * `-l --lsb={0,1}` LSB first (1) or MSB first (0). * `-b --bits=[7...]` bits per word. * `-s --speed=` set the speed in Hz. +* `-r --spirdy={0,1}` set the SPI_READY spi mode flag. +* `-w --wait` block, keeping the file descriptor open. * `-h --help` help screen. * `-v --version` display the version number. @@ -62,9 +64,24 @@ $ ``` +Note: on some platforms, the speed is reset to a default value when the file descriptor is closed. +To avoid this, one can use the `-w` option that keep the file descriptor open. For example: + +``` +$ spi-config -d /dev/spidev0.0 -s 10000000 -w & +$ PID=$! +``` + +And when you don't need the SPI device anymore: + +``` +$ kill $PID +``` + ### spi-pipe usage #### Options * `-d --device=` use the given spi-dev character device. +* `-s --speed=` Maximum SPI clock rate (in Hz). * `-b --blocksize=` transfer block size in byte. * `-n --number=` number of blocks to transfer. * `-h --help` help screen. diff -Nru spi-tools-0.8.1/src/spi-config.c spi-tools-0.8.4/src/spi-config.c --- spi-tools-0.8.1/src/spi-config.c 2016-01-10 23:07:15.000000000 +0000 +++ spi-tools-0.8.4/src/spi-config.c 2019-12-09 06:13:24.000000000 +0000 @@ -36,6 +36,7 @@ int lsb; // {0,1} (-1 when not configured). int bits; // [7...] (-1 when not configured). uint32_t speed; // 0 when not configured. + int spiready; // {0,1} (-1 when not configured). } spi_config_t; @@ -47,18 +48,21 @@ fprintf(stderr, " -d --device= use the given spi-dev character device.\n"); fprintf(stderr, " -q --query print the current configuration.\n"); fprintf(stderr, " -m --mode=[0-3] use the selected spi mode:\n"); - fprintf(stderr, " 0: low iddle level, sample on leading edge,\n"); - fprintf(stderr, " 1: low iddle level, sample on trailing edge,\n"); - fprintf(stderr, " 2: high iddle level, sample on leading edge,\n"); - fprintf(stderr, " 3: high iddle level, sample on trailing edge.\n"); + fprintf(stderr, " 0: low idle level, sample on leading edge,\n"); + fprintf(stderr, " 1: low idle level, sample on trailing edge,\n"); + fprintf(stderr, " 2: high idle level, sample on leading edge,\n"); + fprintf(stderr, " 3: high idle level, sample on trailing edge.\n"); fprintf(stderr, " -l --lsb={0,1} LSB first (1) or MSB first (0).\n"); fprintf(stderr, " -b --bits=[7...] bits per word.\n"); fprintf(stderr, " -s --speed= set the speed in Hz.\n"); + fprintf(stderr, " -r --spirdy={0,1} consider SPI_RDY signal (1) or ignore it (0).\n"); + fprintf(stderr, " -w --wait block keeping the file descriptor open to avoid speed reset.\n"); fprintf(stderr, " -h --help this screen.\n"); fprintf(stderr, " -v --version display the version number.\n"); } + int main (int argc, char * argv[]) { int opt; @@ -69,14 +73,16 @@ {"query", no_argument, NULL, 'q' }, {"help", no_argument, NULL, 'h' }, {"version", no_argument, NULL, 'v' }, + {"wait", no_argument, NULL, 'w' }, {"mode", required_argument, NULL, 'm' }, {"lsb", required_argument, NULL, 'l' }, {"bits", required_argument, NULL, 'b' }, {"speed", required_argument, NULL, 's' }, + {"spirdy", required_argument, NULL, 'r' }, {0, 0, 0, 0 } }; - spi_config_t new_config = { -1, -1, -1, 0 }; + spi_config_t new_config = { -1, -1, -1, 0, -1 }; spi_config_t config; char * device = NULL; int fd; @@ -84,8 +90,9 @@ uint8_t byte; uint32_t u32; int query_only = 0; + int wait = 0; - while ((opt = getopt_long(argc, argv, "d:qhvm:l:b:s:", options, &long_index)) >= 0) { + while ((opt = getopt_long(argc, argv, "d:qhvwm:l:b:s:r:", options, &long_index)) >= 0) { switch(opt) { case 'q': query_only = 1; @@ -99,7 +106,9 @@ case 'd': device = optarg; break; - + case 'w': + wait = 1; + break; case 'm': if ((sscanf(optarg, "%d", & val) != 1) || (val < 0) || (val > 3)) { @@ -137,10 +146,19 @@ new_config.speed = val; break; + case 'r': + if ((sscanf(optarg, "%d", & val) != 1) + || (val < 0) || (val > 1)) { + fprintf(stderr, "%s: wrong SPI_RDY value ([0,1])\n", argv[0]); + exit(EXIT_FAILURE); + } + new_config.spiready = val; + break; + default: fprintf(stderr, "%s: wrong option. Use -h for help.\n", argv[0]); exit(EXIT_FAILURE); - } + } } if (device == NULL) { @@ -160,6 +178,9 @@ exit(EXIT_FAILURE); } config.mode = byte; + config.spiready = ((config.mode & SPI_READY) ? 1 : 0); + // clear the upper flag bits to be left with mode number + config.mode &= 0x3; if (ioctl(fd, SPI_IOC_RD_LSB_FIRST, & byte) < 0) { perror("SPI_IOC_RD_LSB_FIRST"); exit(EXIT_FAILURE); @@ -177,13 +198,23 @@ config.speed = u32; if (query_only) { - fprintf(stdout, "%s: mode=%d, lsb=%d, bits=%d, speed=%d\n", - device, config.mode, config.lsb, config.bits, config.speed); + fprintf(stdout, "%s: mode=%d, lsb=%d, bits=%d, speed=%d, spiready=%d\n", + device, config.mode, config.lsb, config.bits, config.speed, config.spiready); exit(EXIT_SUCCESS); } // Set the new configuration. - if ((config.mode != new_config.mode) && (new_config.mode != -1)) { + if ((config.spiready != new_config.spiready) && (new_config.spiready == 1)) { + new_config.mode |= SPI_READY; + } + if ((config.mode != new_config.mode) || (config.spiready != new_config.spiready)) { + // In case only the spiready flag was changed + if (new_config.mode == -1) { + new_config.mode = config.mode; + } + if (new_config.spiready == 1) { + new_config.mode |= SPI_READY; + } byte = new_config.mode; if (ioctl(fd, SPI_IOC_WR_MODE, & byte) < 0) { perror("SPI_IOC_WR_MODE"); @@ -213,7 +244,9 @@ exit(EXIT_FAILURE); } } - + if (wait) + for (;;) + pause(); return EXIT_SUCCESS; } diff -Nru spi-tools-0.8.1/src/spi-pipe.c spi-tools-0.8.4/src/spi-pipe.c --- spi-tools-0.8.1/src/spi-pipe.c 2016-01-10 23:07:15.000000000 +0000 +++ spi-tools-0.8.4/src/spi-pipe.c 2019-12-09 06:13:24.000000000 +0000 @@ -38,6 +38,7 @@ fprintf(stderr, "usage: %s options...\n", name); fprintf(stderr, " options:\n"); fprintf(stderr, " -d --device= use the given spi-dev character device.\n"); + fprintf(stderr, " -s --speed= Maximum SPI clock rate (in Hz).\n"); fprintf(stderr, " -b --blocksize= transfer block size in byte.\n"); fprintf(stderr, " -n --number= number of blocks to transfer (-1 = infinite).\n"); fprintf(stderr, " -h --help this screen.\n"); @@ -51,6 +52,7 @@ static struct option options[] = { {"device", required_argument, NULL, 'd' }, + {"speed", required_argument, NULL, 's' }, {"blocksize", required_argument, NULL, 'b' }, {"number", required_argument, NULL, 'n' }, {"help", no_argument, NULL, 'h' }, @@ -66,7 +68,8 @@ int blocknumber = -1; int offset = 0; int nb = 0; - + int speed = -1; + int orig_speed = -1; struct spi_ioc_transfer transfer = { .tx_buf = 0, @@ -77,8 +80,7 @@ .bits_per_word = 0, }; - - while ((opt = getopt_long(argc, argv, "d:b:n:rhv", options, &long_index)) >= 0) { + while ((opt = getopt_long(argc, argv, "d:s:b:n:rhv", options, &long_index)) >= 0) { switch(opt) { case 'h': display_usage(argv[0]); @@ -91,12 +93,18 @@ break; case 'b': if ((sscanf(optarg, "%d", & blocksize) != 1) - || (blocksize < 0) || (blocksize > 16384)) { + || (blocksize <= 0) || (blocksize > 16384)) { fprintf(stderr, "%s: wrong blocksize\n", argv[0]); exit(EXIT_FAILURE); } break; - + case 's': + if ((sscanf(optarg, "%d", & speed) != 1) + || (speed < 10) || (speed > 100000000)) { + fprintf(stderr, "%s: Invalid speed\n", argv[0]); + exit(EXIT_FAILURE); + } + break; case 'n': if ((sscanf(optarg, "%d", & blocknumber) != 1) || (blocknumber < -1)) { @@ -136,6 +144,18 @@ exit(EXIT_FAILURE); } + if (speed != -1) { + if (ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, & orig_speed) < 0) { + perror("SPI_IOC_RD_MAX_SPEED_HZ"); + exit(EXIT_FAILURE); + } + + if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, & speed) < 0) { + perror("SPI_IOC_WR_MAX_SPEED_HZ"); + exit(EXIT_FAILURE); + } + } + while ((blocknumber > 0) || (blocknumber == -1)) { for (offset = 0; offset < blocksize; offset += nb) { nb = read(STDIN_FILENO, & (tx_buffer[offset]), blocksize - offset); @@ -154,6 +174,14 @@ if (blocknumber > 0) blocknumber --; } + + if (orig_speed != -1) { + if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, & orig_speed) < 0) { + perror("SPI_IOC_WR_MAX_SPEED_HZ"); + exit(EXIT_FAILURE); + } + } + free(rx_buffer); free(tx_buffer); if (blocknumber != 0)