[Solved] Connectivity problems with Blue Pill and ST-Link v2

Post here first, or if you can't find a relevant section!
elroy
Posts: 8
Joined: Wed Sep 21, 2022 5:14 pm

[Solved] Connectivity problems with Blue Pill and ST-Link v2

Post by elroy »

Today I've had problems while trying to install Arduino IDE, configure it for STM32, and communicate with an STM32F103C8T6 connected through an ST-Link v2, trying both on macOS and in Windows 10. The STM32 and programmer were bought in this package: https://www.amazon.com/dp/B079B95L9Y .

On Mac, I've tried installing Arduino IDE 2.0.0 on a 2018 Intel MacBook Pro running macOS 12.6 Monterey, and also on a 2015 Intel MacBook Pro running macOS 10.15.7 Catalina. Neither computer sees the ST-Link v2 when it's attached to a USB port. It doesn't appear as an option in Arduino IDE, and doesn't show up as a device in Terminal in \dev\cu* .

On the Windows 10 PC, I tried installing Arduino IDE 1.8.19. When the ST-Link v2 was plugged in it didn't show up in Device Manager, so I went to st.com and downloaded the driver package stsw-link009. The driver install appeared to execute normally, and Device Manager now shows a USB device with name STM32 STLink, reporting "This device is working properly." If I go to Tools > Get Board Info, it says I first must select a port. However, the Port menu item is grayed out and can't be selected.

If I remove the STLink and plug in an Arduino Uno using its USB cable, it works normally on all three computers -- it shows up as /dev/cu.usbmodem14201 on the Macs, and on COM3 on the Windows PC.

I double-checked the plug-in wires between the ST-Link v2 and the Blue Pill, and verified that 3.3v, gnd, clock and IO were all connected correctly. Although the ST-Link doesn't appear to be recognized by any of the computers, the small red LED on the ST-Link is illuminated when it's attached to any computer. On the Blue Pill, the red LED near the ground connection pin lights solidly, while the LED near the 3.3v connection pin flashes.

Any suggestions on what to try next? I note that st.com only appears to have an ST-Link v2 driver for Windows -- is there another option for Mac? If the programmer I bought seems dodgy, I'm fine with investing in a new one if anyone has suggestions on one known to work well. Thanks for any ideas.
Last edited by elroy on Fri Sep 23, 2022 2:34 pm, edited 1 time in total.
ozcar
Posts: 143
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: Connectivity problems with Blue Pill and ST-Link v2

Post by ozcar »

I don't think "Get Board info" is a definitive test.

What happens if you just try to upload something? Select Upload method: "STM32CubeProgrammer (SWD)" first.

That works for me regardless of whether the code already loaded in the board has USB support or not. Without USB support, no COM port appears when the board is plugged in, and so there is no port to select in the Arduino IDE. If I upload say just a "blinky" but having selected USB support: "CDC (generic 'Serial' supercede U(S)ART)", then a COMx port appears in Device Manager when the board is plugged in, and the Arduino IDE can see that COM port (Board info then works, but really only gives the USB PID and VID).

Disclaimer: I have no idea about macOS, and Arduino IDE 2.0.0 is too new for me to go anywhere near at this time. I'm using Windows 10, Arduino IDE 1.8.18 and official STM core 2.3.0.
elroy
Posts: 8
Joined: Wed Sep 21, 2022 5:14 pm

Re: Connectivity problems with Blue Pill and ST-Link v2

Post by elroy »

ozcar wrote: Wed Sep 21, 2022 10:41 pm What happens if you just try to upload something? Select Upload method: "STM32CubeProgrammer (SWD)" first.
Can't try it on the Macs, but when I do on the Windows PC (which was already set for the above upload method), the compilation seems to complete ok, and then I get this error:
An error occurred while uploading the sketch
STM32_Programmer_CLI.exe not found.
Please install it or add <STM32CubeProgrammer path>\bin' to your PATH environment:
https://www.st.com/en/development-tools ... eprog.html
Aborting!
When I do a web search on "STM32_Programmer_CLI" I see references to installing an ST-Link utility, or perhaps other programmer software like STM32CubeProgrammer. I haven't done any of this yet, as it wasn't mentioned in the online instructions I was following to get Arduino IDE set up for STM32. Are there any canonical instructions on what I need to do here?

I'm also wondering if an install of something for the programmer that I haven't done yet would solve the issue on the Macs. Getting them working is a high priority for me.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: Connectivity problems with Blue Pill and ST-Link v2

Post by GonzoG »

It's not "STM32_Programmer_CLI", it's just STM32CubeProgrammer, like it's there in error. You need it to use STM STM native upload methods.
There are also STLink tools for Mac and Linux:
https://github.com/stlink-org/stlink
ozcar
Posts: 143
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: Connectivity problems with Blue Pill and ST-Link v2

Post by ozcar »

It has been a long time since I first installed the official STM core. I do have a vague recollection of having to install the programmer code and make sure that it was in the path.

I see in other threads here people saying that they have STM32_Programmer_CLI.exe in a directory somewhere under their <user>\AppData\Local\Arduino15\packages\ where the STM32DUINO files are. However I do not have it anywhere there - I did a search to check and it is not found. If I open a command prompt and enter

Code: Select all

where STM32_Programmer_CLI.exe
it finds it where I have installed STM32CubeProgrammer. If you install that, it provides the CLI progam which is used by the IDE, but also gives you a GUI version which you could also use to check if your STLINK is working (it might ask you to update the firmware on the STLINK).
elroy
Posts: 8
Joined: Wed Sep 21, 2022 5:14 pm

