Stable snap using serial-port

Hi,

I’m a bit new to snap, but I am trying to create a snap for a Raspberry Pi clone (UP Squared). I want to be able to put it on the stable channel, but don’t mind if I need to configure some things with the snap first.

Unfortunately the app requires some hardware resources (usb and serial-ports). The Usb-interface was really easy to manage. I just put in a plug for raw-usb and used snap connect [snap-name]:raw-usb to connect it to my device. I then tried the same for the serial-port but it is not included in the core and thus needs to be connected to a slot. I tried to add a slot to the snapcraft.yaml file but it gets rejected because it needs to be a snap of type gadget.

Does anyone know a fix to make a slot, a gadget with serial-ports for the UP Squared or some other way to fix this issue?

To have a serial-port plug, you will indeed have to have a gadget expose that plug.

By default, the pi-gadget does not expose such a plug (https://github.com/snapcore/pi-gadget/blob/18-armhf/snapcraft.yaml).

If you’re already using a custom gadget which you maintain, you can add it by following Gadget providing serial-port slot, note if you’re using a pure serial-port, you can omit the usb-* declarations

I myself use this method and it works.

my-serial-slot:
    interface: serial-port
    path: /dev/ttyAMA0

After which you can use

snap connect your-snap:serial-port :my-serial-slot

Hi,

Thanks for the quick response. This is indeed what I would want for the snap. I’m just confused how to get this to work with my snap.

Should I add the extra files, the parts (grub and grub-prepare), my required slots and the gadget.yaml to my own snap and change it to a gadget type or should I make a different snap with this example and only use it to connect the serial-port slot? I also don’t understand the final step to create a pc.img file. What should I do with that file exactly?

Sorry if I’m missing the point of the explanation.

Which serial-port are you attempting to use? Is this a dynamically generated serial-port for a USB device per-chance? If that’s the case, you should try enabling hot-plug support and then see if your device shows up as a serial-port interface slot when it is connected.

It is showed as /dev/ttyS5 and /dev/ttyS6. The physical connection is with the GPIO pin 8 and 10 (the up squared has the same 40-pin layout as a pi). I don’t think it will work since it is not USB, but I could try to use it.

Just tried to hotplug method, but it didn’t work. It connected the serial-port interface to my other usb-device that I had already connected to raw-usb. It didn’t give any warnings, but I couldn’t get acces to the correct serial port. But still thanks for the help.