WP7702 using SPI

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?

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.

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.

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)?

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

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.

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.

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.

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?

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!

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.

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.

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.

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

Hi @dfrey

I am trying to use spiService for an external device. I had connected device to RPi connector (SPI0).

I tried to run the spiService, but it wont return/exit.

Jan 6 04:04:26 swi-mdm9x28 user.info Legato: INFO | supervisor[655]/supervisor T=main | app.c app_Start() 2926 | Starting app ‘spiService’
Jan 6 04:04:26 swi-mdm9x28 user.info Legato: INFO | supervisor[655]/supervisor T=main | kernelModules.c ExecuteCommand() 190 | Execute ‘/legato/systems/current/modules/files/spisvc/scripts/install.sh /legato/systems/current/modules/spisvc.ko’

I checked the install.sh…there is a forever loop running. probably, it is not finding /dev/spisvc. I dont see that either in /dev.

KO_PATH="$1"
insmod “$KO_PATH”

while [ -z “$(find -name “/dev/spisvc*”)” ]
do
sleep 1
done

I dont see the /dev/spisvc. but lsmod shows that spisvc exist.

root@swi-mdm9x28:/dev# lsmod
Tainted: G
spisvc 1069 0 - Live 0xbf003000 (O)

I do see that spidev1.0 available in /dev.

my application will not run because execution of spiService is stuck in the loop.

Any hack to jump out of this?

Thanks
Madan

The Legato 18.07.0 release was a bit screwed up. A commit snuck in which broke SPI. I have updated the Legato_patches repository for 18.07.0 to include a patch which corrects the SPI issue.

@dfrey, Thank you for the quick update.

It got me going. However, I got into a small issue. Maybe you know why.
I am getting only zeros. I am using a MAX6675 breakout board.

SO -> pin 21
CS -> pin 24
SCLK -> Pin 23

Config -
le_spi_Configure(spiHandle, 0, 8, 4300000, 0);
I tried different values for mode and frequency.

Any ideas where the issue might be?

Regards

Hi @dfrey,

I tried the loopback suggestion.
Connected MISO, MOSI pins together.

Here is the test code. But I get zeros in the read buffer.
Appreciate your suggestions on this.

le_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};
    uint8_t readBuffer[20] = {0,};
    uint32_t readBufferSize = NUM_ARRAY_MEMBERS(writeData);
    //LE_ASSERT_OK(le_spi_WriteHD(spiHandle, writeData, NUM_ARRAY_MEMBERS(writeData)));
    res = le_spi_WriteReadFD(spiHandle,writeData, NUM_ARRAY_MEMBERS(writeData), readBuffer,&readBufferSize );
    if (res == LE_OK){
        int i; 
        for (i = 0; i < readBufferSize; i++)
            LE_INFO("0x%X ",readBuffer[i]);
    }
    else{
        LE_FATAL_IF(res != LE_OK, "le_spi_WriteReadFD failed with result=%s", LE_RESULT_TXT(res));
    }

}
LE_INFO("SPI write completed successfully");

I tried to ensure that the TC module functionality with Arduino and RPi. It is working on both setups using SPI.
Please advise if I am missing something here on mangOH.

Thanks for your support.

A quick update on the SPI on mangOH Red 18.07.0…
I tried to capture the CLK and CS0 on an oscilloscope. Unfortunately, CS0 is stuck at HIGH and CLK at LOW. No change in them, even at different frequencies (modified through spi_config).

Looks like something broken with SPI on RPI connector. Or Something not configured properly.
@dfrey, @asyal need some help here to get SPI working on RPI connector.

Thanks for your support.