WP7702 using SPI


#1

Hi,

I am using a WP7702 module and I was wondering if anyone has gotten the spidev working on a similar module? Outcome of running spidev seen below. Related post on Legato forum:

Jan 31 07:03:30 | supervisor[7972]/supervisor T=main | app.c GetDevID() 644 | Could not get file info for ‘/dev/spidev0.0’. No such file or directory.
Jan 31 07:03:30 | supervisor[7972]/supervisor T=main | app.c SetCfgDevicePermissions() 754 | Failed to set permissions (rw) for app ‘spiService’ on device ‘/dev/spidev0.0’.

Spisvc is installed, and lsmod gives this:

root@swi-mdm9x28:~# lsmod
Tainted: G
spisvc 1069 0 - Live 0xbf000000 (O)

Modprobe:

root@swi-mdm9x28:~# modprobe spidev
modprobe: module spidev not found in modules.dep

There is one spidev installed on the module, but it is not working:

root@swi-mdm9x28:~# ls /dev/spi
/dev/spidev1.0

Is this just a firmware / kernel issue?


#2

On the wp76xx and wp77xx, the primary i2c bus is 1 (instead of 0 on the wp85 and wp75). I think we just need to add a few ifdefs to make it work. I will try to do that now.


#3

I have submitted a pull request to the legato-af repository. If you apply this change to your Legato source code and then add the spisvc kernel module to your SDEF, then it should be possible to use the spiService app on the wp77xx or wp76xx platforms.


#4

Hi @dfrey,

Left a comment on your pull request. You can now start spiService with those changes, but it does not read anything from the spi bus. I have a HX711 ADC converter (with a weight sensor) I have used with the WP8548 which works fine, but no readings when connected to WP7702.

root@swi-mdm9x28:~# lsmod
Tainted: G
spisvc 1069 0 - Live 0xbf052000 (O)
9_mangoh_red_dv5 8893 0 - Live 0xbf04b000 (O)
4_bmi160_i2c 1396 0 - Live 0xbf047000 (O)
3_bmp280_i2c 2631 0 - Live 0xbf043000 (O)
3_bmi160 5472 1 4_bmi160_i2c, Live 0xbf03e000 (O)
2_bmp280 9493 1 3_bmp280_i2c, Live 0xbf033000 (O)
0_ltc294x 5575 0 - Live 0xbf02a000 (O)
0_iot_slot 14701 0 - Live 0xbf022000 (O)
0_cp2130 20486 0 - Live 0xbf007000 (O)
0_bq24296 10844 0 - Live 0xbf000000 (O)

root@swi-mdm9x28:~# ls /dev/spi
/dev/spidev1.0

And I did change my code to check for spidev1.0, not 0.0 as for WP8548. Is there some configuration I am missing? Are the parameters / SPI-pins different for WP7702 (MOSI, MISO, CLK)?


#5

I’m going to look at the SPI pins on a logic analyzer and see if anything looks off. I will update later today.


#6

Did you find anything? Just something I forgot previously: changing the speed of the spi device did give different readings (le_spi_Configure()). But the readings were always static, there was no difference. I used 96000bps for WP8548, tried that and different speeds on WP7702 but nothing.


#7

Some other stuff came up so I didn’t get to it. I haven’t forgotten about it though. Will update here when I have some new information.


#8

I ran this code and observed the expected pattern on the CS, CLK and MOSI lines.

