This example is found in API-DLL\FP-GP-ARM-Demo-Py in the installation directory.
If running 64-bit Python (default installation), use the x64 ARM-win setup (X-ProARM-xvxx-Setup_x64)
If running 32-bit Python, use the x86 ARM-win setup (X-ProARM-xvxx-Setup_x86)
For Linux the default Python installation will work with the amd64 or armhf builds.
Any application using the library will call most of the following functions. First, any one adapter is found, and initialized. Assuming at least one adapter was found (F_OpenInstancesAndFPAs returns > 0), the config and code files are loaded to select the MCU and data to be programmed. Finally, the procedure F_AutoProgram will run the full programming sequence of Erase, Blank Check, Write, Verify, and optionally Lock the MCU.
import os import sys import ctypes #FP-ARM - comment this out and uncomment GP-ARM to use demo for GangPro-ARM if (sys.platform == "win32"): libname = "./FlashProARM-FPAsel.dll" else: libname = "libmultifparm.so" #GP-ARM - commented out - comment this out and uncomment FP-ARM to use demo for FlashPro-ARM #if (sys.platform == "win32"): # libname = "./GangProARM-FPAsel.dll" #else: # libname = "libmultigparm.so" init_file = bytes('FPAs-setup.ini', 'utf-8') if (sys.platform == "win32"): config_file_path = bytes('ConfigFiles\\EFR32BG12P433F1024.cfg', 'utf-8') code_file_path = bytes('CodeFiles\\SL-512k.txt', 'utf-8') else: config_file_path = bytes('ConfigFiles/EFR32BG12P433F1024.cfg', 'utf-8') code_file_path = bytes('CodeFiles/SL-512k.txt', 'utf-8') #Load library lib = ctypes.cdll.LoadLibrary(libname) # Get number of connected adapters instances = lib.F_OpenInstancesAndFPAs(init_file) print("Connected adapters: {}".format(instances)) # Init all adapters result = lib.F_Set_FPA_index(0) print("F_Set_FPA_index(0): {}".format(result)) result = lib.F_Initialization() print("F_Initialization: {}".format(result)) # Get adapters serial numbers serials = [] for instance in range(1, instances+1): serials.append(lib.F_Get_FPA_SN(instance)) print(serials) result = lib.F_ConfigFileLoad(config_file_path) print("F_ConfigFileLoad: {}".format(result)) result = lib.F_ReadCodeFile(code_file_path) print("F_ReadCodeFile: {}".format(result)) # Select one adapter result = lib.F_Set_FPA_index(1) print("F_Set_FPA_index(1): {}".format(result)) # Verify Access (not required with Auto Program) result = lib.F_Verify_Access_to_MCU() print("F_Verify_Access_to_MCU: {}".format(result)) # Auto Program result = lib.F_AutoProgram(0) print("F_AutoProgram: {}".format(result)) # Print Auto Program text output (same as GUI) # max length REPORT_MESSAGE_MAX_SIZE 2000 report_s = ctypes.create_string_buffer(2000) lib.F_ReportMessage(report_s) s = report_s.value.decode() print(s)
Running the aforementioned code snippet with Python 3.8.3 produces the following result:
FlashPro-430 python example running on Raspberry Pi - 64-bit (arm64 build)
This example is found in /libfpgp430-5.8.0_arm64/Python-demo in the installation directory (linux unzipped package).
Python 3.9.2 used in example, based on MSP430 installer.
Any application using the library will call most of the following functions. First, any one adapter is found, and initialized. Assuming at least one adapter was found (F_OpenInstancesAndFPAs returns > 0), the config and code files are loaded to select the MCU and data to be programmed. Finally, the procedure F_AutoProgram will run the full programming sequence of Erase, Blank Check, Write, Verify, and optionally Lock the MCU.
from ctypes import cdll, c_int, c_long, c_byte, c_char_p, create_string_buffer, Structure # Load the DLL fpasel_dll = cdll.LoadLibrary('/usr/lib/aarch64-linux-gnu/libmultifp430.so') # Set function return types and argument types fpasel_dll.F_Multi_DLLTypeVer.restype = c_int fpasel_dll.F_Get_FPA_SN.restype = c_long fpasel_dll.F_OpenInstancesAndFPAs.argtypes = [c_char_p] fpasel_dll.F_ConfigFileLoad.argtypes = [c_char_p] fpasel_dll.F_ReadCodeFile.argtypes = [c_int, c_char_p] # Prepare string buffer for serial numbers serial_numbers = create_string_buffer(b"*# *") # Call DLL functions fpa_instances = fpasel_dll.F_OpenInstancesAndFPAs(serial_numbers) dll_id = fpasel_dll.F_Multi_DLLTypeVer() result = fpasel_dll.F_Use_Config_INI(0) result = fpasel_dll.F_Initialization() serial_number = fpasel_dll.F_Get_FPA_SN(1) # Output results print("Discovered adapters: {}".format(fpa_instances)) formatted_dll_id = "Multi-FPA DLL version - {0:X}.{1:02X}".format((dll_id >> 8) & 0xF, dll_id & 0xFF) print(formatted_dll_id) print("Adapter serial number: {}".format(serial_number)) # Load configuration and program files config_result = fpasel_dll.F_ConfigFileLoad(b'../LinuxCommandLineDemo/TestConfigs/config_F169.cfg') file_result = fpasel_dll.F_ReadCodeFile(1, b'../LinuxCommandLineDemo/TestCodeFiles/test_8k.txt') ap_result = fpasel_dll.F_AutoProgram(0) # Output results of operations print("Config file load: {}".format(config_result)) print("Code file read: {}".format(file_result)) print("Auto Program: {}".format(ap_result)) # Set the return type for F_Report_Message to c_char_p (C string) fpasel_dll.F_Report_Message.restype = c_char_p # Call the function to get the report message report_message = fpasel_dll.F_Report_Message() # Check if the message is not None and decode it to a Python string if report_message: print(report_message.decode('utf-8')) else: print("No report message available.") # Close instances fpasel_dll.F_CloseInstances()
Running the aforementioned code snippet with Python 3.9.2 produces the following result: