HAL_ChibiOS: added build information for each MCU

this abstracts the build information for each MCU, so that hwdef.dat
can control the build process of ChibiOS
This commit is contained in:
Andrew Tridgell 2018-03-06 12:33:30 +11:00
parent d1e4185817
commit 551dca63e1
5 changed files with 53 additions and 12 deletions

View File

@ -92,10 +92,10 @@ PROJECT = ch
# Imported source files and paths # Imported source files and paths
# Startup files. # Startup files.
include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk include $(CHIBIOS)/$(CHIBIOS_STARTUP_MK)
# HAL-OSAL files (optional). # HAL-OSAL files (optional).
include $(CHIBIOS)/os/hal/hal.mk include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/hal/ports/STM32/STM32F4xx/platform.mk include $(CHIBIOS)/$(CHIBIOS_PLATFORM_MK)
include $(CHIBIOS)/os/hal/osal/rt/osal.mk include $(CHIBIOS)/os/hal/osal/rt/osal.mk
# RTOS files (optional). # RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/rt/rt.mk

View File

@ -1,3 +1,15 @@
#!/usr/bin/env python
'''
these tables are generated from the STM32 datasheets for the
STM32F40x
'''
# additional build information for ChibiOS
build = {
"CHIBIOS_STARTUP_MK" : "os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk",
"CHIBIOS_PLATFORM_MK" : "os/hal/ports/STM32/STM32F4xx/platform.mk"
}
AltFunction_map = { AltFunction_map = {
# format is PIN:FUNCTION : AFNUM # format is PIN:FUNCTION : AFNUM
# extracted from tabula-AF-F405.csv # extracted from tabula-AF-F405.csv

View File

@ -4,6 +4,12 @@ these tables are generated from the STM32 datasheet RM0402 in en.DM00180369.pdf
STM32F412 STM32F412
''' '''
# additional build information for ChibiOS
build = {
"CHIBIOS_STARTUP_MK" : "os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk",
"CHIBIOS_PLATFORM_MK" : "os/hal/ports/STM32/STM32F4xx/platform.mk"
}
DMA_Map = { DMA_Map = {
# format is (DMA_TABLE, StreamNum, Channel) # format is (DMA_TABLE, StreamNum, Channel)
# extracted from tabula-stm32f412-ref-manual-196.csv # extracted from tabula-stm32f412-ref-manual-196.csv

View File

@ -1,9 +1,15 @@
#!/usr/bin/env python #!/usr/bin/env python
''' '''
these tables are generated from the STM32 datasheet DM00071990.pdf for the these tables are generated from the STM32 datasheets for the
STM32F427 and STM32F4279 STM32F42x
''' '''
# additional build information for ChibiOS
build = {
"CHIBIOS_STARTUP_MK" : "os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk",
"CHIBIOS_PLATFORM_MK" : "os/hal/ports/STM32/STM32F4xx/platform.mk"
}
DMA_Map = { DMA_Map = {
# format is (DMA_TABLE, StreamNum, Channel) # format is (DMA_TABLE, StreamNum, Channel)
# extracted from tabula-STM32F4x7-dma.csv # extracted from tabula-STM32F4x7-dma.csv

View File

@ -60,6 +60,9 @@ alllines = []
# allow for extra env vars # allow for extra env vars
env_vars = {} env_vars = {}
# build flags for ChibiOS makefiles
build_flags = []
mcu_type = None mcu_type = None
@ -78,15 +81,19 @@ def error(str):
sys.exit(1) sys.exit(1)
def get_alt_function(mcu, pin, function): def get_mcu_lib(mcu):
'''return alternative function number for a pin''' '''get library file for the chosen MCU'''
import importlib import importlib
try: try:
lib = importlib.import_module(mcu) return importlib.import_module(mcu)
alt_map = lib.AltFunction_map
except ImportError: except ImportError:
error("Unable to find module for MCU %s" % mcu) error("Unable to find module for MCU %s" % mcu)
def get_alt_function(mcu, pin, function):
'''return alternative function number for a pin'''
lib = get_mcu_lib(mcu)
alt_map = lib.AltFunction_map
if function and function.endswith("_RTS") and ( if function and function.endswith("_RTS") and (
function.startswith('USART') or function.startswith('UART')): function.startswith('USART') or function.startswith('UART')):
# we do software RTS # we do software RTS
@ -317,10 +324,10 @@ def write_mcu_config(f):
f.write('// SDIO available, enable POSIX filesystem support\n') f.write('// SDIO available, enable POSIX filesystem support\n')
f.write('#define USE_POSIX\n\n') f.write('#define USE_POSIX\n\n')
f.write('#define HAL_USE_SDC TRUE\n') f.write('#define HAL_USE_SDC TRUE\n')
env_vars['CHIBIOS_FATFS_FLAG'] = 'USE_FATFS=yes' build_flags.append('USE_FATFS=yes')
else: else:
f.write('#define HAL_USE_SDC FALSE\n') f.write('#define HAL_USE_SDC FALSE\n')
env_vars['CHIBIOS_FATFS_FLAG'] = 'USE_FATFS=no' build_flags.append('USE_FATFS=no')
if 'OTG1' in bytype: if 'OTG1' in bytype:
f.write('#define STM32_USB_USE_OTG1 TRUE\n') f.write('#define STM32_USB_USE_OTG1 TRUE\n')
f.write('#define HAL_USE_USB TRUE\n') f.write('#define HAL_USE_USB TRUE\n')
@ -348,6 +355,11 @@ def write_mcu_config(f):
f.write('#define CCM_RAM_SIZE %u\n' % ccm_size) f.write('#define CCM_RAM_SIZE %u\n' % ccm_size)
f.write('\n') f.write('\n')
lib = get_mcu_lib(mcu_type)
build_info = lib.build
# setup build variables
for v in build_info.keys():
build_flags.append('%s=%s' % (v, build_info[v]))
def write_ldscript(fname): def write_ldscript(fname):
'''write ldscript.ld for this board''' '''write ldscript.ld for this board'''
@ -952,6 +964,12 @@ def build_peripheral_list():
return peripherals return peripherals
def write_env_py(filename):
'''write out env.py for environment variables to control the build process'''
# CHIBIOS_BUILD_FLAGS is passed to the ChibiOS makefile
env_vars['CHIBIOS_BUILD_FLAGS'] = ' '.join(build_flags)
pickle.dump(env_vars, open(filename, "wb"))
def process_line(line): def process_line(line):
'''process one line of pin definition file''' '''process one line of pin definition file'''
global allpins global allpins
@ -1065,6 +1083,5 @@ write_ldscript(os.path.join(outdir, "ldscript.ld"))
# exist in the same directory as the ldscript.ld file we generate. # exist in the same directory as the ldscript.ld file we generate.
copy_common_linkerscript(outdir, args.hwdef) copy_common_linkerscript(outdir, args.hwdef)
# write out env.py write_env_py(os.path.join(outdir, "env.py"))
pickle.dump(env_vars, open(os.path.join(outdir, "env.py"), "wb"))