Adds support for Jlink debugger and simplicity stuff.

This commit is contained in:
2026-07-09 12:08:35 +02:00
parent 84c961cb75
commit 9d84210ad2

121
.emacs
View File

@@ -20,6 +20,7 @@
'(doom-modeline-minor-modes t) '(doom-modeline-minor-modes t)
'(doom-modeline-total-line-number t) '(doom-modeline-total-line-number t)
'(fill-column 80) '(fill-column 80)
'(gdb-debuginfod-enable-setting t)
'(global-auto-revert-mode t) '(global-auto-revert-mode t)
'(global-display-line-numbers-mode t) '(global-display-line-numbers-mode t)
'(global-subword-mode t) '(global-subword-mode t)
@@ -40,7 +41,7 @@
'(org-agenda-files '("~/org/1.TODO.org")) '(org-agenda-files '("~/org/1.TODO.org"))
'(package-enable-at-startup nil) '(package-enable-at-startup nil)
'(package-selected-packages '(package-selected-packages
'(spice-mode yasnippet-snippets yaml-mode xterm-color which-key wgrep web-mode vterm vertico treemacs-projectile treemacs-nerd-icons system-packages string-inflection spdx quelpa-use-package pyvenv py-isort protobuf-mode prettier polymode orderless opencl-c-mode ng2-mode multiple-cursors marginalia magit lsp-ui lsp-treemacs lsp-pyright lsp-ltex json-mode go-mode glsl-mode flycheck embark-consult doom-themes doom-modeline dockerfile-mode delight company code-cells cmake-mode clang-format+ blacken aggressive-indent)) '(realgud treemacs lsp-mode projectile yasnippet spice-mode yasnippet-snippets yaml-mode xterm-color which-key wgrep web-mode vterm vertico treemacs-projectile treemacs-nerd-icons system-packages string-inflection spdx quelpa-use-package pyvenv py-isort protobuf-mode prettier polymode orderless opencl-c-mode ng2-mode multiple-cursors marginalia magit lsp-ui lsp-treemacs lsp-pyright lsp-ltex json-mode go-mode glsl-mode flycheck embark-consult doom-themes doom-modeline dockerfile-mode delight company code-cells cmake-mode clang-format+ blacken aggressive-indent))
'(safe-local-variable-values '(safe-local-variable-values
'((vc-follow-symlinks . t) '((vc-follow-symlinks . t)
(TeX-master . t) (TeX-master . t)
@@ -631,6 +632,122 @@
(projectile-related-files-fn-test-with-suffix "cpp" "UTest") (projectile-related-files-fn-test-with-suffix "cpp" "UTest")
) )
) )
(defun atu/simplicity-fw-inference (&optional dir)
"Return simplicity project_name if DIR contains a .slcp file with project_name key"
(let ((root-dir (projectile-expand-root "" dir)))
(directory-files root-dir t "\\.slcp$" t))
)
(defvar atu/simplicity-project-name nil
"The simplicity project name to know about the name of the output files")
(defvar atu/simplicity-project-mcu-target nil
"The simplicity MCU target of the current project")
(defun atu/simplicity-flash-command ()
"Returns the flashing command for a project"
(unless atu/simplicity-project-name
(error "Not a simplicity project"))
(format "~/.silabs/slt/installs/archive/commander/commander flash build/base/%s.s37" atu/simplicity-project-name)
)
(defun atu/simplicity-jlink-gdb-server-command ()
"Runs the debugger for the current project"
(unless atu/simplicity-project-name
(error "Not a simplicity firmware project"))
(unless atu/simplicity-project-mcu-target
(error "Missing MCU target in the project config file"))
(format "JLinkGDBServer -if swd -port 50000 -swoport 500001 -telnetport 500002 -device %s -rtos GDBServer/RTOSPlugin_FreeRTOS.so" atu/simplicity-project-mcu-target)
)
(defun atu/jlink-server-running-p ()
"Return non-nil if the jlink process server exists and is running."
(let* ((buf-name (if projectile-per-project-compilation-buffer
(format "*projectile-task: jlink-gdb-server*<%s>" (projectile-project-name))
"*projectile-task: jlink-gdb-server*"))
(buf (get-buffer buf-name))
(proc (when buf (get-buffer-process buf))))
(and proc (eq (process-status proc) 'run))))
(defun atu/jlink-server-cleanup (&optional project-dir)
(let* ( (buf-name (if projectile-per-project-compilation-buffer
(format "*projectile-task: jlink-gdb-server*<%s>" (projectile-project-name project-dir))
"*projectile-task: jlink-gdb-server*"))
(buf (get-buffer buf-name))
(proc (when buf (get-buffer-process buf))))
(message "testing %s" buf-name)
(when proc (eq (process-status proc) 'run)
(message "Terminating jlink server")
(interupt-process proc)
)))
(defun atu/simplicity-debug ()
(interactive)
(unless atu/simplicity-project-name
(error "Not a simplicity firmware project"))
(unless (atu/jlink-server-running-p)
(projectile--run-task "jlink-gdb-server" (atu/simplicity-jlink-gdb-server-command) nil t))
(let* ((fw-path (projectile-expand-root
(format "build/base/%s.out" atu/simplicity-project-name)
))
(gdb-command (concat "gdb-multiarch -i=mi "
"-iex \"set debuginfod enabled off\" "
(format "-ex \"file %s\" " fw-path)
"-ex \"target remote localhost:50000\" "
"-ex \"monitor reset\" "
"-ex \"load\" "
"-ex \"break main\" "
"-ex \"continue\" "
"-ex \"delete 1\" "
))
)
(unless (file-exists-p fw-path)
(error "Build project first!"))
(gdb gdb-command)
)
)
(projectile-register-project-type 'simplicity-fw #'atu/simplicity-fw-inference
:project-file "?*.slcp"
:configure "cmake -B build -S cmake_gcc -DCMAKE_EXPORT_COMPILE_COMMANDS=On"
:compile "cmake --build build"
:tasks '(("flash" . atu/simplicity-flash-command)
("jlink-gdb-server" . atu/simplicity-jlink-gdb-server-command))
)
(defun atu/projectile-changed-project (new previous)
"An hook that will help us define functions and task based on project type"
(setq atu/simplicity-project-name nil)
(setq atu/simplicity-project-mcu-target nil)
(when (eq 'simplicity-fw (projectile-project-type new))
(let* ((slcp-files (directory-files new t "\\.slcp$" t))
(slcp-file (car slcp-files)))
(with-temp-buffer
(insert-file-contents slcp-file)
(goto-char (point-min))
(if (re-search-forward "^[ \t]*project_name[ \t]*:\\(.+\\)$" nil t)
(setq atu/simplicity-project-name (string-trim (match-string 1)))
(setq atu/simplicity-project-name nil))
(goto-char (point-min))
(if (re-search-forward "^[ \t]*id[ \t]*:[ \t]*\\(\\(?:BGM\\|EFR\\|EFM\\)[^[:space:]]*\\)" nil t)
(setq atu/simplicity-project-mcu-target (match-string 1))
(setq atu/simplicity-project-mcu-target nil)
)
)
(message "Simplicity firmware project %s targeting %s" atu/simplicity-project-name atu/simplicity-project-mcu-target)
)
)
(unless atu/simplicity-project-mcu-target
(atu/jlink-server-cleanup previous)
)
)
(add-to-list 'projectile-project-changed-functions #'atu/projectile-changed-project)
) )
;; (use-package polymode ;; (use-package polymode
@@ -1024,6 +1141,8 @@
(custom-set-faces (custom-set-faces
;; custom-set-faces was added by Custom. ;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful. ;; If you edit it by hand, you could mess it up, so be careful.