Manual was updated due to changes from previous version of CubeMX.
How to setup IDE for STM32 MCU, with Eclipse, STM32CubeMX, GNU ARM Embedded, GNU ARM Eclipse Plugins.
Used MCU: STM32F103RET6.
Video on YouTube
All process has been recorded on video. Operating system: Windows 10 Home.
If it is not working, please write in comments.
List of used software.:
- Eclipse IDE for C/C++ Developers
- Java Virtual Machine
- GCC ARM Embedded Windows Installer
- How to install the Windows Build Tools?
- The GNU ARM Eclipse plug-ins
- How to install the GNU ARM Eclipse plug-ins? (download by Eclipse)
- STM32CubeMX STM32Cube initialization code generator
- Jlink - Software and documentation pack for Windows
Eclipse IDE for C/C++ Developers
Download Eclipse installer and install Eclipse IDE for C/C++ Developers.
Java Virtual Machine
If Eclipse installer can't find JRE, next dialog can be shown:
The required 64-bit Java 1.7.0 virtual machine could not be found.
Do you want to browse your system for it?
You can browse for it or open web-site by clicking No.
Windows Build Tools
Installation manual. All as usual.
GCC ARM Embedded
Disable checkboxes Launch gccvar.bat and Add path to enviroment variable after installation. So you can install many compilers.
GNU ARM Eclipse plug-ins
Installation manual. In Eclipse menu choose Help -> Install New Software.... Add website
- name: GNU ARM Eclipse Plug-ins
- URL: http://gnuarmeclipse.sourceforge.net/updates
Select and install all components.
If you see an error about Handshake_failure, please read the next topic: GNU ARM Eclipse plug-ins: Received fatal alert: handshake_failure.
STM32CubeMX Eclipse plug in
Start Eclipse. Choose menu Help -> Install New Software... and install plugin from archive STSW-STM32095.zip. Restart Eclipse.
Start Eclipse. Open STM32CubeMX from menu Window -> Show View -> Other... -> STM32CubeMX. Choose Help -> Install New Libraries from STM32CubeMX menu to open Libraries Manager.
Here you can install package for selected MCU series.
- Network: select checkbox and click Install Now.
- Local: click From Local... and open file STM32CubeF1.zip.
All as usual.
Create project in Eclipse
Choose menu C/C++ -> C Project. Write a project's name and select type Hello World ARM C++ Project, Toolchain Cross ARM GCC. Replace source's directory from src to Src. At Linker semi-hosting options write only next string
Create project in STM32CubeMX
Start STM32CubeMX and create new project.
Select used MCU. For example STM32F103RET6. Change project settings.
Start code generation. Set project name equals to Eclipse project. Set Project Location directory in workspace, where existing Eclipse project was placed. Set Toolchain/IDE to SW4STM32. Uncheck Generate Under Root.
Start by clicking Ok.
Source codes will be saved over early created project.
Refresh project tree in Eclipse. You can see newly added directories, Driver and Inc. Src directory combined with existing.
Newly added directories disabled by default, so enable it thru properties dialog.
Create file startup.asm in Src directory. Add path to generated assembler startup file:
How to migrate settings from CubeMX project to Eclipse?
Open Eclipse project. Open project's Properties - C/C++ General - Path and Symbols. Add some string markers to Includes и Symbols.
Then close project. Open XML file of both projects, .cproject and ./SW4STM32/< project name >/.cproject.
Format XML with any tool for easy reading. For example, xmlbeautifier.
Locate nodes with symbols in XML file (SW4STM32), like next:
<tool id="fr.ac6.managedbuild.tool.gnu.cross.c.compiler.147826764" name="MCU GCC Compiler" superClass="fr.ac6.managedbuild.tool.gnu.cross.c.compiler"> <option id="gnu.c.compiler.option.preprocessor.def.symbols.1801753735" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" useByScannerDiscovery="false" valueType="definedSymbols"> <listOptionValue builtIn="false" value="__weak=__attribute__((weak))" /> ...
Locate nodes with markers in other XML file (Eclipse) and replace it. List of symbols looks like next:
__weak="__attribute__((weak))" __packed="__attribute__((__packed__))" USE_HAL_DRIVER STM32F103RE ARM_MATH_CM3
Last line missing in XML file, but it is required for build.
Quote at __weak and __packed are required. In XML file quotes need to be escaped as
Locate nodes with Include paths in XML file (SW4STM32) like this:
<tool id="fr.ac6.managedbuild.tool.gnu.cross.c.compiler.147826764" name="MCU GCC Compiler" superClass="fr.ac6.managedbuild.tool.gnu.cross.c.compiler"> <option id="gnu.c.compiler.option.include.paths.976375416" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> <listOptionValue builtIn="false" value="..\..\..\Inc" /> ...
Change prefix from relative path
Copy nodes to other XML file (Eclipse).
Open project's Properties in Eclipse, navigate to C/C++ Build -> Settings -> Tool Settings -> Target Processor -> ARM family, select cortex-m3.
Also you can change charset of project's resources to UTF-8.
Copy linker script from ./SW4STM32/< project name >/STM32F103RETx_FLASH.ld to Scripts/STM32F103RETx_FLASH.ld.
Open project's Properties, navigate to C/C++ Build -> Settings -> Tool Settings -> Cross ARM C Linker -> General. Add file to Scripts files (-T) list.
Start build project.
You can set C/C++ Build -> Behavior -> Enable parallel build to speed up build.
Check connection with debugger and MCU thru J-Flash.
Start J-Flash. Create new project. Select debugger, Target Interface, CPU -> Device. Click menu Target -> Connect. You should see message in log:
If you don't see it, something going wrong.
Then select Target -> _Manual programming -> Erase chip. You should see message in log:
Erase operaion completed successfully.
Setup debugger in Eclipse
Open menu Debug -> Debug Configurations....
Create new connection under GDB Segger J-Link Debugging.
Set Device name on Debugger page, for example STM32F103RE.
Select Connection and Interface, if needed.
To add debug configuration to favorites menu, set checlbox Debug in list Display in favorites menu on Common page.
Start debug from favorites in Debug menu.
Formware shoud be programmed to flash. Debug starts with breakpoint on method main.
This project's structure allows update project with STM32CubeMX without problems.
Just start STM32CubeMX.
Load STM32CubeMX project (generated *.ioc file in root directory of project).
Start code generation.
Files will be regenerated over existing, but user's code keeps in special sections.
На этом пока всё.