Some functions for work with stm32 arm microcontrollers in EMACS.
Video of work: https://youtu.be/M7RBQsq5_lc
- cmake-ide
- python
- cmake
- clang
- st-link https://github.com/texane/stlink
- https://github.com/SL-RU/STM32CubeMX_cmake
- (optional) openocd
- clone repository to /.emacs.d/stm32
- execute "git submodule update --init" to clone STM32CubeMX_cmake to /.emacs.d/stm32/STM32CubeMX_cmake
- Change paths to yours in stm32.el
- add to your init file (require 'stm32)
- install cmake-ide and configure
WORK IN PROGRESS!!! STM32-Emacs can use two diferent tools for debuggin
- Create STM32CubeMx project and generate it for SW4STM32
- M-x
stm32-new-project[RET]select CubeMX project path - open main.c
- C-c . C or M-x
stm32-cmake-build[RET] to compile - connect stlink to your PC
- M-x
stm32-run-st-util[RET] to start gdb server - start GDB debugger with M-x
stm32-start-gdb[RET] - in gdb) "load" to upload file to MC and "cont" to run.For more see https://github.com/texane/stlink
- good luck!
NOTE: The step 6 can be omited as the step 7 cheks if st-util is running and starts it if it's not running, but it is recommended the first time to run the steps one by one in case of configuration errors, once you are in the debug window you can skip step 6 in the next debugging sessions.
Openocd requieres a .cfg file to properly function you need to provide the file in this case it must be called openocd.cfg(you may change it in the custom varible *stm32-openocd-config-name*), and example file is provided (openocd.cfg) the file needs to be located in your project root.
- Create STM32CubeMx project and generate it for SW4STM32
- M-x
stm32-new-project[RET] select CubeMX project path - put the board.cfg in your project root(an example file named board.cfg is provided in this repo)
- open main.c
- C-c . C or M-x
stm32-cmake-build[RET] to compile - connect stlink to your PC
- M-x
stm32-run-openocd[RET] to start openocd server - start GDB debugger with M-x
stm32-start-openocd-gdb[RET] - debug your project and good luck!
NOTE: The step 6 can be omited as the step 7 cheks if openocd is running and starts it if it's not running, but it is recommended the first time to run the steps one by one in case of configuration errors, once you are in the debug window you can skip step 6 in the next debugging sessions.
If you have a project using an RTOS (FreeRTOS for example) you can debug your project without problems but only openocd supports debugging tasks or threads, this is because openocd searches the tasks of your project and presents them as threads to gdb with this you can wath the stack of every task and also the current state of the task, but in order to do that you need to check if Openocd supports your particular RTOS(section: 21-6 RTOS Support).
If your RTOS is supported you need to do the following steps for enabling debugging tasks in Openocd:
- add the
RTOSFLAGto the openocd.cfg file this flag varies (the file opencd.cfg contains an example for FreeRTOS users)$_TARGETNAME configure -rtos 'RTOSFLAG' - add the symbols definition (if requered section:21.6) to your proyect. for FreeRTOS users an example file is provided (FreeRTOS-openocd.c)
- some RTOS require further configurations in the CMakeLists file (FreeRTOS is one of them), for more information check the example file FreeRTOS-openocd.c
- recompile your proyect and start debugging with Openocd.
Once you are in the debuger window you can load and test your prject, but the default gdb window acts like a terminal and is not very helpful in regards of context and data, so its a good idea to use gdb in many windows mode you can activate it in your startup config file with (gdb-many-windows 1) or with M-x gdb-many-windows [RET]
You can build or clean and build your projects with the following functions.
-
M-x
stm32-cmake-build[RET] this is the equivalent of cleand and build of most IDE's and it recompiles every source file of your project -
M-x
stm32-make-build[RET] the equivalent of build of most IDE's with this you can compile only the modified source files of your project scince the last compilation, this is useful if you only changed a couple of lines in your project as it makes the compilation proces faster.
Once you finished your debugging session you can finish all the windows opened by this plugin with the following function.
M-x stm32-kill-gdb [RET]
This will kill the gdb process and the st-link or openocd proces depending on which do you chose to run
After CubeMx project regeneration or adding new libraries or new sources you need to do M-x stm32-cmake-build
If you have error in cmsis_gcc.h do M-xM-x stm32-fix-vfpcc[RET]. It will change some lines in cmsis_gcc.h and will create backup cmsis_gcc.h.bak.
This program is distributed under the terms of GNU General Public License, version 3 or any later version. See COPYING for details.