Resolving stdio.h and FPU Instruction Errors in STM32F103 Project with clangd and Neovim

@Middleware & OS I have an STM32F103 project initialized with STM32CubeMX. For editing, I use Neovim, and I compile the code with arm-none-eabi-gcc using an auto-generated Makefile. I've installed clangd LSP and Bear to generate the compile_commands.json file. Everything works fine except for two errors: 1. stdio.h file not found. 2. Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT). In the core_cm3.h file, __FPU_USED is disabled, which aligns with clang's indication:
/** __FPU_USED indicates whether an FPU is used or not.
This core does not support an FPU at all
*/
#define __FPU_USED 0U
/** __FPU_USED indicates whether an FPU is used or not.
This core does not support an FPU at all
*/
#define __FPU_USED 0U
I couldn't find any line in my Makefile flags that enables the FPU for compilation. Here are the relevant sections:
# fpu
# NONE for Cortex-M0/M0+/M3

# float-abi

# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# fpu
# NONE for Cortex-M0/M0+/M3

# float-abi

# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
I commented out $(FPU) and $(FLOAT-ABI), but the error persists. The project compiles without issues since GCC doesn't complain, but these errors are annoying. Is there a way to fix these errors? Or are there any GCC-based LSPs to use instead of clangd? I've noticed that ccls is on Neovim's LSP list, but I couldn't install it successfully.
2 Replies
Dtynin
Dtynin•4mo ago
@Sterling For stdio.h not found, add the ARM toolchain include path to compile_commands.json:
{
"directory": "/path/to/project",
"command": "arm-none-eabi-gcc -I/path/to/arm-none-eabi/include -o file.o -c file.c",
"file": "file.c"
}
{
"directory": "/path/to/project",
"command": "arm-none-eabi-gcc -I/path/to/arm-none-eabi/include -o file.o -c file.c",
"file": "file.c"
}
For FPU instructions, ensure the target CPU is specified:
{
"directory": "/path/to/project",
"command": "arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -o file.o -c file.c",
"file": "file.c"
}
{
"directory": "/path/to/project",
"command": "arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -o file.o -c file.c",
"file": "file.c"
}
Update your Makefile:
MCU = -mcpu=cortex-m3 -mthumb
MCU = -mcpu=cortex-m3 -mthumb
Alternatively, try installing ccls as an LSP:
sudo apt install ccls
sudo apt install ccls
Then configure Neovim to use ccls.
Sterling
Sterling•4mo ago
Hmmm, nicee. 🙂 So I will simply update compile_commands.json and the Makefile. If issues persist, I'll try ccls. Thanks @Dtynin
Want results from more Discord servers?
Add your server