Skip to content

Commit

Permalink
AP_HAL_ChibiOS: fix setting APP_RAM size
Browse files Browse the repository at this point in the history
also allows passing APP_RAM_START index through hwdef
  • Loading branch information
bugobliterator committed Oct 18, 2023
1 parent cc799d3 commit a197802
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit a197802

Please sign in to comment.