Code Monkey home page Code Monkey logo

stm32-emacs's Introduction

STM32-Emacs


License: GPL v3

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 config
  • stm32-start-gdb-elf starts openocd gdb server with selected config and arm-none-eabi-gdb session with selected .elf
  • stm32-flash-to-mcu executes load and cont commands in GDB session
  • stm32-kill-gdb stops openocd and GDB session
  • stm32-open-cubemx open CubeMX with selected .ioc or without

Required:


Install:


  1. install and configure helm, projectile and other deps
  2. clone repository to /.emacs.d/stm32
  3. add to your init file (require 'stm32)
  4. customize if needed

How to use:


Openocd requieres a .cfg file to properly function you need to place .cfg in any directory of current project.

  1. Create project and compile .elf
  2. M-xstm32-start-gdb-eld[RET], select openocd config .cfg, then select .elf
  3. M-xstm32-run-openocd[RET] to start openocd server
  4. in gdb console execute load to upload file to MCU and cont to run. Or execute M-xstm32-flash-to-mcu[RET].
  5. debug your project and good luck!

RTOS support


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-xstm32-start-openocd-gdb[RET].

Optional gdb steps


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]

Closing stm32-debugger


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

License:


This program is distributed under the terms of GNU General Public License, version 3 or any later version. See COPYING for details.

stm32-emacs's People

Contributors

hector93 avatar sl-ru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

stm32-emacs's Issues

Python3 direct execution

