Compare commits

..

1 Commits

3 changed files with 18 additions and 25 deletions

View File

@@ -66,10 +66,8 @@ After project creation or after modifying the IOC, code generation needs to be i
### The remaining work ### The remaining work
After code generation and conversion, a more manual part of project setup remains. MX Convert only prepares code for integration with CMake projects, the base CMake should be built around the cubemx folder, and it's setup is outside the scope of this tool and guide. After code generation and convertion, a more manual part of project setup remains. MX Convert only prepares code for integration with CMake projects, the base CMake should be built around the cubemx folder, and it's setup is outside the scope of this tool and guide.
### TODO ### TODO
Explain `my_main` and FREERTOS use. Explain `my_main` and FREERTOS use.
### Known issues

View File

@@ -110,9 +110,7 @@ def inject_handlers_file(path: Path):
patched = content patched = content
for handler in INJECT_HANDLERS: for handler in INJECT_HANDLERS:
patched = patched \ patched = patched.replace("void %s_Handler(void){"%(handler), "void %s_Handler(void){\nmy_%s();"%(handler, handler))
.replace("void %sHandler(void)\n{\n /*"%(handler), "void %sHandler(void)\n{\n my_%s();\n /*"%(handler, handler)) \
.replace("/* USER CODE BEGIN PFP */\n\n", "/* USER CODE BEGIN PFP */\nvoid my_%s();\n"%(handler))
with open(path, "w") as of: with open(path, "w") as of:
of.write(patched) of.write(patched)
@@ -131,14 +129,13 @@ def call_my_main(path: Path):
with open(main_c, "r") as _if: with open(main_c, "r") as _if:
content = _if.read() content = _if.read()
patched = content.replace("/* USER CODE BEGIN PFP */\n\n", "/* USER CODE BEGIN PFP */\nvoid my_main();\n").replace("/* USER CODE BEGIN WHILE */\n while (1)", "/* USER CODE BEGIN WHILE */\n my_main();\n while (1)") patched = content.replace("/* USER CODE BEGIN PFP */", "/* USER CODE BEGIN PFP */\nvoid my_main();").replace("/* USER CODE BEGIN WHILE */\n while (1)", "/* USER CODE BEGIN WHILE */\nmy_main();\n while (1)")
with open(main_c, "w") as of: with open(main_c, "w") as of:
of.write(patched) of.write(patched)
def load_config(path: Path): def load_config(path: Path):
if not path.exists(): if not path.exists():
print("WARN: No config file", path)
return return
if not path.is_file(): if not path.is_file():
print("Config '%s' is not a file."%(path)) print("Config '%s' is not a file."%(path))
@@ -184,21 +181,21 @@ def overlay_config(config: dict):
print("exclude must be a list of strings") print("exclude must be a list of strings")
exit(1) exit(1)
CMAKE_EXCLUDE_SOURCES = config["exclude"] CMAKE_EXCLUDE_SOURCES = config["exclude"]
if "assume_yes" in config and config["assume_yes"]: if "assume-yes" in config and config["assume-yes"]:
if not isinstance(config["assume_yes"], bool): if not isinstance(config["assume-yes"], bool):
print("assume_yes must be a bool") print("assume-yes must be a bool")
exit(1) exit(1)
ASSUME_YES |= config["assume_yes"] ASSUME_YES |= config["assume-yes"]
if "inject_handlers" in config and config["inject_handlers"]: if "inject-handlers" in config and config["inject-handlers"]:
if not isinstance(config["inject_handlers"], list): if not isinstance(config["inject-handlers"], list):
print("inject_handlers must be a list of strings") print("inject-handlers must be a list of strings")
exit(1) exit(1)
INJECT_HANDLERS += config["inject_handlers"] INJECT_HANDLERS += config["inject-handlers"]
if "no_my_main" in config and config["no_my_main"]: if "no-my-main" in config and config["no-my-main"]:
if not isinstance(config["no_my_main"], bool): if not isinstance(config["no-my-main"], bool):
print("no_my_main must be a bool") print("no-my-main must be a bool")
exit(1) exit(1)
NO_MY_MAIN |= config["no_my_main"] NO_MY_MAIN |= config["no-my-main"]
def print_config(): def print_config():
print("MX_DISCARD_PATHS", MX_DISCARD_PATHS) print("MX_DISCARD_PATHS", MX_DISCARD_PATHS)
@@ -226,19 +223,17 @@ def main2(ns: Namespace):
recurse_cmakelists(ns.path) recurse_cmakelists(ns.path)
root_cmakelists(ns.path) root_cmakelists(ns.path)
if INJECT_HANDLERS: if not INJECT_HANDLERS:
inject_handlers(ns.path) inject_handlers(ns.path)
if not NO_MY_MAIN: if not NO_MY_MAIN:
call_my_main(ns.path) call_my_main(ns.path)
print("Convert complete")
def main(): def main():
parser = ArgumentParser(prog="MX Convert") parser = ArgumentParser(prog="MX Convert")
parser.add_argument("-c", "--config", action="store", type=Path, default="mx_convert.toml", help="The config file to read. If not specified, defaults to 'mx_convert.toml'.") parser.add_argument("-c", "--config", action="store", type=Path, default="mx_convert.toml", help="The config file to read. If not specified, defaults to 'mx_convert.toml'.")
parser.add_argument("-d", "--discard", action="append", help="Add a file to the discard list (delete if found).") parser.add_argument("-d", "--discard", action="append", help="Add a file to the discard list (delete if found).")
parser.add_argument("-i", "--inject-handlers", action="append", help="Add a call to your own handler functions in MX generated code. Ex: for PendSV_Handler use '-i PendSV_'") parser.add_argument("-i", "--inject-handlers", action="store", help="Add a call to your own handler functions in MX generated code.")
parser.add_argument("-H", "--header", action="append", help="Add a pattern to the headers list, single wildcards allowed. Includes *.h by default.") parser.add_argument("-H", "--header", action="append", help="Add a pattern to the headers list, single wildcards allowed. Includes *.h by default.")
parser.add_argument("-n", "--no-my-main", action="store_true", help="Disable added call to my_main inside the generated main function.") parser.add_argument("-n", "--no-my-main", action="store_true", help="Disable added call to my_main inside the generated main function.")
parser.add_argument("-s", "--source", action="append", help="Add a pattern to the sources list, single wildcards allowed. Includes *.c and *.s by default.") parser.add_argument("-s", "--source", action="append", help="Add a pattern to the sources list, single wildcards allowed. Includes *.c and *.s by default.")

View File

@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "mx_convert" name = "mx_convert"
version = "0.5.6" version = "0.5.5"
description = "A Cube MX projct conversion helper" description = "A Cube MX projct conversion helper"
authors = [{ name = "Didas72" }] authors = [{ name = "Didas72" }]
dependencies = [] dependencies = []