Programming Daisy from NeoVim (or any other editor besides VScode)

Hey guys,

It’s been a while since I left VScode behind so was looking to migrate my daisy environment to NeoVim which I’m more comfortable with these days. I used bear to generate compile_commands.json via a make clean && bear -- make which did the trick for getting the correct compiler info to the LSP for autocomplete and “go to definitions” etc. Besides some linter errors confined to the #include "daisy_seed.h" file, it started off great! Was building and flashing fine with make program-dfu and make program (honestly, don’t know how I used to live without the debug probe for instant flashing)

Then all came crumbling down once I wanted to include some c++ standard library functionality. The first was std::array. Linter errors anywhere the array was being declared / used and LSP not aware of the c++ array file. I tried including the path to the toolchain’s c++ include directory /Library/DaisyToolchain/0.2.0/arm/arm-none-eabi/include/c++/10.3.1 in the compile_commands.json. No joy. Think this solved the “go to definition” for the std::array but any array declarations / usage of the array was surrounded with incorrect errors. However, I know this is just a tooling error because the project builds and flashes fine.

So far the best solution has been including the path to the system c++ header files via /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 which is a hacky patch at best as I’m sure there’ll be discrepancies compared to the GNU arm toolchain that daisy uses. Currently this works for std::array but for other standard library functions suchas std::set still have the issue of incorrect errors.

Not sure what else to try here.. I can see that the .vscode’s c_cpp_properties.json simply specifies the compiler path and has no issues, However when trying to replicate this with compile_flags.json my results have been the same or worse than above.

Has anyone successfully setup an environment for coding daisy projects from NeoVim which can include c++ standard library functions? Actually, it’s probably not even a NeoVim specific issue, is anyone using an editor other than VScode? Zed would be a good second best I guess..

Here’s a snippet from c_cpp_properties.json for reference

Thanks!

"cStandard": "c11",
      "compilerPath": "/usr/local/bin/arm-none-eabi-g++",
      "cppStandard": "c++17",
      "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE"
      ],

Sharing the solution from fennecdjay on Discord here incase anyone searches for this further down the line:

  1. Add the following as a compile_flags.txt in the root of your project
  2. Make sure those include paths (-I) are correct for your filesystem. They should point to the libDaisy and DaisySP directories.
  3. Remove compile_commands.jsonfrom your project if you have it
-IlibDaisy/src
-IlibDaisy/src/sys
-IlibDaisy/src/usbd
-IlibDaisy/Drivers/CMSIS/Include
-IlibDaisy/Drivers/CMSIS_5/CMSIS/Core/Include
-IlibDaisy/Drivers/CMSIS-Device/ST/STM32H7xx/Include
-IlibDaisy/Middlewares/ST/STM32_USB_Host_Library/Core/Inc
-IlibDaisy/Drivers/STM32H7xx_HAL_Driver/Inc
-IlibDaisy/src/usbh
-IlibDaisy/Drivers/STM32H7xx_HAL_Driver/Inc/Legacy
-IlibDaisy/Middlewares/ST/STM32_USB_Device_Library/Core/Inc
-IlibDaisy/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc
-IlibDaisy/Middlewares/Third_Party/FatFs/src
-IlibDaisy
-IlibDaisy/Drivers/CMSIS/DSP/Include
-IDaisySP
-IDaisySP/examples/fastconv
-IlibDaisy/src/hid
-IDaisySP/tests/fastconv
-IDaisySP/tests/util
-IDaisySP/modules
-IDaisySP/Source
-IDaisySP/tests/util
#            "defines": [
-D                CORE_CM7
-D              STM32H750xx
-D               STM32H750IB
-D               ARM_MATH_CM7
-D               flash_layout
-D               HSE_VALUE=16000000
-D               USE_HAL_DRIVER
-D               USE_FULL_LL_DRIVER

Now there should be no errors on daisy related includes or C++ library functions from NeoVim.

Hope that helps anyone who wants to escape VS Code!

in case someone finds a better way or changes to be done to the file, here is a link to the gist: