光機電實驗 STM32CubeMX + CLion + OpenOCD + gcc-arm-embedded
I'm using Version 2018.2 EAP (182.2574.4).
It's an early access program now (5/25/2018), and I get this version from https://www.jetbrains.com/clion/nextversion/
(EAP version doesn't require license. Stable version requires license. If you're a student, you can get license by signing up using school email address. more information)
brew install caskroom/cask/gcc-arm-embedded
Then you can find it in /usr/local/Caskroom/gcc-arm-embedded
brew install openocd
Then you can find it in /usr/local/Cellar/open-ocd
http://www.st.com/en/development-tools/stm32cubemx.html
Project Location should be at /Users/{User Name}/Project.
Toolchain/IDE should be SW4STM32.
Generate Under Root should be selected.
Select your project created by STM32CubeMX.
Just press OK.
Go Preferences -> Plugins -> Browse repositories -> search openocd -> find 'OpenOCD + STM32CubeMX support for ARM embedded development' and install it -> Restart CLion
(I'm using version 1.1 alpha6. more details about plugin version)
Go Preferences -> Build,Execution,Deployment -> Bulid Tools -> OpenOCD Support
You can create it by yourself or download this
Then go Preferences -> Build,Execution,Deployment -> CMake
Add this parameter to CMake options
-DCMAKE_TOOLCHAIN_FILE=<path to toolchain-arm-eabi-gcc.cmake>
For me, I put the file in ~/Project/
-DCMAKE_TOOLCHAIN_FILE=~/Project/toolchain-arm-eabi-gcc.cmake
Go Tools -> Update CMake project with STM32CubeMX project
Choose st_nucleo_f3.cfg or stm32f3discovery.cfg, or you can set this later.
Run -> Edit Configurations... -> OCD {Project name} ->Board config file
Those config file will be found in /usr/local/Cellar/open-ocd/0.10.0/share/openocd/scripts/board/
We are using STM32F303RE, so we can choose st_nucleo_f3.cfg or stm32f3discovery.cfg
However, if you choose stm32f3discovery.cfg, there might be some errors.
To fix it (imformation from here), you can find stlink-v2.cfg in /usr/local/Cellar/open-ocd/0.10.0/share/openocd/scripts/interface/.
Find this line:
hla_vid_pid 0x0483 0x3748
Change the line to:
hla_vid_pid 0x0483 0x374b
Change your code in main.c or other source file if needed
Go run -> Build
Your Binary file will be in ~/Project/cmake-build-debug/. Just drag it in to your ARM device.
When you encounter an error like this:
This error seems to be caused by updating CMake project with STM32CubeMX project repeatly.
Close CLion, and delete your project at welcome page. Then import your project as a new CMake project.
Go Tools -> Update CMake project with STM32CubeMX project
Change your code in main.c or other source file if needed
Go run -> Build
https://github.com/elmot/clion-embedded-arm/blob/master/USAGE.md
http://quotation.github.io/development/2017/01/13/embedded-development-in-clion.html
https://blog.jetbrains.com/clion/2016/06/clion-for-embedded-development/
https://blog.jetbrains.com/clion/2017/12/clion-for-embedded-development-part-ii/
https://github.com/cilegann/2018SPRING_Opto-mechatronics-Labs