diff --git a/Tools/ardupilotwaf/boards.py b/Tools/ardupilotwaf/boards.py index 032f1900aa..2ebac353e5 100644 --- a/Tools/ardupilotwaf/boards.py +++ b/Tools/ardupilotwaf/boards.py @@ -64,7 +64,6 @@ class Board: cfg.srcnode.find_dir('libraries/AP_Common/missing').abspath() ]) - def configure_env(self, cfg, env): # Use a dictionary instead of the convetional list for definitions to # make easy to override them. Convert back to list before consumption. @@ -267,14 +266,6 @@ class chibios(Board): HAVE_STD_NULLPTR_T = 0, ) - if self.with_uavcan: - env.AP_LIBRARIES += [ - 'modules/uavcan/libuavcan_drivers/stm32/driver/src/*.cpp' - ] - env.INCLUDES += [ - cfg.srcnode.find_dir('modules/uavcan/libuavcan_drivers/stm32/driver/include').abspath() - ] - env.AP_LIBRARIES += [ 'AP_HAL_ChibiOS', ] @@ -363,11 +354,6 @@ class chibios(Board): ] env.LIB += ['gcc', 'm'] - if self.with_uavcan: - env.CFLAGS += ['-DUAVCAN_STM32_CHIBIOS=1', - '-DUAVCAN_STM32_NUM_IFACES=2'] - env.CXXFLAGS += ['-DUAVCAN_STM32_CHIBIOS=1', - '-DUAVCAN_STM32_NUM_IFACES=2'] env.GIT_SUBMODULES += [ 'ChibiOS', @@ -393,7 +379,6 @@ class fmuv3(chibios): name = 'fmuv3' def __init__(self): super(fmuv3, self).__init__() - self.with_uavcan = True def configure_env(self, cfg, env): super(fmuv3, self).configure_env(cfg, env) @@ -410,7 +395,6 @@ class skyviper_v2450(fmuv3): name = 'skyviper-v2450' def __init__(self): super(skyviper_v2450, self).__init__() - self.with_uavcan = False def configure_env(self, cfg, env): super(skyviper_v2450, self).configure_env(cfg, env) diff --git a/Tools/ardupilotwaf/chibios.py b/Tools/ardupilotwaf/chibios.py index c0e65483a3..634f433b34 100644 --- a/Tools/ardupilotwaf/chibios.py +++ b/Tools/ardupilotwaf/chibios.py @@ -106,6 +106,37 @@ def chibios_firmware(self): src=self.objcopy_target) _upload_task.set_run_after(generate_fw_task) +def setup_can_build(cfg): + '''enable CAN build. By doing this here we can auto-enable CAN in + the build based on the presence of CAN pins in hwdef.dat''' + env = cfg.env + env.AP_LIBRARIES += [ + 'AP_UAVCAN', + 'modules/uavcan/libuavcan/src/**/*.cpp', + 'modules/uavcan/libuavcan_drivers/stm32/driver/src/*.cpp' + ] + + env.CFLAGS += ['-DUAVCAN_STM32_CHIBIOS=1', + '-DUAVCAN_STM32_NUM_IFACES=2'] + + env.CXXFLAGS += [ + '-Wno-error=cast-align', + '-DUAVCAN_STM32_CHIBIOS=1', + '-DUAVCAN_STM32_NUM_IFACES=2' + ] + + env.DEFINES += [ + 'UAVCAN_CPP_VERSION=UAVCAN_CPP03', + 'UAVCAN_NO_ASSERTIONS=1', + 'UAVCAN_NULLPTR=nullptr' + ] + + env.INCLUDES += [ + cfg.srcnode.find_dir('modules/uavcan/libuavcan/include').abspath(), + cfg.srcnode.find_dir('modules/uavcan/libuavcan_drivers/stm32/driver/include').abspath() + ] + cfg.get_board().with_uavcan = True + def load_env_vars(env): '''optionally load extra environment variables from env.py in the build directory''' print("Checking for env.py") @@ -191,9 +222,14 @@ def configure(cfg): print("Failed to generate hwdef.h") load_env_vars(cfg.env) + if env.HAL_WITH_UAVCAN: + setup_can_build(cfg) def build(bld): load_env_vars(bld.env) + + if bld.env.HAL_WITH_UAVCAN: + bld.get_board().with_uavcan = True bld( # build hwdef.h and apj.prototype from hwdef.dat. This is needed after a waf clean