I am actually making this post so someone like me can find help easily in future, and they don't have to cry for days for something silly. (Ps. this is what I did, some steps might be redundant)
If you are trying to use STM32 via Arduino IDE using ST-Link V2 on windows 11, things you need are:
- Arduino IDE (duh!)
- Driver (https://www.st.com/en/development-tools/stsw-link009.html)
- STM32 Cube Programmer (Not the IDE)
Installation process is pretty straight forward.
Steps to follow:
-
Check your device manager if it shows STM32 STlink under Universal Serial Bus Devices, when ST-Link is connected to your computer.
If not, the driver is not installed properly, try to re-install it. -
Check your environment variables if there is a PATH looking like
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin . (the exact destination may vary)
If not, manually find the file. It should be under your STM32CubeProgrammer file you have downloaded before. find the bin file. Copy the path.
click Windows+R, Run cmd, a terminal will open, type SystemPropertiesAdvanced.exe and press enter, then click on Environment variable then in System Variables (not the user variable), find path, double click on it, click new and paste the path of bin file. click all the OKs and you should be all done. -
Now in cube programmer, select ST-Link in the right panel, select SWD in port, then click connect. if connects successfully, everything is good till now. You need to connect your Blue Pill with your ST-link in this process. I will assume you have attached the jumpers properly. : )
If it does not work, please check previous processes. There is a chance your ST-link might be faulty. At least, it was for my case. Please make sure to buy it from a trustworthy source. Often times, the clones are also good to use. But, some plasticy ones are available in the market, I would not suggest you to buy that. -
Now close the Cube Programmer if everything is good till now. or carry on just in case, the error might not be in the hardware.
-
Open Arduino IDE, click File-> Preferences -> then paste this link in additional board manager urls.
https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/main/package_stmicroelectronics_index.json . Then click OK -
Then go to Tools -> Board -> Board manager and then search STM32, and install STM32 MCU based boards (2.10.1 or above maybe)
-
Then again got to tools and select accordingly:
Board -> STM32 MCU based boards -> Generic STM32F1 Series
Board Part Number -> Blue Pill F103C8
Upload Method -> STM32CubeProgrammer(SWD)
You don't have to change the rest. -
Now write your sketch and upload, takes quite some time. If uploads successfully, congratulations.
if not, the steps I followed to fix my problem.
i. I had a faulty STM32, it didn't connected using Cube programmer. SO i had to get a new one.
ii. I had a "st-link error (dev_connect_err)" error, when I did everything properly, turns out I had to close the Cube Programmer before uploading the sketch.
This is all I had to say. This isn't solution to all problems regarding ST-Link and Blue Pill, There are plenty. I just said what was my issue and what worked for me.
I wrote everything from memory, if you find something does not make sense, please let me know. : )