Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(debug): implement latest arduino-cli specifications #2409

Merged
merged 12 commits into from
Jun 27, 2024

Conversation

fpistm
Copy link
Member

@fpistm fpistm commented Jun 27, 2024

Include:

Note

All series can used debug feature thanks STLink interface and openocd.
Except:

  • STM32H5xx: current openocd version do not support it
  • STM32MP1xx required other transport layer

image

  • One shot script to update all boards.txt entries with debug options
    import fileinput
    import re
    from pathlib import Path
    
    
    script_path = Path(__file__).parent.resolve()
    # Base path
    core_path = script_path
    variant_path = core_path / "variants"
    boards_entry_filename = "boards_entry.txt"
    config_series = {
        "STM32MP1xx": "stm32mp15x.cfg",
        "STM32C0xx": "stm32c0x.cfg",
        "STM32F0xx": "stm32f0x.cfg",
        "STM32F1xx": "stm32f1x.cfg",
        "STM32F2xx": "stm32f2x.cfg",
        "STM32F3xx": "stm32f3x.cfg",
        "STM32F4xx": "stm32f4x.cfg",
        "STM32F7xx": "stm32f7x.cfg",
        "STM32G0xx": "stm32g0x.cfg",
        "STM32G4xx": "stm32g4x.cfg",
        "STM32H5xx": "stm32h5x.cfg",
        "STM32H7xx": "stm32h7x.cfg",
        "STM32L0xx": "stm32l0x.cfg",
        "STM32L1xx": "stm32l1x.cfg",
        "STM32L4xx": "stm32l4x.cfg",
        "STM32L5xx": "stm32l5x.cfg",
        "STM32U5xx": "stm32u5x.cfg",
        "STM32WBxx": "stm32wbx.cfg",
        "STM32WBAxx": "stm32wbax.cfg",
        "STM32WLxx": "stm32wlx.cfg",
    }
    
    
    def main():
        # Parse boards.txt
        regexmd_newline = re.compile(r"^$")
        board_serie = ""
        base_line = ""
        found_series = False
        generic = False
        # Not for generic
        # <menu name>.menu.pnum.<BoardName>.debug.server.openocd.scripts.2=target/<openocd serie>.cfg
        for line in fileinput.input(core_path / "boards.txt", inplace=True):
            m = regexmd_newline.match(line)
            if m and found_series:
                if not board_serie or not base_line:
                    exit(1)
                if not generic:
                    # Add target line
                    print(
                        f"{base_line}debug.server.openocd.scripts.2=target/{config_series[board_serie]}",
                    )
    
                found_series = False
            if "build.series=" in line:
                if ".menu." in line:
                    generic = False
                else:
                    generic = True
                if found_series:
                    exit(2)
                found_series = True
                board_serie = line.partition("=")[-1].strip()
                base_line = line.partition("build.series")[0].strip()
            print(line, end="")
    
        # For all with variant path
        # <menu name>.menu.pnum.<BoardName>.debug.svd_file={runtime.platform.path}/svd/{build.series}/<svdfile>
        variant_path = Path()
        product_line = ""
        found_svd = False
        found_variant = False
        svd_file = ""
        for line in fileinput.input(core_path / "boards.txt", inplace=True):
            m = regexmd_newline.match(line)
            if m and found_variant and product_line:
                # Add svd file
                # Opend boards_entry.txt and extract build.board
                with open(
                    core_path / "variants" / variant_path / "boards_entry.txt"
                ) as myfile:
                    for line2 in myfile:
                        if "product_line=" in line2:
                            if product_line == line2.partition("=")[-1].strip():
                                found_svd = True
                        if found_svd and "debug.svd_file" in line2:
                            svd_file = line2.partition("=")[-1].strip()
                            break
                if svd_file:
                    print(
                        f"{base_line}debug.svd_file={svd_file}",
                    )
                svd_file = ""
                product_line = ""
                found_svd = False
                found_variant = False
            if "build.variant=" in line:
                variant_path = Path(line.partition("=")[-1].strip())
                found_variant = True
            if "build.product_line=" in line:
                product_line = line.partition("=")[-1].strip()
                base_line = line.partition("build.product_line")[0].strip()
    
            print(line, end="")
    
        exit(0)
    
    
    if __name__ == "__main__":
        main()

fpistm added 4 commits June 27, 2024 10:15
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
avoid multiple json files.

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@fpistm fpistm force-pushed the debug_enhancement branch from 2851ee8 to 4ee3c63 Compare June 27, 2024 08:16
fpistm added 4 commits June 27, 2024 11:15
This script will update the stm32_svd repository:
https://github.com/stm32duino/stm32_svd

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@fpistm fpistm force-pushed the debug_enhancement branch from 4ee3c63 to 4f7fcbb Compare June 27, 2024 12:39
fpistm added 3 commits June 27, 2024 15:42
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@fpistm fpistm force-pushed the debug_enhancement branch from 4f7fcbb to 7bfa64c Compare June 27, 2024 13:57
@fpistm fpistm merged commit 1296dfa into stm32duino:main Jun 27, 2024
23 checks passed
@fpistm fpistm deleted the debug_enhancement branch June 27, 2024 14:11
@fpistm fpistm added enhancement New feature or request and removed New feature labels Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

1 participant