Scanning dependencies of target ('Test2','.elf
[ 4%] Building C object CMakeFiles/('Test2','.elf.dir/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c.o
clang: error: no such file or directory: ', -mthumb'
clang: error: no such file or directory: ', '
clang: error: invalid float ABI '-mfloat-abi=hard, '
clang: error: invalid float ABI '-mfloat-abi=hard, '
CMakeFiles/('Test2','.elf.dir/build.make:62: recipe for target 'CMakeFiles/('Test2','.elf.dir/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c.o' failed
make[2]: *** [CMakeFiles/('Test2','.elf.dir/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/('Test2','.elf.dir/all' failed
make[1]: *** [CMakeFiles/('Test2','.elf.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Compilation exited abnormally with code 2 at Tue Jun 26 10:43:33

new function `st-flash`

My function is for st-flash, maybe it will be useful to someone else.
I am not creating a pull-request because I am not an expert in elisp, and perhaps this is not the best implementation. (and also I use only Linux)

(defun stm32-st-flash (&optional path)
  "st-flash  --format ihex write ${project_name}.hex.  Use existing project path's or use optional arg PATH."
  (interactive)
	(message "st-flash --format ihex write ${project_name}.hex")
  (let ((dir (or path (stm32-get-project-build-dir)))
        (name (stm32-get-project-name))
        (output-buffer (get-buffer-create "*st-flash*")))
    (async-shell-command (concat "cd " dir "; st-flash  --format ihex write " name ".hex") output-buffer)))

arm-none-eabi-gdb is not compatible with Emacs built in gdb?

Thanks your effort to share this package.

When I am exploring stm32-emacs, encounter a problem.

Try: M-x stm32-start-gdb-elf then select cfg file and elf file. "stm32-gdb-server" starts successfully,
then Emacs ask "Enable querying debuginfod servers for this session? (y or n) ",
then I enter "y" and hit "Enter" to comfirm.
But "gud-target extended-remote localhost:3333" thow a error:

Debugger entered--Lisp error: (wrong-type-argument gdb-handler nil)
  signal(wrong-type-argument (gdb-handler nil))
  gdb-get-handler-function(1)
  gdb-handle-reply(1)
  gdb-done-or-error("1" error "msg=\"Support for debuginfod is not compiled into G..." t)
  gdb-error("1" "msg=\"Support for debuginfod is not compiled into G..." t)
  gdbmi-bnf-incomplete-record-result("1" (gdb-error . progressive))
  #f(compiled-function () #<bytecode 0x1f930131137fb>)()
  gdbmi-bnf-result-and-async-record-impl()
  gdbmi-bnf-async-record()
  gdbmi-bnf-out-of-band-record()
  gdbmi-bnf-output()
  gud-gdbmi-marker-filter("1^error,msg=\"Support for debuginfod is not compile...")
  apply(gud-gdbmi-marker-filter "1^error,msg=\"Support for debuginfod is not compile...")
  gud-marker-filter("1^error,msg=\"Support for debuginfod is not compile...")
  gud-filter(#<process gud-target extended-remote localhost:3333> "1^error,msg=\"Support for debuginfod is not compiled into GDB.\"\n(gdb) \n2^done\n(gdb) \n3^done\n(gdb) \n4^done\n(gdb) \n5^done\n(gdb) \n6^done,files=[{file=\"Mid...")
  read-from-minibuffer(#("Enable querying debuginfod servers for this session? (y or n) " 54 55 (face help-key-binding font-lock-face help-key-binding) 59 60 (face help-key-binding font-lock-face help-key-binding)) nil (keymap (keymap (C-M-left . backward-sexp) (C-M-right . forward-sexp) (escape . abort-recursive-edit) (remap keymap (quit . abort-recursive-edit) (exit-prefix . abort-recursive-edit) (exit . y-or-n-p-insert-other) (scroll-other-window-down . minibuffer-scroll-other-window-down) (scroll-other-window . minibuffer-scroll-other-window) (scroll-down . minibuffer-scroll-down-command) (scroll-up . minibuffer-scroll-up-command) (recenter . minibuffer-recenter-top-bottom) (self-insert-command . y-or-n-p-insert-other) (ignore . y-or-n-p-insert-other) (delete-and-edit . y-or-n-p-insert-other) (edit-replacement . y-or-n-p-insert-other) (edit . y-or-n-p-insert-other) (undo-all . y-or-n-p-insert-other) (undo . y-or-n-p-insert-other) (backup . y-or-n-p-insert-other) (skip . y-or-n-p-insert-n) (automatic . y-or-n-p-insert-y) (act-and-exit . y-or-n-p-insert-y) (act-and-show . y-or-n-p-insert-y) (act . y-or-n-p-insert-y)) keymap (16 . previous-line-or-history-element) (14 . next-line-or-history-element) (escape . keyboard-escape-quit) (18 . counsel-minibuffer-history) (23 . evil-delete-backward-word) (menu-bar keymap (minibuf "Minibuf" keymap (previous menu-item "Previous History Item" previous-history-element :help "Put previous minibuffer history element in the min...") (next menu-item "Next History Item" next-history-element :help "Put next minibuffer history element in the minibuf...") (isearch-backward menu-item "Isearch History Backward" isearch-backward :help "Incrementally search minibuffer history backward") (isearch-forward menu-item "Isearch History Forward" isearch-forward :help "Incrementally search minibuffer history forward") (return menu-item "Enter" exit-minibuffer :key-sequence "\15" :help "Terminate input and exit minibuffer") (quit menu-item "Quit" abort-recursive-edit :help "Abort input and exit minibuffer") "Minibuf")) (24 keymap (down . minibuffer-complete-defaults) (up . minibuffer-complete-history)) (13 . exit-minibuffer) (10 . exit-minibuffer) (7 . minibuffer-keyboard-quit) (C-tab . file-cache-minibuffer-complete) (9 . self-insert-command) (XF86Back . previous-history-element) (up . previous-line-or-history-element) (prior . previous-history-element) (XF86Forward . next-history-element) (down . next-line-or-history-element) (next . next-history-element) (27 keymap (60 . minibuffer-beginning-of-buffer) (114 . previous-matching-history-element) (115 . next-matching-history-element) (112 . previous-history-element) (110 . next-history-element))) keymap (escape . exit-prefix) (M-prior . scroll-other-window-down) (M-next . scroll-other-window) (prior . scroll-down) (next . scroll-up) (27 keymap (33554454 . scroll-other-window-down) (22 . scroll-other-window) (118 . scroll-down)) (22 . scroll-up) (29 . quit) (7 . quit) (63 . help) (help . help) (f1 . help) (8 . help) (85 . undo-all) (117 . undo) (94 . backup) (33 . automatic) (12 . recenter) (23 . delete-and-edit) (18 . edit) (46 . act-and-exit) (return . exit) (13 . exit) (113 . exit) (44 . act-and-show) (69 . edit-replacement-exact-case) (101 . edit-replacement) (78 . skip) (89 . act) (110 . skip) (121 . act) (backspace . skip) (delete . skip) (127 . skip) (32)) nil t)
  y-or-n-p("Enable querying debuginfod servers for this sessio...")
  gdb-init-1()
  gdb-update()
  gdb("arm-none-eabi-gdb -iex \"target extended-remote localhost:3333\" -i=mi  /Users/c/Downloads/STM32Project/STM32F103ZET6__CubeMX__/FreeRTOS/Demo8-1_Notify_ADC/./build/Demo8-1_Notify_ADC.elf")
  (progn (gdb (s-concat stm32-gdb-command " " (concat root file))))
  (unwind-protect (progn (gdb (s-concat stm32-gdb-command " " (concat root file)))) (set-window-configuration wconfig))
  (let ((wconfig (current-window-configuration))) (unwind-protect (progn (gdb (s-concat stm32-gdb-command " " (concat root file)))) (set-window-configuration wconfig)))
  (progn (let ((wconfig (current-window-configuration))) (unwind-protect (progn (gdb (s-concat stm32-gdb-command " " (concat root file)))) (set-window-configuration wconfig))))
  (if file (progn (let ((wconfig (current-window-configuration))) (unwind-protect (progn (gdb (s-concat stm32-gdb-command " " (concat root file)))) (set-window-configuration wconfig)))))
  (let ((file (stm32--select-file root "*.elf"))) (if file (progn (let ((wconfig (current-window-configuration))) (unwind-protect (progn (gdb (s-concat stm32-gdb-command " " ...))) (set-window-configuration wconfig))))))
  (progn (let ((file (stm32--select-file root "*.elf"))) (if file (progn (let ((wconfig (current-window-configuration))) (unwind-protect (progn (gdb ...)) (set-window-configuration wconfig)))))))
  (if (and 'root 'server-started) (progn (let ((file (stm32--select-file root "*.elf"))) (if file (progn (let ((wconfig ...)) (unwind-protect (progn ...) (set-window-configuration wconfig))))))))
  (let* ((root (projectile-project-root)) (p (get-buffer-process "*stm32-gdb-server*")) (server-started (if (not p) (progn (stm32-start-gdb-server))))) (if (and 'root 'server-started) (progn (let ((file (stm32--select-file root "*.elf"))) (if file (progn (let (...) (unwind-protect ... ...))))))))
  stm32-start-gdb-elf()
  funcall-interactively(stm32-start-gdb-elf)
  call-interactively(stm32-start-gdb-elf record nil)
  command-execute(stm32-start-gdb-elf record)
  counsel-M-x-action("stm32-start-gdb-elf")
  ivy-call()
  ivy-read("M-x " ("toggle-debug-on-error" "stm32-kill-gdb" "stm32-flash-to-mcu" "gud-gdb" "stm32-start-gdb-server" "gdb" "eval-region" "erase-buffer" "project-compile" "project-find-file" "diredp-paste-files" "hurricane/dired-duplicate-this-file" "blink-search" "eaf-open-pdf-from-history" "lsp-bridge-restart-process" "imenu" "helm-imenu" "lsp-format-region" "clang-format-buffer" "lsp-bridge-code-format" "lsp-format-buffer" "align-regexp" "org-noter" "eaf-stop-process" "blink-search-restart-process" "hurricane/now" "calc-now" "hurricane/open-link-in-chrome" "treemacs" "counsel-org-goto" "vera-mode" "dap-debug" "dap-hydra" "lsp-bridge-peek" "dap-gdb-lldb-setup" "hurricane//org-noter-store-link" "lsp-mode" "evil-surround-delete" "hurricane/insert-chrome-current-tab-url" "dap-mode" "activities-resume" "dap-debug-edit-template" "hurricane/manage-chrome-tabs" "activities-new" "activities-save-all" "find-lisp-find-dired" "dap-ui-show-many-windows" "auto-save-mode" "dap-delete-session" "eaf-restart-process" ...) :predicate counsel--M-x-externs-predicate :require-match t :history counsel-M-x-history :action counsel-M-x-action :keymap (keymap (C-M-left . backward-sexp) (C-M-right . forward-sexp) (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) :initial-input nil :caller counsel-M-x)
  counsel-M-x()
  funcall-interactively(counsel-M-x)
  call-interactively(counsel-M-x nil nil)
  command-execute(counsel-M-x)

So I decide to do a litter dig into this.

I try to run

  gdb("arm-none-eabi-gdb -iex \"target extended-remote localhost:3333\" -i=mi  /Users/c/Downloads/STM32Project/STM32F103ZET6__CubeMX__/FreeRTOS/Demo8-1_Notify_ADC/./build/Demo8-1_Notify_ADC.elf")

this command string:

arm-none-eabi-gdb -iex "target extended-remote localhost:3333" -i=mi  /Users/c/Downloads/STM32Project/STM32F103ZET6__CubeMX__/FreeRTOS/Demo8-1_Notify_ADC/./build/Demo8-1_Notify_ADC.elf

in Emacs built in gdb manually.

It throws error too.

2024-04-17 00 51 19

Then I try the same command string in gub-gdb, It runs successfully.

2024-04-17 00 53 23

Here is my Emacs information:

System Info 💻

  • OS: darwin
  • Emacs: 29.3
  • Spacemacs: 0.999.0
  • Spacemacs branch: nil (rev. nil)
  • Graphic display: t
  • Running in daemon: nil
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: ivy
  • Layers:
(ivy better-defaults
     (search-engine :variables search-engine-config-list
                    '((CAAC :name "CAAC" :url "http://www.caac.gov.cn/so/s?tab=all&qt=%s" :keywords
                            (:keybinding "c" :docstring "**民用航空局智能云搜索"))
                      (SOGOU :name "SOGOU" :url "https://weixin.sogou.com/weixin?type=2&s_from=input&query=%s" :keywords
                             (:keybinding "s" :docstring "搜狗微信搜索" :browser 'eaf-open-browser))
                      (WEIXIN :name "WEIXIN" :url "https://weixin.sogou.com/weixin?type=2&s_from=input&query=%s" :keywords
                              (:keybinding "w" :docstring "搜狗微信搜索"))
                      (MERRIAM-WEBSTER :name "MERRIAM-WEBSTER" :url "https://www.merriam-webster.com/dictionary/%s" :keywords
                                       (:keybinding "m" :docstring "韦氏词典" :browser 'eaf-open-browser))))
     (syntax-checking :variables syntax-checking-enable-by-default t syntax-checking-enable-tooltips t)
     (vinegar :variables vinegar-reuse-dired-buffer t)
     (git :variables git-magit-status-fullscreen t magit-push-always-verify nil magit-save-repository-buffers 'dontask magit-revert-buffers 'silent magit-refs-show-commit-count 'all magit-revision-show-gravatars nil)
     (auto-completion :variables auto-completion-enable-sort-by-usage t auto-completion-enable-snippets-in-popup t auto-completion-enable-help-tooltip nil :disabled-for org markdown)
     emacs-lisp
     (org :variables org-want-to-do-binding t org-enable-github-support t org-enable-reveal-js-support t org-enable-roam-support t org-enable-roam-support t org-enable-roam-protocol t org-enable-roam-server t org-roam-v2-ack t org-enable-valign t org-enable-hugo-support t org-enable-transclusion-support t)
     fasd
     (chinese :variables chinese-default-input-method nil chinese-enable-youdao-dict t)
     (eaf :variables eaf-python-command "python3.10" eaf-pdf-dark-mode nil browse-url-browser-function 'browse-url-default-browser eaf-proxy-type "http" eaf-proxy-host "0.0.0.0" eaf-proxy-port "7890")
     pdf hurricane)
  • System configuration features: ACL GLIB GMP GNUTLS JPEG JSON LIBXML2 MODULES NOTIFY KQUEUE NS PDUMPER PNG RSVG SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER ZLIB

Finally, if I change from gdb to gub-gdb in this line:

(gdb (s-concat stm32-gdb-command " " (concat root file)))))))))

I can run command stm32-start-gdb-elf to start gdb server and debugger succesfully.

So what causes the difference?

multiple definition

/Core/Src/syscalls.c:89: multiple definition of `_exit'; /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/thumb/v7-m/nofp/libnosys.a(_exit.o):/build/newlib-CVVEyx/newlib-3.3.0/build/arm-none-eabi/thumb/v7-m/nofp/libgloss/libnosys/../../../../../../../libgloss/libnosys/_exit.c:17: first defined here

Через скрипты CubeIDE линкуется нормально.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.