From 1bfe2ef9f7f39d93174b1f62ac4b079aac2dea59 Mon Sep 17 00:00:00 2001 From: Fabien Poussin Date: Wed, 14 Mar 2018 17:56:15 +0100 Subject: Adding script to update various config files automaticaly. --- tools/board_gpio.tpl | 55 --------------- tools/mx2board.py | 2 +- tools/templates/board_gpio.tpl | 55 +++++++++++++++ tools/templates/halconf_community.h | 134 ++++++++++++++++++++++++++++++++++++ tools/templates/mcuconf_community.h | 105 ++++++++++++++++++++++++++++ tools/update_configs.py | 100 +++++++++++++++++++++++++++ 6 files changed, 395 insertions(+), 56 deletions(-) delete mode 100644 tools/board_gpio.tpl create mode 100644 tools/templates/board_gpio.tpl create mode 100644 tools/templates/halconf_community.h create mode 100644 tools/templates/mcuconf_community.h create mode 100644 tools/update_configs.py (limited to 'tools') diff --git a/tools/board_gpio.tpl b/tools/board_gpio.tpl deleted file mode 100644 index 07a316d..0000000 --- a/tools/board_gpio.tpl +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef _BOARD_GPIO_H_ -#define _BOARD_GPIO_H_ - -/* Generated by mx2board.py */ - -{% for d, v in defines %} -#define {{ d }} {{ v }} -{%- endfor %} - -{% for p, v in ports %} -/* PORT {{p}} */ -#define VAL_GPIO{{p}}_MODER ( \ - {%- for i in v.MODER %} - {{ i }} | \ - {%- endfor %} - 0) - -#define VAL_GPIO{{p}}_OTYPER ( \ - {%- for i in v.OTYPER %} - {{ i }} | \ - {%- endfor %} - 0) - -#define VAL_GPIO{{p}}_OSPEEDR ( \ - {%- for i in v.OSPEEDR %} - {{ i }} | \ - {%- endfor %} - 0) - -#define VAL_GPIO{{p}}_PUPDR ( \ - {%- for i in v.PUPDR %} - {{ i }} | \ - {%- endfor %} - 0) - -#define VAL_GPIO{{p}}_ODR ( \ - {%- for i in v.ODR %} - {{ i }} | \ - {%- endfor %} - 0) - -#define VAL_GPIO{{p}}_AFRL ( \ - {%- for i in v.AFRL %} - {{ i }} | \ - {%- endfor %} - 0) - -#define VAL_GPIO{{p}}_AFRH ( \ - {%- for i in v.AFRH %} - {{ i }} | \ - {%- endfor %} - 0) -{% endfor %} - -#endif \ No newline at end of file diff --git a/tools/mx2board.py b/tools/mx2board.py index ea0b010..642a934 100644 --- a/tools/mx2board.py +++ b/tools/mx2board.py @@ -332,7 +332,7 @@ if __name__ == '__main__': defines = gen_defines(proj) ports = gen_ports(gpio, proj) - with open(cur_path + '/board_gpio.tpl', 'r') as tpl_file: + with open(cur_path + '/templates/board_gpio.tpl', 'r') as tpl_file: tpl = tpl_file.read() template = Template(tpl) diff --git a/tools/templates/board_gpio.tpl b/tools/templates/board_gpio.tpl new file mode 100644 index 0000000..07a316d --- /dev/null +++ b/tools/templates/board_gpio.tpl @@ -0,0 +1,55 @@ +#ifndef _BOARD_GPIO_H_ +#define _BOARD_GPIO_H_ + +/* Generated by mx2board.py */ + +{% for d, v in defines %} +#define {{ d }} {{ v }} +{%- endfor %} + +{% for p, v in ports %} +/* PORT {{p}} */ +#define VAL_GPIO{{p}}_MODER ( \ + {%- for i in v.MODER %} + {{ i }} | \ + {%- endfor %} + 0) + +#define VAL_GPIO{{p}}_OTYPER ( \ + {%- for i in v.OTYPER %} + {{ i }} | \ + {%- endfor %} + 0) + +#define VAL_GPIO{{p}}_OSPEEDR ( \ + {%- for i in v.OSPEEDR %} + {{ i }} | \ + {%- endfor %} + 0) + +#define VAL_GPIO{{p}}_PUPDR ( \ + {%- for i in v.PUPDR %} + {{ i }} | \ + {%- endfor %} + 0) + +#define VAL_GPIO{{p}}_ODR ( \ + {%- for i in v.ODR %} + {{ i }} | \ + {%- endfor %} + 0) + +#define VAL_GPIO{{p}}_AFRL ( \ + {%- for i in v.AFRL %} + {{ i }} | \ + {%- endfor %} + 0) + +#define VAL_GPIO{{p}}_AFRH ( \ + {%- for i in v.AFRH %} + {{ i }} | \ + {%- endfor %} + 0) +{% endfor %} + +#endif \ No newline at end of file diff --git a/tools/templates/halconf_community.h b/tools/templates/halconf_community.h new file mode 100644 index 0000000..bed1ac8 --- /dev/null +++ b/tools/templates/halconf_community.h @@ -0,0 +1,134 @@ +/* + ChibiOS - Copyright (C) 2014 Uladzimir Pylinsky aka barthess + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef HALCONF_COMMUNITY_H +#define HALCONF_COMMUNITY_H + +/** + * @brief Enables the community overlay. + */ +#if !defined(HAL_USE_COMMUNITY) || defined(__DOXYGEN__) +#define HAL_USE_COMMUNITY TRUE +#endif + +/** + * @brief Enables the FSMC subsystem. + */ +#if !defined(HAL_USE_FSMC) || defined(__DOXYGEN__) +#define HAL_USE_FSMC FALSE +#endif + +/** + * @brief Enables the NAND subsystem. + */ +#if !defined(HAL_USE_NAND) || defined(__DOXYGEN__) +#define HAL_USE_NAND FALSE +#endif + +/** + * @brief Enables the 1-wire subsystem. + */ +#if !defined(HAL_USE_ONEWIRE) || defined(__DOXYGEN__) +#define HAL_USE_ONEWIRE FALSE +#endif + +/** + * @brief Enables the EICU subsystem. + */ +#if !defined(HAL_USE_EICU) || defined(__DOXYGEN__) +#define HAL_USE_EICU FALSE +#endif + +/** + * @brief Enables the CRC subsystem. + */ +#if !defined(HAL_USE_CRC) || defined(__DOXYGEN__) +#define HAL_USE_CRC FALSE +#endif + +/** + * @brief Enables the RNG subsystem. + */ +#if !defined(HAL_USE_RNG) || defined(__DOXYGEN__) +#define HAL_USE_RNG FALSE +#endif + +/** + * @brief Enables the EEPROM subsystem. + */ +#if !defined(HAL_USE_EEPROM) || defined(__DOXYGEN__) +#define HAL_USE_EEPROM FALSE +#endif + +/** + * @brief Enables the TIMCAP subsystem. + */ +#if !defined(HAL_USE_TIMCAP) || defined(__DOXYGEN__) +#define HAL_USE_TIMCAP FALSE +#endif + +/** + * @brief Enables the TIMCAP subsystem. + */ +#if !defined(HAL_USE_COMP) || defined(__DOXYGEN__) +#define HAL_USE_COMP FALSE +#endif + +/*===========================================================================*/ +/* FSMCNAND driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables the @p nandAcquireBus() and @p nanReleaseBus() APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(NAND_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define NAND_USE_MUTUAL_EXCLUSION TRUE +#endif + +/*===========================================================================*/ +/* 1-wire driver related settings. */ +/*===========================================================================*/ +/** + * @brief Enables strong pull up feature. + * @note Disabling this option saves both code and data space. + */ +#define ONEWIRE_USE_STRONG_PULLUP FALSE + +/** + * @brief Enables search ROM feature. + * @note Disabling this option saves both code and data space. + */ +#define ONEWIRE_USE_SEARCH_ROM FALSE + +/*===========================================================================*/ +/* EEProm driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables 24xx series I2C eeprom device driver. + * @note Disabling this option saves both code and data space. + */ +#define EEPROM_USE_EE24XX FALSE + /** + * @brief Enables 25xx series SPI eeprom device driver. + * @note Disabling this option saves both code and data space. + */ +#define EEPROM_USE_EE25XX FALSE + +#endif /* HALCONF_COMMUNITY_H */ + +/** @} */ diff --git a/tools/templates/mcuconf_community.h b/tools/templates/mcuconf_community.h new file mode 100644 index 0000000..6530c12 --- /dev/null +++ b/tools/templates/mcuconf_community.h @@ -0,0 +1,105 @@ +/* + ChibiOS/RT - Copyright (C) 2014 Uladzimir Pylinsky aka barthess + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/* + * FSMC driver system settings. + */ +#define STM32_FSMC_USE_FSMC1 FALSE +#define STM32_FSMC_FSMC1_IRQ_PRIORITY 10 + +/* + * FSMC NAND driver system settings. + */ +#define STM32_NAND_USE_FSMC_NAND1 FALSE +#define STM32_NAND_USE_FSMC_NAND2 FALSE +#define STM32_NAND_USE_EXT_INT FALSE +#define STM32_NAND_DMA_STREAM STM32_DMA_STREAM_ID(2, 7) +#define STM32_NAND_DMA_PRIORITY 0 +#define STM32_NAND_DMA_ERROR_HOOK(nandp) osalSysHalt("DMA failure") + +/* + * FSMC SRAM driver system settings. + */ +#define STM32_USE_FSMC_SRAM FALSE +#define STM32_SRAM_USE_FSMC_SRAM1 FALSE +#define STM32_SRAM_USE_FSMC_SRAM2 FALSE +#define STM32_SRAM_USE_FSMC_SRAM3 FALSE +#define STM32_SRAM_USE_FSMC_SRAM4 FALSE + +/* + * FSMC SDRAM driver system settings. + */ +#define STM32_USE_FSMC_SDRAM FALSE + +/* + * TIMCAP driver system settings. + */ +#define STM32_TIMCAP_USE_TIM1 FALSE +#define STM32_TIMCAP_USE_TIM2 FALSE +#define STM32_TIMCAP_USE_TIM3 FALSE +#define STM32_TIMCAP_USE_TIM4 FALSE +#define STM32_TIMCAP_USE_TIM5 FALSE +#define STM32_TIMCAP_USE_TIM8 FALSE +#define STM32_TIMCAP_USE_TIM9 FALSE +#define STM32_TIMCAP_TIM1_IRQ_PRIORITY 3 +#define STM32_TIMCAP_TIM2_IRQ_PRIORITY 3 +#define STM32_TIMCAP_TIM3_IRQ_PRIORITY 3 +#define STM32_TIMCAP_TIM4_IRQ_PRIORITY 3 +#define STM32_TIMCAP_TIM5_IRQ_PRIORITY 3 +#define STM32_TIMCAP_TIM8_IRQ_PRIORITY 3 +#define STM32_TIMCAP_TIM9_IRQ_PRIORITY 3 + +/* + * COMP driver system settings. + */ +#define STM32_COMP_USE_COMP1 FALSE +#define STM32_COMP_USE_COMP2 FALSE +#define STM32_COMP_USE_COMP3 FALSE +#define STM32_COMP_USE_COMP4 FALSE +#define STM32_COMP_USE_COMP5 FALSE +#define STM32_COMP_USE_COMP6 FALSE +#define STM32_COMP_USE_COMP7 FALSE + +#define STM32_COMP_USE_INTERRUPTS TRUE +#define STM32_COMP_1_2_3_IRQ_PRIORITY 5 +#define STM32_COMP_4_5_6_IRQ_PRIORITY 5 +#define STM32_COMP_7_IRQ_PRIORITY 5 + +#if STM32_COMP_USE_INTERRUPTS +#define STM32_DISABLE_EXTI21_22_29_HANDLER +#define STM32_DISABLE_EXTI30_32_HANDLER +#define STM32_DISABLE_EXTI33_HANDLER +#endif + +/* + * USBH driver system settings. + */ +#define STM32_OTG1_CHANNELS_NUMBER 8 +#define STM32_OTG2_CHANNELS_NUMBER 12 + +#define STM32_USBH_USE_OTG1 1 +#define STM32_OTG1_RXFIFO_SIZE 1024 +#define STM32_OTG1_PTXFIFO_SIZE 128 +#define STM32_OTG1_NPTXFIFO_SIZE 128 + +#define STM32_USBH_USE_OTG2 0 +#define STM32_OTG2_RXFIFO_SIZE 2048 +#define STM32_OTG2_PTXFIFO_SIZE 1024 +#define STM32_OTG2_NPTXFIFO_SIZE 1024 + +#define STM32_USBH_MIN_QSPACE 4 +#define STM32_USBH_CHANNELS_NP 4 + diff --git a/tools/update_configs.py b/tools/update_configs.py new file mode 100644 index 0000000..637429e --- /dev/null +++ b/tools/update_configs.py @@ -0,0 +1,100 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +__author__ = 'Fabien Poussin' +__version__ = '0.1' + +import os +import re +from argparse import ArgumentParser +from traceback import print_exc +from shutil import copy + +parser = ArgumentParser(description='Generate ChibiOS-Contrib config and make files from ChibiOS') +parser.add_argument('-s', '--src', default='../../ChibiOS-RT', type=str, help="ChibiOS folder") +parser.add_argument('-d', '--dst', default='..', type=str, help='ChibiOS-Contrib folder') + + +def makefile(lines): + + + for l in range(len(lines)): + + if 'CHIBIOS =' in lines[l]: + lines[l] = lines[l][:-1] + '/../ChibiOS-RT\n' + lines.insert(l + 1, 'CHIBIOS_CONTRIB = $(CHIBIOS)/../ChibiOS-Contrib\n') + + if '$(CHIBIOS)/os/hal/hal.mk' in lines[l] \ + or '$(CHIBIOS)/os/hal/ports/' in lines[l] \ + or '$(CHIBIOS)/os/various' in lines[l] : + lines[l] = lines[l].replace('CHIBIOS', 'CHIBIOS_CONTRIB') + + return "".join(lines) + + +def halconf(lines): + + idx_end = lines.index('#endif /* HALCONF_H */\n') + lines.insert(idx_end - 1, '\n') + lines.insert(idx_end - 1, '#include "halconf_community.h"') + lines.insert(idx_end - 1, '\n') + + return "".join(lines) + + +def mcuconf(lines): + + idx_end = lines.index('#endif /* MCUCONF_H */\n') + lines.insert(idx_end - 1, '\n') + lines.insert(idx_end - 1, '#include "mcuconf_community.h"') + lines.insert(idx_end - 1, '\n') + + return "".join(lines) + + +if __name__ == '__main__': + + args = parser.parse_args() + sources = {} + + for family in os.scandir(args.src + '/testhal/STM32/'): + if not family.name[0].isupper() or not family.is_dir(): + continue + + for test in os.scandir(family.path): + try: + sources[family.name] = {'makefile': None, 'halconf': None, 'mcuconf': None} + + with open(test.path + '/Makefile', 'r') as file: + sources[family.name]['makefile'] = makefile(file.readlines()) + + with open(test.path + '/halconf.h', 'r') as file: + sources[family.name]['halconf'] = halconf(file.readlines()) + + with open(test.path + '/mcuconf.h', 'r') as file: + sources[family.name]['mcuconf'] = mcuconf(file.readlines()) + + except Exception as e: + print(test.path, e) + del sources[family.name] + continue + + break + + print(sources.keys()) + + for family in os.scandir(args.dst + '/testhal/STM32/'): + if not family.name[0].isupper() or not family.is_dir(): + continue + + for test in os.scandir(family.path): + copy('templates/halconf_community.h', test.path) + copy('templates/mcuconf_community.h', test.path) + + with open(test.path + '/Makefile', 'w') as file: + file.write(sources[family.name]['makefile']) + + with open(test.path + '/halconf.h', 'w') as file: + file.write(sources[family.name]['halconf']) + + with open(test.path + '/mcuconf.h', 'w') as file: + file.write(sources[family.name]['mcuconf']) -- cgit v1.2.3