From 0d8ed9c0de7c36cef25ad9d54775765420e0dd86 Mon Sep 17 00:00:00 2001 From: David Alessio Date: Thu, 17 Oct 2019 14:05:44 +0000 Subject: [PATCH] Merged in david_alessio/apps/bugfix/spitool-exch-parse-txdata (pull request #202) Bugfix/spitool exch parse txdata * friendlier I2C "knock-knock" uses only read request While many I2C slave devices have multiple indexed registers, some have only one register and it's not indexed. For example, the I2C bus switch TCA9548A has only a Control Register, attempting to index to "Reg[0]" alters its contents to 0x00 disabling all subordinate buses. This patch fixes that problem by simply trying to read something/anything from the slave. This also helps coax out slaves with register files that start from a higher index, i.e. the AT24CS0x, FLASH chips with a UUID that appears as a 2nd I2C slave at (address+8), report their serial number at Reg[80]-Reg[8F] and will NAK a read of Reg[0]. * modify get/set to prevent write of reg index if not specifed * correctly parse exch txdata args, if any * should always call the board's deselect Approved-by: Gregory Nutt --- system/spi/spi_exch.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/system/spi/spi_exch.c b/system/spi/spi_exch.c index ebfa3d3c0..087d50bb8 100644 --- a/system/spi/spi_exch.c +++ b/system/spi/spi_exch.c @@ -105,7 +105,14 @@ int spicmd_exch(FAR struct spitool_s *spitool, int argc, FAR char **argv) /* There may be transmit data on the command line */ - if (argndx < argc) + if (argc - argndx > spitool->count) + { + spitool_printf(spitool, g_spitoomanyargs, argv[0]); + return ERROR; + } + + + while (argndx < argc) { FAR uint8_t *a = (uint8_t *)argv[argndx]; while (*a) @@ -125,12 +132,6 @@ int spicmd_exch(FAR struct spitool_s *spitool, int argc, FAR char **argv) argndx += 1; } - if (argndx != argc) - { - spitool_printf(spitool, g_spitoomanyargs, argv[0]); - return ERROR; - } - /* Get a handle to the SPI bus */ fd = spidev_open(spitool->bus); @@ -148,7 +149,7 @@ int spicmd_exch(FAR struct spitool_s *spitool, int argc, FAR char **argv) seq.ntrans = 1; seq.trans = &trans; - trans.deselect = false; + trans.deselect = true; #ifdef CONFIG_SPI_CMDDATA trans.cmd = spitool->command; #endif