From 50bfa516bcf4d549456493b68ab13020149c8183 Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Sun, 8 Jan 2023 14:46:36 +1100 Subject: [PATCH] waf: add support for dronecan on linux --- Tools/ardupilotwaf/boards.py | 45 ++++++++++++++++++++++++++++++++---- wscript | 14 +++++------ 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/Tools/ardupilotwaf/boards.py b/Tools/ardupilotwaf/boards.py index 0ed397d2d1..bf39ed7bc4 100644 --- a/Tools/ardupilotwaf/boards.py +++ b/Tools/ardupilotwaf/boards.py @@ -429,7 +429,7 @@ class Board: ] if self.with_can and not cfg.env.AP_PERIPH: - if not cfg.env.SITL32BIT and cfg.env.BOARD == 'sitl': + if not cfg.env.FORCE32BIT and (cfg.env.BOARD == 'sitl' or cfg.env.BOARD == 'linux'): env.DEFINES.update( HAL_ENABLE_LIBUAVCAN_DRIVERS = 0 ) @@ -759,7 +759,7 @@ class sitl(Board): '-fno-slp-vectorize' # compiler bug when trying to use SLP ] - if cfg.options.sitl_32bit: + if cfg.options.force_32bit: # 32bit platform flags env.CXXFLAGS += [ '-m32', @@ -1134,7 +1134,15 @@ class chibios(Board): return self.name class linux(Board): + def __init__(self): + if self.toolchain == 'native': + self.with_can = True + else: + self.with_can = False + def configure_env(self, cfg, env): + if cfg.options.board == 'linux' and cfg.options.force_32bit: + self.with_can = True super(linux, self).configure_env(cfg, env) env.DEFINES.update( @@ -1162,8 +1170,35 @@ class linux(Board): 'AP_HAL_Linux', ] - if self.with_can: + if cfg.options.force_32bit: + env.DEFINES.update( + HAL_FORCE_32BIT = 1, + ) + # 32bit platform flags + cfg.env.CXXFLAGS += [ + '-m32', + ] + cfg.env.CFLAGS += [ + '-m32', + ] + cfg.env.LDFLAGS += [ + '-m32', + ] + else: + env.DEFINES.update( + HAL_FORCE_32BIT = 0, + ) + if self.with_can and cfg.options.board == 'linux' and cfg.options.force_32bit: + cfg.env.HAL_NUM_CAN_IFACES = 2 + cfg.define('HAL_NUM_CAN_IFACES', 2) cfg.define('UAVCAN_EXCEPTIONS', 0) + cfg.define('UAVCAN_SUPPORT_CANFD', 1) + cfg.define('HAL_CANFD_SUPPORTED', 1) + cfg.define('CANARD_ENABLE_CANFD', 1) + + if self.with_can: + env.DEFINES.update(CANARD_MULTI_IFACE=1, + CANARD_IFACE_ALL = 0x3) if cfg.options.apstatedir: cfg.define('AP_STATEDIR', cfg.options.apstatedir) @@ -1270,7 +1305,7 @@ class bbbmini(linux): def configure_env(self, cfg, env): super(bbbmini, self).configure_env(cfg, env) - + cfg.env.HAL_NUM_CAN_IFACES = 1 env.DEFINES.update( CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_BBBMINI', ) @@ -1283,6 +1318,7 @@ class blue(linux): def configure_env(self, cfg, env): super(blue, self).configure_env(cfg, env) + cfg.env.HAL_NUM_CAN_IFACES = 1 env.DEFINES.update( CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_BLUE', @@ -1296,6 +1332,7 @@ class pocket(linux): def configure_env(self, cfg, env): super(pocket, self).configure_env(cfg, env) + cfg.env.HAL_NUM_CAN_IFACES = 1 env.DEFINES.update( CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_POCKET', diff --git a/wscript b/wscript index 7a5d5e2c6c..263c096349 100644 --- a/wscript +++ b/wscript @@ -328,9 +328,9 @@ configuration in order to save typing. default=False, help="Enable SITL RGBLed") - g.add_option('--sitl-32bit', action='store_true', + g.add_option('--force-32bit', action='store_true', default=False, - help="Enable SITL 32bit") + help="Force 32bit build") g.add_option('--build-dates', action='store_true', default=False, @@ -440,7 +440,7 @@ def configure(cfg): cfg.env.BOARD = cfg.options.board cfg.env.DEBUG = cfg.options.debug cfg.env.COVERAGE = cfg.options.coverage - cfg.env.SITL32BIT = cfg.options.sitl_32bit + cfg.env.FORCE32BIT = cfg.options.force_32bit cfg.env.ENABLE_ASSERTS = cfg.options.enable_asserts cfg.env.BOOTLOADER = cfg.options.bootloader cfg.env.ENABLE_MALLOC_GUARD = cfg.options.enable_malloc_guard @@ -482,7 +482,7 @@ def configure(cfg): cfg.load('dronecangen') else: cfg.load('uavcangen') - if not (cfg.options.sitl_32bit and cfg.options.board != 'sitl'): + if cfg.options.force_32bit or (cfg.options.board != 'sitl' and cfg.options.board != 'linux'): cfg.load('dronecangen') cfg.env.SUBMODULE_UPDATE = cfg.options.submodule_update @@ -542,8 +542,8 @@ def configure(cfg): else: cfg.end_msg('disabled', color='YELLOW') - cfg.start_msg('SITL 32-bit build') - if cfg.env.SITL32BIT: + cfg.start_msg('Force 32-bit build') + if cfg.env.FORCE32BIT: cfg.end_msg('enabled') else: cfg.end_msg('disabled', color='YELLOW') @@ -680,7 +680,7 @@ def _build_dynamic_sources(bld): bld.srcnode.find_dir('modules/uavcan/libuavcan/include').abspath() ] ) - if (not bld.env.SITL32BIT) and bld.env.BOARD == 'sitl': + if (not bld.env.FORCE32BIT) and (bld.env.BOARD == 'sitl' or bld.env.BOARD == 'linux'): # remove generated files dronecan_dir = bld.bldnode.make_node('modules/DroneCAN/libcanard/dsdlc_generated/').abspath() if os.path.exists(dronecan_dir):