From a1978021ac825178827c412880ba92765bfed72c Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Mon, 16 Oct 2023 18:05:20 +1100 Subject: [PATCH] AP_HAL_ChibiOS: fix setting APP_RAM size also allows passing APP_RAM_START index through hwdef --- .../hwdef/scripts/chibios_hwdef.py | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py index 8cb3f1fbfc1f91..13ed644b3f78d6 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py @@ -749,17 +749,18 @@ def has_sdcard_spi(self): def get_ram_map(self): '''get RAM_MAP. May be different for bootloader''' - self.env_vars['APP_RAM_START'] = None - if args.bootloader: - ram_map = self.get_mcu_config('RAM_MAP_BOOTLOADER', False) - if ram_map is not None: - app_ram_map = self.get_mcu_config('RAM_MAP', False) - if app_ram_map is not None and app_ram_map[0][0] != ram_map[0][0]: - # we need to find the location of app_ram_map[0] in ram_map - for i in range(len(ram_map)): - if app_ram_map[0][0] == ram_map[i][0]: - self.env_vars['APP_RAM_START'] = i - return ram_map + if 'APP_RAM_START' not in self.env_vars: + self.env_vars['APP_RAM_START'] = None + if args.bootloader: + ram_map = self.get_mcu_config('RAM_MAP_BOOTLOADER', False) + if ram_map is not None: + app_ram_map = self.get_mcu_config('RAM_MAP', False) + if app_ram_map is not None and app_ram_map[0][0] != ram_map[0][0]: + # we need to find the location of app_ram_map[0] in ram_map + for i in range(len(ram_map)): + if app_ram_map[0][0] == ram_map[i][0]: + self.env_vars['APP_RAM_START'] = i + return ram_map elif self.env_vars['EXT_FLASH_SIZE_MB'] and not self.env_vars['INT_FLASH_PRIMARY']: ram_map = self.get_mcu_config('RAM_MAP_EXTERNAL_FLASH', False) if ram_map is not None: @@ -1099,16 +1100,17 @@ def write_mcu_config(self, f): cc_regions = [] total_memory = 0 for (address, size, flags) in ram_map: - cc_regions.append('{0x%08x, 0x%08x, CRASH_CATCHER_BYTE }' % (address, address + size*1024)) + size *= 1024 + cc_regions.append('{0x%08x, 0x%08x, CRASH_CATCHER_BYTE }' % (address, address + size)) if self.env_vars['APP_RAM_START'] is not None and address == ram_map[self.env_vars['APP_RAM_START']][0]: ram_reserve_start = self.get_ram_reserve_start() address += ram_reserve_start size -= ram_reserve_start - regions.append('{(void*)0x%08x, 0x%08x, 0x%02x }' % (address, size*1024, flags)) + regions.append('{(void*)0x%08x, 0x%08x, 0x%02x }' % (address, size, flags)) total_memory += size f.write('#define HAL_MEMORY_REGIONS %s\n' % ', '.join(regions)) f.write('#define HAL_CC_MEMORY_REGIONS %s\n' % ', '.join(cc_regions)) - f.write('#define HAL_MEMORY_TOTAL_KB %u\n' % total_memory) + f.write('#define HAL_MEMORY_TOTAL_KB %u\n' % (total_memory/1024)) if self.env_vars['APP_RAM_START'] is not None: f.write('#define HAL_RAM0_START 0x%08x\n' % ram_map[self.env_vars['APP_RAM_START']][0]) @@ -3027,6 +3029,8 @@ def process_line(self, line): value = ' '.join(a[2:]) if name == 'AP_PERIPH' and value != "1": raise ValueError("AP_PERIPH may only have value 1") + if name == 'APP_RAM_START': + value = int(value, 0) self.env_vars[name] = value def process_file(self, filename):