How to deal with a problematic STM32 ST-Link/v1 device and Ubuntu

This post explains how to ignore the USB storage of the STM32-VL Discovery board so it enumerates in Ubuntu 12.04.  Problems arise when you boot your linux system from an external USB drive.  The not so obvious solution is really simple.

Over the past couple of years, I’ve managed to accumulate a pile of STM32 discovery boards.  I really haven’t done much with them and that is a shame as they are truly capable boards.  I’ve decided to try and use them more often in the future.  I think I’m addicted to buying these things, my newest addition is the NUCLEO-F030 board.  This new board adds yet another version of the ST-LINK firmware to the list.

There are now three versions, ST-Link/V1, ST-Link/V2, and the latest ST-LINK/V2-1. The V2-1 version adds a mass storage device and virtual serial port. However, openocd requires a patch to the latest source code so you can use the Nucleo.  I added the patch and it worked great. (see link below)

However, in the process of testing this openocd patch, I realized my STM32-VL Discovery board was no longer enumerating with my Ubuntu 12.04 setup.  The STM32-VL Discovery board uses the older ST-LINK/V1 interface. The  VL board shows up as a composite USB device with the ST-Link/V1 interface and a Mass Storage device that contains document links to the ST website.  The problem with the V1 firmware is the buggy implementation of the mass storage device.  Most people on linux just configure modprobe to ignore the usb-storage on the ST-Link/V1 (see link below). Something on my system had changed though, it wasn’t working. After looking at the sysylog output, I realized that when I plugged in the STM32-VL board it was constantly resetting itself because of the usb-storage part of the STM32-VL device. It would start to work and then repeatedly reset.

I had long ago added a file called /etc/modprobe.d/usb-storage.conf that looks like this:

That .conf file is supposed to tell modprobe to ignore the Mass Storage device of the ST-Link/V2. Modprobe seemed to be ignoring my quirks file.  In syslog, I found linux trying to mount it:

Digging around on google yielded no answers that seemed to work.  I finally posed my problem to the ##stm32 IRC channel on  PaulFerster quickly provided the clue I needed once I explained my problem.  I had recently switched from an ATA unix boot disk to an external USB drive to provide more flexibility with my development system setup. My new setup had a side effect on the usb-storage kernel module. Using a USB drive forces the usb-storage module to get loaded by the initfs device which happens earlier in the boot process. This new bootflow ends up ignoring my modprobe.d configuration changes.

The simple solution to this problem is to run this command as root before you plug in your STM32-VL Discovery board:

That command tickled the insides of the loaded usb-storage module and fixed the problem. I plugged in my board and tailed the syslog output. Here is what it looks like when usb-storage does the right thing:

Notice the line: “kernel: [14512.589160] usb-storage 1-3.1:1.0: device ignored”? That is what it is supposed to do.  So the real source of my problem was switching my boot drive from an ATA drive to a USB external one.  Hopefully, this will solve the problem for someone else.


ST-Link/V2-1 patch for openocd:

How to ignore the ST-Link/V1 disk in linux (see the modprobe section):

Leave a Comment