Some functions for work with ARM microcontrollers in EMACS. All functions works in respect of projectile project and uses HELM for selection.
stm32-start-gdb-server
starts openocd gdb server with selected configstm32-start-gdb-elf
starts openocd gdb server with selected config andarm-none-eabi-gdb
session with selected.elf
stm32-flash-to-mcu
executesload
andcont
commands in GDB sessionstm32-kill-gdb
stops openocd and GDB sessionstm32-open-cubemx
open CubeMX with selected.ioc
or without
- openocd
- arm-none-eabi-gdb
- helm
- projectile
- friendly-shell-command
- s.el
- (optional) CubeMX
- install and configure helm, projectile and other deps
- clone repository to /.emacs.d/stm32
- add to your init file (require 'stm32)
- customize if needed
Openocd requieres a .cfg
file to properly function you need to place .cfg
in any directory of current project.
- Create project and compile
.elf
- M-x
stm32-start-gdb-eld
[RET], select openocd config.cfg
, then select.elf
- M-x
stm32-run-openocd
[RET] to start openocd server - in gdb console execute
load
to upload file to MCU andcont
to run. Or execute M-xstm32-flash-to-mcu
[RET]. - debug your project and good luck!
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
RTOSFLAG
to 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 M-x
stm32-start-openocd-gdb
[RET].
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]
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
This program is distributed under the terms of GNU General Public License, version 3 or any later version. See COPYING for details.