|
27 | 27 | # GitHub
|
28 | 28 | gh_st = "https://github.com/STMicroelectronics/"
|
29 | 29 | gh_core = "https://github.com/stm32duino/Arduino_Core_STM32.git"
|
| 30 | +gh_ble = "https://github.com/stm32duino/STM32duinoBLE.git" |
30 | 31 | repo_generic_name = "STM32Cube"
|
31 | 32 | repo_core_name = "Arduino_Core_STM32"
|
| 33 | +repo_ble_name = "STM32duinoBLE" |
32 | 34 | repo_local_path = home / "STM32Cube_repo"
|
33 | 35 | local_cube_path = Path("")
|
34 | 36 |
|
@@ -611,6 +613,158 @@ def updateMDFile(md_file, serie, version):
|
611 | 613 | print(regexmd_up.sub(rf"\g<1>{version}", line), end="")
|
612 | 614 |
|
613 | 615 |
|
| 616 | +def updateBleRepo(): |
| 617 | + # Handle BLE library repo |
| 618 | + repo_path = repo_local_path / repo_ble_name |
| 619 | + print(f"Updating {repo_ble_name}...") |
| 620 | + if repo_path.exists(): |
| 621 | + rname, bname = getRepoBranchName(repo_path) |
| 622 | + # Get new tags from the remote |
| 623 | + git_cmds = [ |
| 624 | + ["git", "-C", repo_path, "fetch"], |
| 625 | + [ |
| 626 | + "git", |
| 627 | + "-C", |
| 628 | + repo_path, |
| 629 | + "checkout", |
| 630 | + "-B", |
| 631 | + bname, |
| 632 | + f"{rname}/{bname}", |
| 633 | + ], |
| 634 | + ] |
| 635 | + else: |
| 636 | + # Clone it as it does not exists yet |
| 637 | + git_cmds = [["git", "-C", repo_local_path, "clone", gh_ble]] |
| 638 | + for cmd in git_cmds: |
| 639 | + execute_cmd(cmd, None) |
| 640 | + |
| 641 | + |
| 642 | +ble_file_list = [ |
| 643 | + "Middlewares/ST/STM32_WPAN/ble/core/ble_bufsize.h", |
| 644 | + "Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/hw.h", |
| 645 | + "Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/shci/shci.c", |
| 646 | + "Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/shci/shci.h", |
| 647 | + "Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/tl/mbox_def.h", |
| 648 | + "Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/tl/shci_tl.c", |
| 649 | + "Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/tl/shci_tl.h", |
| 650 | + "Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/tl/tl.h", |
| 651 | + "Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/tl/tl_mbox.c", |
| 652 | + "Middlewares/ST/STM32_WPAN/stm32_wpan_common.h", |
| 653 | + "Middlewares/ST/STM32_WPAN/utilities/stm_list.c", |
| 654 | + "Middlewares/ST/STM32_WPAN/utilities/stm_list.h", |
| 655 | + "Middlewares/ST/STM32_WPAN/LICENSE.md", |
| 656 | + "Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode/Core/Inc/app_conf.h", |
| 657 | + "Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode/STM32_WPAN/Target/" |
| 658 | + + "hw_ipcc.c", |
| 659 | +] |
| 660 | + |
| 661 | + |
| 662 | +def applyBlePatch(): |
| 663 | + print(" Applying patches to ble library") |
| 664 | + BLE_patch_path = repo_local_path / repo_ble_name / "extras" / "STM32Cube_FW" |
| 665 | + patch_list = [] |
| 666 | + |
| 667 | + if BLE_patch_path.is_dir(): |
| 668 | + for file in sorted(BLE_patch_path.iterdir()): |
| 669 | + if file.name.endswith(".patch"): |
| 670 | + patch_list.append(BLE_patch_path / file) |
| 671 | + |
| 672 | + if len(patch_list): |
| 673 | + patch_failed = [] |
| 674 | + print( |
| 675 | + f" Apply {len(patch_list)} patch{'' if len(patch_list) == 1 else 'es'} for BLE library" |
| 676 | + ) |
| 677 | + for patch in patch_list: |
| 678 | + try: |
| 679 | + # Test the patch before apply it |
| 680 | + status = execute_cmd( |
| 681 | + [ |
| 682 | + "git", |
| 683 | + "-C", |
| 684 | + repo_local_path / repo_ble_name, |
| 685 | + "apply", |
| 686 | + "--check", |
| 687 | + patch, |
| 688 | + ], |
| 689 | + subprocess.STDOUT, |
| 690 | + ) |
| 691 | + if status: |
| 692 | + print(f"patch {patch} can't be applied") |
| 693 | + patch_failed.append([patch, status]) |
| 694 | + continue |
| 695 | + |
| 696 | + # Apply the patch |
| 697 | + status = execute_cmd( |
| 698 | + [ |
| 699 | + "git", |
| 700 | + "-C", |
| 701 | + repo_local_path / repo_ble_name, |
| 702 | + "am", |
| 703 | + "--keep-non-patch", |
| 704 | + "--quiet", |
| 705 | + "--signoff", |
| 706 | + patch, |
| 707 | + ], |
| 708 | + None, |
| 709 | + ) |
| 710 | + except subprocess.CalledProcessError as e: |
| 711 | + patch_failed.append([patch, e.cmd, e.output.decode("utf-8")]) |
| 712 | + # print(f"Failed command: {e.cmd}") |
| 713 | + if len(patch_failed): |
| 714 | + for fp in patch_failed: |
| 715 | + e_out = "" if len(fp) == 2 else f"\n--> {fp[2]}" |
| 716 | + print(f"Failed to apply {fp[0]}:\n{fp[1]}{e_out}") |
| 717 | + |
| 718 | + |
| 719 | +def updateBleReadme(filepath, version): |
| 720 | + print(" Updating README.md in ble library") |
| 721 | + for line in fileinput.input(filepath, inplace=True): |
| 722 | + print(re.sub(r"v\d+.\d+.\d+", version, line), end="") |
| 723 | + |
| 724 | + |
| 725 | +def updateBleLibrary(): |
| 726 | + if upargs.local: |
| 727 | + cube_path = local_cube_path |
| 728 | + else: |
| 729 | + cube_name = f"{repo_generic_name}WB" |
| 730 | + cube_path = repo_local_path / cube_name |
| 731 | + ble_path = repo_local_path / repo_ble_name / "src" / "utility" / "STM32Cube_FW" |
| 732 | + cube_version = cube_versions["WB"] |
| 733 | + |
| 734 | + ble_commit_msg = f"Update STM32Cube_FW from Cube version {cube_version}" |
| 735 | + |
| 736 | + for file in ble_file_list: |
| 737 | + file_path = Path(cube_path / file) |
| 738 | + file_name = file_path.name |
| 739 | + if file_path.exists: |
| 740 | + # copy each file to destination |
| 741 | + if not Path(ble_path / file_name).parent.exists(): |
| 742 | + Path(ble_path / file_name).parent.mkdir(parents=True) |
| 743 | + if file_name == "app_conf.h": |
| 744 | + # rename app_conf.h to app_conf_default.h |
| 745 | + copyFile(file_path, ble_path / "app_conf_default.h") |
| 746 | + else: |
| 747 | + copyFile(file_path, ble_path / file_name) |
| 748 | + else: |
| 749 | + print(f"File : {file_path} not found") |
| 750 | + print("Abort") |
| 751 | + sys.exit() |
| 752 | + |
| 753 | + updateBleReadme(ble_path / "README.md", cube_version) |
| 754 | + |
| 755 | + # Commit all BLE files |
| 756 | + commitFiles(ble_path, ble_commit_msg) |
| 757 | + |
| 758 | + # Apply BLE Arduino specific patch |
| 759 | + applyBlePatch() |
| 760 | + |
| 761 | + |
| 762 | +def updateBle(): |
| 763 | + print("Updating WB BLE library") |
| 764 | + updateBleRepo() |
| 765 | + updateBleLibrary() |
| 766 | + |
| 767 | + |
614 | 768 | def updateOpenAmp():
|
615 | 769 | print("Updating OpenAmp Middleware")
|
616 | 770 | repo_path = repo_local_path / repo_core_name
|
@@ -753,6 +907,9 @@ def updateCore():
|
753 | 907 | " --> Projects/STM32MP157C-DK2/Applications/OpenAMP/OpenAMP_TTY_echo"
|
754 | 908 | )
|
755 | 909 |
|
| 910 | + if serie == "WB": |
| 911 | + updateBle() |
| 912 | + |
756 | 913 |
|
757 | 914 | # Parser
|
758 | 915 | upparser = argparse.ArgumentParser(
|
|
0 commit comments