Problem: STM32CubeIDE sucks ass, I want to use NVIM Solution: Use stm32cubemx with CMake output and ccls for LSP. GDB for debugging later on


Setup

  1. Project Generation: Use stm32cubemx. Select “CMake” as the toolchain/IDE. STM32CubeMX CMake Project Settings

  2. Neovim ccls LSP Configuration:

lspconfig.ccls.setup({
    on_attach = on_attach,
    capabilities = capabilities,
    init_options = {
        cache = {
            directory = ".ccls-cache",
        },
    },
})
  1. Nix devShell Dependencies:
{
  description = "Basic emed flake";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };
  outputs =
    {
      self,
      nixpkgs,
      flake-utils,
    }:
    flake-utils.lib.eachDefaultSystem (
      system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [ ];
        };
      in
      {
        devShells.default = pkgs.mkShell {
          buildInputs = with pkgs; [
            cmake
            ccls
            gcc-arm-embedded
          ];
          shellHook = "";
        };
      }
    );
}
  1. Build and LSP Setup: From your code’s root directory:
mkdir -p build
cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
make -j$(nproc)
cd ..
ln -s build/compile_commands.json .

Your LSP is now working!