Python Basic Demo Code Sequence

This example uses python to program the target board.

  • If running 64-bit Python (default installation), use the x64 M-win setup (X-ProM-xvxx-Setup_x64)

  • If running 32-bit Python, use the x86 M-win setup (X-ProM-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-M - comment this out and uncomment GP-M to use demo for GangPro-M if (sys.platform == "win32"): libname = "./FlashProM-FPAsel.dll" else: libname = "libmultifpm.so" #GP-M - commented out - comment this out and uncomment FP-M to use demo for FlashPro-M #if (sys.platform == "win32"): # libname = "./GangProM-FPAsel.dll" #else: # libname = "libmultigpm.so" init_file = bytes('FPAs-setup.ini', 'utf-8') if (sys.platform == "win32"): config_file_path = bytes('ConfigFiles\\MX25L51245G-128k.cfg', 'utf-8') code_file_path = bytes('CodeFiles\\0base-32k.sflash.txt', 'utf-8') else: config_file_path = bytes('ConfigFiles/MX25L51245G-128k.cfg', 'utf-8') code_file_path = bytes('CodeFiles/0base-32k.sflash.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)

 

 

Â