COMPONENT_INIT
{
    LE_INFO("===========> SPI application has started");

    le_result_t res;

    spi_DeviceHandleRef_t spiHandle;
    res = spi_Open("spidev1.0", &spiHandle);
    LE_FATAL_IF(res != LE_OK, "spi_Open failed with result=%d", res);

    LE_INFO("Configuring SPI");
    spi_Configure(spiHandle, 0, 8, 960000, 0);

    LE_INFO("Performing a SPI write of 16 bytes");
    {
        const uint8_t writeData[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
        LE_ASSERT_OK(spi_WriteHD(spiHandle, writeData, NUM_ARRAY_MEMBERS(writeData)));
    }
    LE_INFO("SPI write completed successfully");

    spi_Close(spiHandle);
}

I will try to connect a device now to test the read behavior.


#9

I successfully performed a loopback test and also did a read of a register on the CAN IoT card and got a valid value back. One small detail is that I’m using a WP76 using release 8, not a WP77, but I don’t expect there to be a difference.

Can you try a loopback test?


#10

Hi @dfrey,

With loopback test you simply sent data master->slave->master and checked data was still the same? So using spiWriteReadFD / spiWriteReadHD function?

I can do some testing on Monday. There is only Release 7 available, maybe there were some changes to Release 8? Could you provide me with a beta version of the new release so I can try it out as well?
Our contact person who provided us with the WP77xx module said he would look into it and see if we could try it out. Thanks, and have a great weekend!


#11

The loopback test is achieved by wiring the MOSI and MISO lines together and then using spiWriteReadFD. The spiWriteReadHD function is useless in this case because there will be no data being driven on MOSI when MISO is being read. I think wp76 release 8 will show up in the next couple days on source.sierrawireless.com. I looked at the changes though and I don’t see anything relating to SPI so I doubt that will make a difference.


#12

Unfortunately looks like I will not have time right now to do further testing with the SPI. But I will get back to you if/when I have tried it out.


#13

Hi @dfrey,

Unfortunately it is a bit difficult for me to run the loopback test, but I have been testing the weight sensor again with WP77. For some reason I cannot get it reading properly. Have you, or someone else, tried with a WP77?

This is the function I am running (if you want I can give the whole code):

int32_t readWeightSensor(){
size_t readBufferSize = NUM_ARRAY_MEMBERS(rxData);
res = le_spi_WriteReadFD(spiHandle, txData, NUM_ARRAY_MEMBERS(txData), rxData, &readBufferSize);
LE_FATAL_IF(res != LE_OK, “le_spi_WriteReadFD failed with result=%s”, LE_RESULT_TXT(res));
int32_t weight = transform_to_weight_bits(rxData);
return (weight-683500)/2180; // Calibration
}

And the init:

LE_INFO(“Opening SPI file handle”);
res = le_spi_Open(“spidev1.0”, &spiHandle);
LE_FATAL_IF(res != LE_OK, “le_spi_Open failed with result=%s”, LE_RESULT_TXT(res));
LE_INFO(“Configuring SPI”);
le_spi_Configure(spiHandle, 3, 8, 960000, 0);

This same code is working on a WP8548 (except for the change to spidev 0.0). Any help here would be appreciated! Thanks.


#15

Hi @basti,

you need to change your spiService.adef in legato AF to adapt it to your module. I’ll explain :

As it is described in legato.io, Services APIs allows to access the APIs the associated services must be running on the Legato System before you can use the API.

In your case SpiService App allows to :

using LEGATO SPI API.
using /dev/spidev (bus. device)
by default, it uses /dev/spidev0.0 bus, but for wp77xx is different, because this module uses the /dev/spidev1.0 bus
TO CHANGE THE SPISERVICE :

Do: vi ~/legato_framework/legato-18.01.0/apps/platformServices/spiService.adef
and change the spidev.

version: 0.1.0
sandboxed: true
start: auto
executables:
{
spiService = ( LEGATO_ROOT/components/spiService ) } processes: { envVars: { LE_LOG_LEVEL = INFO } run: { (spiService) } faultAction: restart #if {LEGATO_SERVICES_WDOG_DISABLE} = 1
watchdogTimeout: never
#else
watchdogTimeout: 120000
#endif
}
requires:
{
device:
{
[rw] /dev/spidev1.0/dev/**********************HERE
}
extern:
{
spiService.spiService.le_spi
}
bindings:
{
spiService.watchdogChain.le_wdog -> .le_wdog
}

  1. go to : ~/legato_framework/legato-18.01.0 and do make wp77xx ( to compile legato AF for new changes )
  2. go to ~/legato_framework/legato-18.01.0/build/wp77xx/system/app/spiService
    o you find spiService.wp77xx.update (check the build date)

drwxrwxr-x 5 mangoh mangoh 4096 Jun 21 16:36 ./
drwxrwxr-x 25 mangoh mangoh 4096 Jun 21 16:34 …/
drwxrwxr-x 3 mangoh mangoh 4096 Jun 21 16:34 obj/
-rw-rw-r-- 1 mangoh mangoh 20848 Jun 21 16:40 spiService.wp77xx
-rw-rw-r-- 1 mangoh mangoh 20969 Jun 21 16:40 spiService.wp77xx.update
drwxrwxr-x 3 mangoh mangoh 4096 Jun 21 16:34 src/
drwxrwxr-x 3 mangoh mangoh 4096 Jun 21 16:40 staging/

you do : update spiService.wp77xx.update 192.168.2.2 (to flash your target with a new spiService app)

  • In your target *

root@swi-mdm9x28:~# app status
[running] atAirVantage
[running] atQmiLinker
[running] atService
[running] audioService
[running] avcService
[running] cellNetService
[running] dataConnectionService
[running] fwupdateService
[running] gpioService
[running] modemService
[running] portService
[running] positioningService
[running] powerMgr
[running] secStore
[stopped] smsInboxService
[stopped] tools
[stopped] voiceCallService
[stopped] wifi
[stopped] wifiApTest
[stopped] wifiClientTest
[running] wifiService
[stopped] wifiWebAp
[stopped] spiService
[stopped] spiFORspi
root@swi-mdm9x28:~# ls /dev/spidev*
ls: /dev/spidev*: No such file or directory
root@swi-mdm9x28:~# insmod spisvc.ko
root@swi-mdm9x28:~# ls /dev/spidev*
/dev/spidev1.0
In the scope we can see the signal of the clock that corresponds to mode 0
root@swi-mdm9x28:~# app start spiService
root@swi-mdm9x28:~# app status
[running] atAirVantage
[running] atQmiLinker
[running] atService
[running] audioService
[running] avcService
[running] cellNetService
[running] dataConnectionService
[running] fwupdateService
[running] gpioService
[running] modemService
[running] portService
[running] positioningService
[running] powerMgr
[running] secStore
[stopped] smsInboxService
[stopped] tools
[stopped] voiceCallService
[stopped] wifi
[stopped] wifiApTest
[stopped] wifiClientTest
[running] wifiService
[stopped] wifiWebAp
[running] spiService
[stopped] spiFORspi