The development environment discussed here is minimal, terminal based, and cross platform. This configuration assumes that a terminal based text editor such as vim and the make utility are the primary tools for programming. It consists of following components:
- GNU ARM Embedded Toolchain
- Makefile Utility
- STM32CubeMX
- Flash Tool (JLink or OpenOCD)
- Hardware
The most recent version of the compiler suite can be found here. The toolchain is self-sufficient. Thus you can simply unzip the archive into any directory of choice then you are good to go.
In Linux, make utility is included in a package such as build-essential. If you have C/C++ compiler installed on your system then you already have it. In Windows, preferred way to get the utility is to install cygwin first, then to install make from there. Alternatively, you can use the one comes with MinGW system or you can find one of the precompiled version. However you may need to choose 32bit version of make, since the GNU ARM toolchain for Windows is 32bit.
STM32CubeMX is a Java program. Thus it runs on Java RE regardless of the host O/S type. Recent versions of the program comes with installers for Windows as well as for Linux. After the install, you can download SDK for your device using STM32CubeMX.
Building A Makefile Project Using CubeMX
Start STM32CubeMX, select a device or a board, and configure peripherals. Then choose Makefile option when generating code. It will populate the output directory with all the necessary files and folders including the Makefile located on the root. This project is self-sufficient and portable. You can use the same project in Windows and in Linux. You only need a toolchain and make utility to build.
Before building the project by running make however, you need to enter the correct BINPATH variable, to which all toolchain commands are referring. If the path is accurate, then the building process should be done without an issue. Following lines will make the setting cross-platform.
Source file
Source file
Source file
101 ifeq ($(OS),Windows_NT) 102 BINPATH = c:/Program\ Files\ \(x86\)/GNU\ Tools\ ARM\ Embedded/6\ 2017-q2-update/bin 103 else 104 BINPATH = $(HOME)/bin/gcc-arm-none-eabi-6-2017-q2-update/bin 105 endif
Flash Download
Most of the ST dev. kits are equipped with onboard version of STLink v.2 interface, some of which you can easily break apart from the kits and use them as stand-alone programmers for your own STM32 projects.
In Windows, you can use ST-Link Utility (GUI) or ST-Link CLI (command line version). If your STM32 kit supports mbed interface, you can simply drag and drop your output onto the drive populated when you insert the kit into a USB port of your computer. There is a Linux version ST-Link tool as well.
Alternatively you can reprogram the STLink and turn it into a Segger J-Link compatible programmer, so that you can use J-Link software by Segger. Benefit of this is to allow you to have cross-platform Makefile setting for flash download.
In Windows, you can use ST-Link Utility (GUI) or ST-Link CLI (command line version). If your STM32 kit supports mbed interface, you can simply drag and drop your output onto the drive populated when you insert the kit into a USB port of your computer. There is a Linux version ST-Link tool as well.
Alternatively you can reprogram the STLink and turn it into a Segger J-Link compatible programmer, so that you can use J-Link software by Segger. Benefit of this is to allow you to have cross-platform Makefile setting for flash download.
230 flash: 231 ifeq ($(OS),Windows_NT) 232 c:/Program\ Files\ \(x86\)/SEGGER/JLink_V622d/JLink -if swd -device stm32l052k8 -commandfile jlinkcmd 233 else 234 JLinkExe -if swd -device stm32l052k8 -commandfile jlinkcmd 235 endifNote that there is a small difference in the name of the JLink utility, i.e. JLink.exe vs JLinkExe. This command reads command script from the file jlinkcmd, which may look like this:
1 r 2 loadfile build/your_output.bin 0x8000000 3 r 4 g 5 exitNow you can download the image to the device without leaving your editor. Finally, you can use OpenOCD in a similar way as OpenOCD supports ST-Link directly as well.
Comments
Post a Comment