# spiService and gpioService are not starting within an Application

**URL:** <https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907>\
**Category:** Legato Application Framework\
**Created:** [July 26, 2021, 7:12pm UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907 "2021-07-26T19:12:34Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon.naegele](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@simon.naegele](https://forum.legato.io/u/simon.naegele)\
**Post date:** [July 26, 2021, 7:12pm UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/1 "2021-07-26T19:12:34Z")

</div>

Hi,  
I want to start the gpioService and the spiService together with my application, but both are never started. Here is my .adef:

```auto
sandboxed: false

executables:
{
	spiMultiTest = ( spiMultiTest )
	spiService = ( $LEGATO_ROOT/components/spiService )
	gpioService = ( $LEGATO_ROOT/components/sysfsGpio )
}

processes:
{
	priority: rt32
	run:
	{
		( spiService )
		( gpioService )
		( spiMultiTest )
	}

    watchdogTimeout: never
}

```

So why is the spiMultiTest starting, but the spiService and gpioService are not started?

Regards,  
Simon

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [July 26, 2021, 8:08pm UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/2 "2021-07-26T20:08:39Z")

</div>

They are already included in the platform services application

> <https://github.com/legatoproject/legato-af/blob/master/apps/platformServices/gpioService.adef>

For example, you should use IPC to communicate with gpioService

> <https://github.com/legatoproject/legato-af/blob/master/apps/sample/gpioCf3Demo/gpioCf3Demo.adef>

---

<div class="post-metadata">

**Author:** ![simon.naegele](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@simon.naegele](https://forum.legato.io/u/simon.naegele)\
**Post date:** [July 27, 2021, 9:48am UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/3 "2021-07-27T09:48:00Z")

</div>

Hi,

I’m aware that they are already included in the platform services.

To give you a bigger picture of what I’m trying to achieve:

1. A GPIO triggers reading from SPI via interrupt
2. The latency between the trigger from GPIO and the SPI chip select is around 3-4 ms, which is way to long for our use-case.
3. We need at least 1ms latency to have enough time to read all of the SPI data

So what I thought:

1. In the docs, IPC is listed to be a function call when components are packed together instead of a socket call.
2. I wanted to test if the function call is way faster than the socket, this is why I wanted to start gpioService, spiService and my own app together.

Is there a better way to do that? How can I get the lowest latency?

Thanks,  
Simon

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [July 27, 2021, 10:40am UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/4 "2021-07-27T10:40:10Z")

</div>

have you tried to implement this in kernel driver module?

Here is an example on using GPIO interrupt on kernel driver module:  
[gpio\_interrupt.rar](https://forum.legato.io/uploads/short-url/vtYYb29GBkKFt9J3wgzCrdBP3Hj.rar) (81.8 KB)

Or you can do the following to directly open the SPI port (/dev/spidev1.0) inside your application instead of calling spiService :

root@swi-mdm9x28-wp:~# insmod /mnt/legato/system/modules/spisvc.ko  
root@swi-mdm9x28-wp:~# ls /dev/spidev1.0  
/dev/spidev1.0

You can see here as example:

> **[Spi linux code example - Programmer Sought](https://www.programmersought.com/article/45661779830/)**
>
> Spi linux code example, Programmer Sought, the best programmer technical posts sharing site.

---

<div class="post-metadata">

**Author:** ![simon.naegele](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@simon.naegele](https://forum.legato.io/u/simon.naegele)\
**Post date:** [July 27, 2021, 10:51am UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/5 "2021-07-27T10:51:41Z")

</div>

No, I haven’t tried a kernel module yet, but that would be the next thing I’d try.

What do you think is the bottleneck for my use-case? IPC, SPI or GPIO?  
Do you know how much latency is caused by the IPC?

Thanks,  
Simon

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [July 27, 2021, 11:04am UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/6 "2021-07-27T11:04:28Z")

</div>

I do not have the exact statistic on the timing on these SPI,GPIO, IPC module.

But I can share my experience with you in this aspect.

I tried to write a legato application to toogle the GPIO state every 250 usec in order to generate a PWM signal of 2000Hz with IPC to GPIO service.  
However, the result is that it can just generate about 950 Hz signal.  
Not even meeting half of the requirement…

Later I tried to implement the PWM signal by kernel driver module with hardware kernel timer.  
The performance is quite good that it can achieve 1.8KHz.

So to reduce latency, I would suggest you making a try on kernel driver module.

---

<div class="post-metadata">

**Author:** ![simon.naegele](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@simon.naegele](https://forum.legato.io/u/simon.naegele)\
**Post date:** [July 28, 2021, 10:16am UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/7 "2021-07-28T10:16:17Z")

</div>

Hi,  
I want to try a kernel module and I’m using the code in gpio\_interrupt.rar.

In the code is a comment that says “LED is 42, mdm\_GPIO=79”

Can you tell me where I can find the pin mapping for mangoYellow? Especially for IOT0 connector?

Regards,  
Simon

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [July 28, 2021, 10:24am UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/8 "2021-07-28T10:24:16Z")

</div>

You can check in dmesg to know the mdm gpio number when you export the gpio

> **[IRQ mode of RPi GPIOs does not work](https://forum.mangoh.io/t/irq-mode-of-rpi-gpios-does-not-work/3723)**
>
> Software setup: WP77xx\_Release12\_GENERIC\_GCF.spk Legato-Dist-Source-mdm9x06-SWI9X06Y\_02.32.02.00.tar.bz2 mangoh git repo commit 57a33ecfabf109e98aee724a24294b18f3c9a4d3 I have tried to use the pin 11 (WP\_GPIO\_1\_lvl) as an interrupt input. From...

---

<div class="post-metadata">

**Author:** ![simon.naegele](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@simon.naegele](https://forum.legato.io/u/simon.naegele)\
**Post date:** [July 28, 2021, 2:46pm UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/9 "2021-07-28T14:46:47Z")

</div>

Hi,  
I build the code from gpio\_interrupt.rar but it is crashing the module (WP7607) and I can’t retrieve any logs why it crashed.

The problem seems to be the call of the function `request_irq()`.

Do you have any idea why?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [July 28, 2021, 3:04pm UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/10 "2021-07-28T15:04:03Z")

</div>

Which gpio are you using?  
Did you check in product technical specification if this gpio can be set to interrupt?

---

<div class="post-metadata">

**Author:** ![simon.naegele](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@simon.naegele](https://forum.legato.io/u/simon.naegele)\
**Post date:** [July 28, 2021, 3:07pm UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/11 "2021-07-28T15:07:23Z")

</div>

I haven’t changed anything from your code. The GPIO is 79, which should be le\_gpio42, right?  
I also already used it in my test code with the gpioService and was able to get an interrupt.

---

<div class="post-metadata">

**Author:** ![simon.naegele](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@simon.naegele](https://forum.legato.io/u/simon.naegele)\
**Post date:** [July 28, 2021, 3:11pm UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/12 "2021-07-28T15:11:09Z")

</div>

I just found out, that the `request_irq` doesn’t seem to be the problem. It’s crashing when I change the GPIO level. So something in calling `ebbgpio_irq_handler` seems to cause the problem

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [July 28, 2021, 3:14pm UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/13 "2021-07-28T15:14:39Z")

</div>

You can clear the code inside the handler and see what happens

---

<div class="post-metadata">

**Author:** ![simon.naegele](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@simon.naegele](https://forum.legato.io/u/simon.naegele)\
**Post date:** [July 28, 2021, 3:20pm UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/14 "2021-07-28T15:20:36Z")

</div>

That’s what I did 🙂 Now it’s working.

The problem seems to be in these lines:

```auto
	struct task_struct* t;
	/* find the task with that pid */
	t = pid_task(find_pid_ns(TargetPID, &init_pid_ns), PIDTYPE_PID);
	send_sig(SIGINT, t, 0);

```

One of these functions crashed the module. Since I don’t need them, I don’t care, but maybe you can fix that before sending it to the next guy that also will waste time on that.

Regards,  
Simon

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [July 29, 2021, 7:36am UTC](https://forum.legato.io/t/spiservice-and-gpioservice-are-not-starting-within-an-application/5907/15 "2021-07-29T07:36:53Z")

</div>

oh yes, you need to delete it.

That part is originally used to wake up a legato application (e.g. hello2)

```auto

1. run the following command to find out the pid of hello2
ps aux | grep hello2
root 1899 0.0 0.5 2932 996 ? S 05:37 0:00 hello2 

2. echo 1899 > /sys/module/helloworld/parameters/TargetPID

```
