With ApolloX can't seem to access the SPI interface

I am running a c++ program under the old Extension, which I could access the SPI interface but I had to have certain settings in the build to make it happen. I had to let the system know that I’m accessing the SPI device and I had to have the spidev library part of the settings in the extension as well as declaring the device to allow access to it. This was working.

What do I have to do in the ApolloX extension? I tried putting in the spidev library, but it doesn’t exist according to torizonpackages.json. I also don’t see anywhere where I need to declare the device. I tried to modify the dockerfiles according to the spi documentation on this website, but again, the new system doesn’t seem to know about spidev.

Any help would be appreciated.

Steve

Greetings @Evets,

had to let the system know that I’m accessing the SPI device

Regarding this point in ApolloX you can manually edit the project’s docker-compose file which controls how your container application gets executed. So for SPI you just simply add a volume/bind-mount to the compose file for the SPI devcie you want to use.

I tried putting in the spidev library, but it doesn’t exist according to torizonpackages.json

What “spidev” library are you referring to? As seen from the documentation here: Add Packages, Libraries and Tools | Toradex Developer Center

torizonpackages.json gets it’s packages from the Debian feeds. When I search the Debian feeds these are the only “spidev” related packages that are found: Debian -- Package Search Results -- spidev

Best Regards,
Jeremias

Hi @jeremias.tx ,

Not really sure how to do that. I see running containers when I debug, but no volume names that match. There is a torizon_portainer_data, is that the volume name I need? There is slso…cpp one.
it is also not clear where I would add the text to do the volume or bind mount add.
I am assuming for the docker compose file, you are talking about the docker-compose.yml file? There isn’t much in there that tells me where to put a:

RUN --mount=type=bind,target=/dev/spidev1.0,source=/,readwrite=true

Statement.

I thought the spidev was a library that gave “user” (vs kernel) access to the spi device. At least that was what I got out of it. When I went back over that section, it was creating a group called spidev and then putting torizon in the group so it had access using the following commands:
RUN groupadd --gid 52 spidev
RUN usermod -a -G spidev torizon

And then you add -D /dev/spidev1.0 (my device) to the CMD to add the arguments to the commandline launch. It runs, but still won’t open the device. I did this in the Dockerfile, not Dockerfile.debug or Docerfile.sdk. I am assuming this is correct.

I tried to do that in the Dockerfile, but it didn’t work as I still couldn’t open the device.

Thanks!
Steve

I am assuming for the docker compose file, you are talking about the docker-compose.yml file? There isn’t much in there that tells me where to put a:

Docker-compose has a well known and documented format. As seen here: Compose file version 3 reference | Docker Docs

If you want to add a device to use in your container then see the devices section here: Compose file version 3 reference | Docker Docs

Simply denote what SPI inteface you want to use in the container. For example:

version: "3.8"
services:
  test:
    image: foo
    devices:
         - "/dev/spiX:/dev/spiX"

Obviously adapt this to your use-case.

RUN groupadd --gid 52 spidev
RUN usermod -a -G spidev torizon

These are not libraries these just standard Linux user groups. You add the torizon user to these groups so that it has permission to access the SPI device that you mapped into the container. You add these to your container’s respective Dockerfile. If you’re running this in debug then add to Dockerfile.debug instead.

And then you add -D /dev/spidev1.0 (my device) to the CMD to add the arguments to the commandline launch

For passing arguments to your application you want to take a look at this: Pass Arguments to Applications | Toradex Developer Center

Best Regards,
Jeremias

Hi @jeremias.tx ,
Thank you so much! That’s was just what I needed!

Steve