Integration with nanopb
Not sure if it's more appropriate to post here or on the nanopb github, but I've noticed to get nanopb to work I have to do:
set(CMAKE_TOOLCHAIN_FILE "/home/blaberj/stm32-cmake/cmake/stm32_gcc.cmake")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=cortex-m4 -mfloat-abi=hard") # Needed for nanopb to work
I assume this is because during:
nanopb_generate_cpp()
The following object files are created:
[2/36] /usr/bin/arm-none-eabi-gcc --sysroot=/usr/arm-none-eabi -I/home/blaberj/nanopb -mcpu=cortex-m4 -mfloat-abi=hard -MD -MT CMakeFiles/nanopb.dir/home/blaberj/nanopb/pb_common.c.obj -MF CMakeFiles/nanopb.dir/home/blaberj/nanopb/pb_common.c.obj.d -o CMakeFiles/nanopb.dir/home/blaberj/nanopb/pb_common.c.obj -c /home/blaberj/nanopb/pb_common.c
[3/36] /usr/bin/arm-none-eabi-gcc --sysroot=/usr/arm-none-eabi -I/home/blaberj/nanopb -mcpu=cortex-m4 -mfloat-abi=hard -MD -MT CMakeFiles/nanopb.dir/home/blaberj/nanopb/pb_encode.c.obj -MF CMakeFiles/nanopb.dir/home/blaberj/nanopb/pb_encode.c.obj.d -o CMakeFiles/nanopb.dir/home/blaberj/nanopb/pb_encode.c.obj -c /home/blaberj/nanopb/pb_encode.c
[4/36] /usr/bin/arm-none-eabi-gcc --sysroot=/usr/arm-none-eabi -I/home/blaberj/nanopb -mcpu=cortex-m4 -mfloat-abi=hard -MD -MT CMakeFiles/nanopb.dir/home/blaberj/nanopb/pb_decode.c.obj -MF CMakeFiles/nanopb.dir/home/blaberj/nanopb/pb_decode.c.obj.d -o CMakeFiles/nanopb.dir/home/blaberj/nanopb/pb_decode.c.obj -c /home/blaberj/nanopb/pb_decode.c
[5/36] : && /home/blaberj/clion-2023.3.4/bin/cmake/linux/x64/bin/cmake -E rm -f libnanopb.a && /usr/bin/arm-none-eabi-ar qc libnanopb.a CMakeFiles/nanopb.dir/home/blaberj/nanopb/pb_decode.c.obj CMakeFiles/nanopb.dir/home/blaberj/nanopb/pb_encode.c.obj CMakeFiles/nanopb.dir/home/blaberj/nanopb/pb_common.c.obj && /usr/bin/arm-none-eabi-ranlib libnanopb.a
Without the set(CMAKE_C_FLAGS <>) those flags aren't added. In some scenarios it compiles and usb works but will hang when I try to send a protobuf. This took forever to figure out, but was wondering if stm32-cmake should handle this somehow? I've worked around tinyusb's cmake implementation, they add:
set(TOOLCHAIN_COMMON_FLAGS
-mthumb
-mcpu=cortex-m4
-mfloat-abi=hard
-mfpu=fpv4-sp-d16
)
to their toolchain file which makes this work opaquely after setting it. Wondering if that's a better approach here or not.
Hello, Sorry for the delayed answer. Playing directly with CMAKE_C_FLAGS is not recommended. In stm32-cmake we do set those flags https://github.com/ObKo/stm32-cmake/blob/5f5c92c1a0a88dd5d214f60402d4244af4e3b795/cmake/stm32/l4.cmake#L36
I assume you are not linking the appropriate stm32-cmake target to the nanopb target. linking STM32::L4 (or a more precise target (see Readme))for a L4 family will bring those flags!