Programming Blue Pill STM32F103C8T6 with Eclipse and ST-Link V2 in Windows 7

Until today, I still could not find an all-in-one tutorial to program Blue Pill with Eclipse. I have been doing trial and error for weeks and have gathered what I have found into this single post. I hope it useful for anyone who setting up their Blue Pill with Eclipse.

Software and hardware requirements
1. Windows 7
2. Blue Pill STM32F103C8T6
3. ST-Link V2
4. Java 7 update 71 or later (I am using Java 8 update 291 for this setup)

ST-Link V2 and Blue Pill

Step 1 – Download Eclipse IDE for C/C++ here.
I download the ZIP archive and store it at a specific easily reachable location such as C:\STM32Toolchain\eclipse . In the later steps, all the packages and plugins will be added in C:\STM32Toolchain in order to manage it easily.

Step 2- Install CDT packages
In Eclipse, go to Help->Install New Software . Select CDT – https://download.eclipse.org/tools/cdt/releases/10.3, under CDT Main Features, select C/C++ Development Tools SDK

Step 2 – Install the GNU ARM plug-ins for Eclipse
Go to Help->Eclipse Marketplace.. . In the pop-up window that appears type “gnu arm eclipse” in the “Find” textbox and click on Go to kick off the search. The first entry found should be as shown, “Eclipse Embedded C/C++”. Click on install and follows the steps.

Step 3- Install the GCC ARM tool-chain
Download the  GCC tool-chain for the ARM Cortex platform here. You can download the installer and start the installation. When asked, install the tool-chain in the following directory C:\STM32Toolchain\gnu-arm\ . Leave unchecked the entry “Add path to environment variable“, especially if you have other compilers or IDE installed on your PC.

Step 4 – Install the Build Tools
Download the build tools here. When asked, install the tools in these folder: C:\STM32Toolchain\GnuWin32

Step 5 – Create an Empty Project in Eclipse
Go to File > New > Project…
Then select C Project. Select “Empty Project” & ARM Cross GCC. Specify the Project Name
Select Toolchain path

Step 6 – Copy the firmware library to the project directory
Download the STM32F1XX firmware library here. Place the library in C:\STM32Toolchain

Create a new folder [USER] and [startup] in the project directory

Copy the firmware library to the project directory

Copy below files in \test1\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template directory to the [USER] folder
a. main.c
b. stm32f10x_conf.h
c. stm32f10x_it.c
d. stm32f10x_it.h

Copy below file in \test1\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template\TrueSTUDIO\STM3210B-EVAL to the project directory (the file will be replaced)
a. stm32_flash.ld

Copy below file in \test1\STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\TrueSTUDIO to the startup directory. Since I am using Blue Pill, the file is startup_stm32f10x_md.s . Rename this file to startup_stm32f10x_md.S
a. startup_stm32f10x_md.s

Copy the firmware library to the project directory. Delete Project and Utilities folders in \test1\STM32F10x_StdPeriph_Lib_V3.5.0 , at this point, the file addition and deletion is completed, select the project in the Eclipse workspace, and then right click test1 and select Refresh, the file will be automatically imported into the project

Step 7 – Define the project properties
Select the project test1 ->right-click->Properties->C/C++ Build->Settings
Select CROSS ARM C Compiler->Preprocessor. Add 2 symbols, USE_STDPERIPH_DRIVER, indicating the use of peripheral firmware libraries and STM32F103X_MD since I am using Blue Pill

Include the paths

Click the Toolchain tab and fill in the bin folder under the path of the installed cross-compilation tool

Add the path for Build Tools ( the GNUWIN32 downloaded earlier )

After that, set the linker file.

After that, modify the Main.c in the USER folder, because it does not contain any DEMO files, so you need to delete the function called under MAIN.C.

You might encounter “make” error. Go to Properties > Tool Chain Editor, select CDT Internal Builder

if you have error saying “Please select first the target STM32F10x device used in your application (in stm32f10x.h file)” , go to stm32f10x.h and select the device. Since I am using Blue Pill, the device is STM32F10X_MD.

if you encounter below error, open core_cm3.c under the project file \STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\CoreSupport and modify the code as shown below

Before
__ASM volatile (“strexb %0, %2, [%1]” : “=r” (result) : “r” (addr), “r” (value) );
__ASM volatile (“strexh %0, %2, [%1]”: “=r” (result): “r” (addr), “r” (value) );

After
 __ASM volatile (“strexb %0, %2, [%1]” : “=&r” (result) : “r” (addr), “r” (value) );|
 __ASM volatile (“strexh %0, %2, [%1]” : “=&r” (result) : “r” (addr), “r” (value) );

if you encounter “undefined reference to `_exit'” error, check whether you have define the correct linker file as in Step 7

if you encounter below error related to Reset Handler, make sure you have rename the file to startup_stm32f10x_md.S as in Step 6.

After that, you will be able to complete the code compilation.

Reference

https://www.carminenoviello.com/2014/12/28/setting-gcceclipse-toolchain-stm32nucleo-part-1/
https://www.programmersought.com/article/97124058587/ https://blog.csdn.net/u012523921/article/details/100774332
https://blog.csdn.net/Neutree/article/details/50551919
https://blog.csdn.net/u012523921/article/details/100774332
https://blog.csdn.net/u012523921/article/details/100736984
https://www.cnblogs.com/micro-st/p/8886566.html
http://www.jeh-tech.com/arm_eclipse.html