Настройки CubeIDE
Project -> Properties -> Settings -> Tool Settings -> MCU GCC Compiler -> Miscellaneous -> Other flags -> Add -> -Wreturn-type -Werror=return-type
-> MCU G++ Compiler -> Miscellaneous -> Other flags -> Add -> -Wreturn-type -Werror=return-type