This example showcases the interactions between a HIL gateway and a STM32 microcontroller using the ST-LINK interface.
It consists of a single file:
test_st_link_interface.py - Contains a test that programs a STM32L476RG with embedops-dev-demo.bin firmware, which can be built by following the EmbedOps CLI Quickstart, starts execution of the firmware, and erases the device.
importosfromhil_sdk.interfaces.st_link_interfaceimportSTLinkInterfacedeftest_st_link_interface(hil_extras_get_path):""" Simple example demonstrating ST-LINK interface usage: 1. Program the STM32L476RG with embedops-dev-demo.bin firmware 2. Start execution of the firmware 3. Erase the device """# Note: This is a binary file can be built by following the EmbedOps CLI Quickstart (https://docs.embedops.io/quickstarts/embedops_cli_quickstart/).# If you have a different binary you want to test with, change the binary file path accordingly.# The binary file can be passed to the HIL gateway via the .embedops/hil/config.yml file (https://docs.embedops.io/hil/reference/yaml_config/).bin_file="embedops-dev-demo.bin"# Assuming the binary is in the "build" directorybin_file_path=hil_extras_get_path(f"build/{bin_file}")assertos.path.isfile(bin_file_path),f"Binary file not found: {bin_file_path}"# Create ST-LINK interface instancest_link=STLinkInterface()# Step 1: Program the deviceprint(f"\n1. Programming device with {bin_file} firmware...")assertst_link.download(bin_file_path,start_address=0x08000000,logfile="program_log.txt"),"✗ Programming failed - check program_log.txt for details"print("✓ Programming successful")# Step 2: Start executionprint("\n2. Starting execution...")assertst_link.start(start_address=0x08000000,logfile="reset_log.txt"),"✗ Start execution failed - check reset_log.txt for details"print(f"✓ Start execution successful - {bin_file} should be running")# Step 3: Erase the deviceprint("\n3. Erasing device...")assertst_link.erase_all(logfile="erase_log.txt"),"✗ Erase failed - check erase_log.txt for details"print("✓ Erase successful")print("\n✓ All operations completed successfully!")print("Log files created: program_log.txt, reset_log.txt, erase_log.txt")return0