STLink server on a Linux server


I’m currently doing a project with STM32 and radios. I want to have a server with all the stm32’s connected, with UART, USB and ST-Link v2. I’m using a laptop as my development computer and don’t want to plug the connections in and out all the time. Therefor I installed a Linux server which will host this for me.

Configuring

Download and install openstm32 (you will get some udev rules for the stlink devices)

Download and install st-link server from st.com [1].

Create a systemd start file:
cat /etc/systemd/system/stlink-server.service
[Unit]
Description=stlink server

[Service]
ExecStart=/usr/bin/stlink-server
User=johan

[Install]
WantedBy=multi-user.target

Run:
sudo systemctl daemon-reload
sudo systemctl enable stlink-server
sudo systemctl start stlink-server

Now the stlink server is started, and if you have stlink usb programmers it will be able to publish in the st-link server.

In order to use the programmers you need to forward the stlink server port the programming computer. This is done via ssh:
ssh -L 7184:localhost:7184 johan@10.10.10.32
Port 7184 is the st-link server port. 10.10.10.32 is my server and the port is going to opened on my localhost.

Open Eclipse, under debug configuration, you should now be able to use stlink server and the programmer(s) should be visible, see picture 1.

I’m using UART and want to name them appropriately, use this udev rule for naming them to uart_X:

cat /etc/udev/rules.d/49-uart.rules
# stm32 discovery boards, with onboard st/linkv1
# ie, STM32VL

SUBSYSTEMS==”usb”, ATTRS{idVendor}==”067b”, ATTRS{idProduct}==”2303″, \
MODE:=”0666″, \
SYMLINK+=”uart_%n”

STM32 USB CDC_ACM

I’m in the phase of implementing STM32 to be a USB COM device. Everytime I reprogram the board Linux get’s cranky and I need to manually unplugging/plugging the stm32 usb again. But instead of going to the server and doing manual work I have created a bash script that fixes this issue for me.

Run: lsusb -t
/: Bus 05.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
|__ Port 1: Dev 2, If 0, Class=Communications, Driver=cdc_acm, 12M
|__ Port 1: Dev 2, If 1, Class=CDC Data, Driver=cdc_acm, 12M
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/8p, 480M
|__ Port 5: Dev 3, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 2: Dev 5, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 7: Dev 4, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 1: Dev 6, If 0, Class=Vendor Specific Class, Driver=pl2303, 12M
|__ Port 4: Dev 7, If 0, Class=Vendor Specific Class, Driver=pl2303, 12M

The stm32 usb device is connected to port 3.
Run: ./fix_usb.sh 3
echo ‘3-1’ > /sys/bus/usb/drivers/usb/unbind
echo ‘3-1’ > /sys/bus/usb/drivers/usb/bind

The script prints out if you want to poweroff or poweron the usb device, just copy paste the unbind/bind rows.

The content of the script:
#!/bin/bash

USB=$1

if [ -z "$USB" ] ;
then
echo need usb no
exit 1
fi

sudo sh -c "echo '0' > /sys/bus/usb/devices/usb$USB/power/autosuspend_delay_ms"
sudo sh -c "echo 'auto' > /sys/bus/usb/devices/usb$USB/power/control"

sudo sh -c "echo 'auto' > /sys/bus/usb/devices/usb$USB/$USB-1/power/control"
sudo sh -c "echo '1' > /sys/bus/usb/devices/usb$USB/$USB-1/power/persist"

echo "echo '${USB}-1' > /sys/bus/usb/drivers/usb/unbind"
echo "echo '${USB}-1' > /sys/bus/usb/drivers/usb/bind"

Now a Linux server is providing stm32 cards to users, which is really neat! Next step is integrate this into Continuous integration.

[1] https://www.st.com/en/development-tools/st-link-server.html

,

Leave a Reply

Your email address will not be published. Required fields are marked *