Re: Connectivity problems with Blue Pill and ST-Link v2

Post by elroy »

GonzoG wrote: Wed Sep 21, 2022 11:53 pm It's not "STM32_Programmer_CLI", it's just STM32CubeProgrammer, like it's there in error. You need it to use STM STM native upload methods.
Ok, thanks. On the st.com site I found and downloaded a package called STM32CubePrg-Mac, and with a little effort was able to install STM32CubeProgrammer.app on my MacBook. Better yet, when I attach the ST-Link v2 and run that app, it is able to connect to and get information on the Blue Pill. So that's sounding like progress.

Now I'm wondering how I'd use STM32CubeProgrammer for basic tasks like uploading sketches to the Blue Pill. Does it work in conjunction with Arduino IDE? Is there a beginner-level tutorial on all this?
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Connectivity problems with Blue Pill and ST-Link v2

Post by ag123 »

well, review the wiki
https://github.com/stm32duino/wiki/wiki
https://github.com/stm32duino/wiki/wiki/Getting-Started
the "official" STM core is integrated with STM32Cube programmer, hence, it can program it directly from within Arduino IDE.

Alternatively, you can use Sketch > Export compiled binary from the Arduino IDE
and a *.bin file should be left in your sketch folder.
Then you can use STM32Cube programmer to flash this file to the device

an example of using STM32Cube programmer on its own is shown in this Adafruit tutorial
https://learn.adafruit.com/adafruit-stm ... er-details
but that is for STM32F4xx which has DFU.
With st-link, it isn't necessary to press that boot0 button.
But you need to select st-link from the options and that the st-link has to be properly wired to the blue pill board.
Preferably, connect the target reset pin from st-link to the reset pin on blue pill as well

the more complete manual for STM32Cube Programmer is actually on ST's web site
https://www.st.com/resource/en/user_man ... ronics.pdf
preferably, review this manual as this is the original source.
User avatar
fpiSTM
Posts: 1737
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Connectivity problems with Blue Pill and ST-Link v2

Post by fpiSTM »

elroy
Posts: 8
Joined: Wed Sep 21, 2022 5:14 pm

Re: Connectivity problems with Blue Pill and ST-Link v2

Post by elroy »

ag123 wrote: Thu Sep 22, 2022 4:02 am well, review the wiki
https://github.com/stm32duino/wiki/wiki
https://github.com/stm32duino/wiki/wiki/Getting-Started
the "official" STM core is integrated with STM32Cube programmer, hence, it can program it directly from within Arduino IDE.
Thanks, I wish I'd seen the Getting-Started wiki article earlier.

I'm still seeing issues while testing on both the Mac and the Windows PC. To keep things simple, I'll just discuss the Mac in this post.

I went down the list of instructions in the Getting-Started wiki article above, and verified that the installations of Arduino IDE, the board files, and STM32CubeProgrammer were normal. I chose Generic STM32F0 series as the board type.

The Getting-Started article then said to go to the Tools > Port menu to select the board's serial port, which should appear on a Mac as something like /dev/tty.usbmodem-1511. In my case, no plausible port for the board appears under Tools > Port, even though the Blue Pill is attached -- it only shows a couple of Bluetooth ports which are not at all related. Under Terminal on the Mac I also checked the /dev directory and found no plausible port. At the bottom right of the Arduino IDE window, a message appears "Generic STM32F0 series [not connected]" even though the board is attached and appears to respond to STS32CubeProgrammer's GUI app. Under Tools > Upload Method, "STM32CubeProgrammer (SWD)" is selected.

I then tried opening the Examples > 01.Basics > Blink program and uploading it to the Blue Pill. Interestingly, the sketch appears to compile and upload normally:
Sketch uses 10704 bytes (65%) of program storage space. Maximum is 16384 bytes.
Global variables use 916 bytes (22%) of dynamic memory, leaving 3180 bytes for local variables. Maximum is 4096 bytes.
-------------------------------------------------------------------
STM32CubeProgrammer v2.11.0
-------------------------------------------------------------------

ST-LINK SN : 52FF70065178515552351787
ST-LINK FW : V2J29S7
Board : --
Voltage : 3.19V
SWD freq : 4000 KHz
Connect mode: Under Reset
Reset mode : Hardware reset
Device ID : 0x410
Revision ID : Rev X
Device name : STM32F101/F102/F103 Medium-density
Flash size : 64 KBytes
Device type : MCU
Device CPU : Cortex-M3
BL Version : --

Memory Programming ...
Opening and parsing file: Blink.ino.bin
File : Blink.ino.bin
Size : 10.66 KB
Address : 0x08000000

Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 10]
Download in Progress:

File download complete
Time elapsed during download operation: 00:00:00.725

RUNNING Program ...
Address: : 0x8000000
Application is running, Please Hold on...
Start operation achieved successfully
The only problem at this point is that the Blue Pill's on-board LED on PC13 is not blinking. Pushing the reset button causes no change. I noticed there are a couple of jumpers on the board, which I left in their default positions.

Does the Blink sketch in the Arduino repository need to be edited in any way for a Blue Pill? Are there any other simple test programs I could upload to verify execution?
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: Connectivity problems with Blue Pill and ST-Link v2

Post by GonzoG »

For BluePills you need to choose "BluePill F103C8" or "BluePill F103CB (or C8 with 128k)" if you have ones with 128k flash.
Generic F103C8 uses different hardware setup.
Post Reply

Return to “General discussion”