0

I have a stm32f103 project that is initialized using stm32cubemx and I'm using neovim for editing and arm-none-eabi-gcc for compilation of code (whit auto-generated makefile).

I also have installed clangd LSP and also bear to generate compile_commands.json file. Everyting works fine except that there's two errors:

  1. stdio.h file not found
  2. Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)

I looked at core_cm3.h file and __FPU_USED is disabled, which is exactly what clang says.

/** __FPU_USED indicates whether an FPU is used or not.
    This core does not support an FPU at all
*/
#define __FPU_USED       0U

But I couldn't find any line in my makefile flags that enables the FPU for compilation.

# fpu
# NONE for Cortex-M0/M0+/M3

# float-abi


# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)

I also commented out $(FPU) and $(FLOAT-ABI), but the error still exists. Although I can compile the project without any problems (because gcc has no complaints), but these errors are kind of on my nerve.

Is there a way to fix these errors? Or is there any gcc-based LSPs to use instead of clangd?

There's also ccls on neovim's LSP list but I was unable to install it.

mehdi
  • 167
  • 11

1 Answers1

1

s there a way to fix these errors?

https://clangd.llvm.org/config#files You can:

  • create clangd configuration file
  • specify -sysroot command to specify the location of your buildchain (/usr/arm-none-eabi/ on my system)
  • and other needed options (-isysroot -nostdlib etc.) if you use them.

I would advise anyway to move CMake and generate compile_command.json anyway.

is there any gcc-based LSPs to use instead of clangd?

I am not aware of any.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • how should I specify the toolchain folder with `-sysroot`? I didn't find any examples. – mehdi Jun 07 '22 at 14:42
  • `CompileFlags: Add: [-sysroot=the_path_to_your_compiler_toolchain_sysroot]`. Around https://stackoverflow.com/questions/53866650/clang-cross-compilation-with-arm-none-eabi – KamilCuk Jun 07 '22 at 14:53
  • I created `~/.config/clangd/config.yaml` with the option above and clean built the project but the error still appears. – mehdi Jun 07 '22 at 15:04
  • OK. I added a comma and the header file error is fixed. – mehdi Jun 07 '22 at 15:31
  • Thank you. Both errors are fixed. I used `--sysroot=/usr/arm-none-eabi ,` and `-mfloat-abi=soft ,` options in the config file. – mehdi Jun 07 '22 at 15:48
  • 1
    An alternative way to get clangd to find the correct headers of a cross-compiler is `--query-driver`, as described in https://clangd.llvm.org/troubleshooting#cant-find-standard-library-headers-map-stdioh-etc. (Note, unlike `-sysroot`, this is an argument to clangd itself. It causes clangd to query the built-in includes of the compiler that appears in the commands of the `compile_commands.json`) – HighCommander4 Jul 08 '22 at 06:31