Writing commands to a microcontroller with a STM32f chip from python
The microcontroller is connected via USB to a Raspberry Pi 3b+.


This is not consistent with the serial port you're trying to use.

Both /dev/ttyAMA0 and /dev/ttyS0 are your Rpi's UART.

Try connecting to /dev/ttyUSB0.

If that won't work, try disconnecting and reconnecting your microcontroller and running $ dmesg | grep tty. That should give you the right port number, but you should look for /dev/ttyUSBxx tags.

According to the manual, you device uses the Silicon Labs CP210x chip, which is been reported to be working with a recent (post 2015...) Raspbian version out of the box.

Note that you can also use the raw UART on the board if you connect them to the RX and TX pins (plus GND) to the hardware UART on your Rpi (in that case, of course, you'd have to use /dev/ttyS0 or /dev/ttyAMA0 as required).

EDIT: On the comments below you say you have a driver problem. Apparently, the USB VID and PID of your device is not included in the driver library so it's not being loaded by default.

Of course, it's up to you to choose whichever connection is more convenient for your purposes but the driver problem can be fixed easily, so I think it's a good idea to write up here too.

According to your own answer, the details of your device are: VID=0003, PID=1920. With this information and the driver name (CP210x) you can follow this procedure to check if your driver can be loaded manually:

First, get root permissions with:

$ sudo -i


Next, move to the driver folder (note that the exact name of the folder might change, depending on the device you have, it might be cp2101

$  cd /sys/bus/usb/drivers/cp210x/


And assign the VID and PID of your product to the driver's new_id file:

$ echo 0003 1920 &gt;new_id


That should make available your device as a serial port on /dev/ttyUSB0.

If you manage to make it work and want to keep it permanent (otherwise you have to load the driver manually with these steps on every reboot), you can take a look here.