Host-side library reference
- class fx2.FX2Config(vendor_id=1204, product_id=34323, device_id=0, disconnect=False, i2c_400khz=False)[source]
Cypress FX2 EEPROM configuration data.
- vendor_idint
USB vendor ID, 16 bits.
- product_idint
USB product ID, 16 bits.
- device_idint
USB device ID, 16 bits in binary-coded decimal.
- disconnectbool
If
True, do not enumerate on startup. IfFalse, enumerate as a default FX2 device with specified VID/PID/DID.- i2c_400khzbool
If
True, use 400 kHz I2C clock to read firmware from EEPROM. IfFalse, use 100 kHz clock.- firmwarelist
Firmware to be loaded into on-chip program/data RAM. If empty, “C0 load” is used; if not, “C2 load” is used, and the command to bring the CPU out of reset is inserted automatically.
- append(addr, chunk)[source]
Append a command to load
chunkataddrinto on-chip program/data RAM on device startup.
- encode(max_size=None)[source]
Convert configuration to an image that can be loaded into an EEPROM.
Returns the EEPROM image if the resulting configuration is smaller than
max_size, or raisesValueErrorif it is not.
- classmethod decode(data, partial=False)[source]
Parse configuration from an image loaded from an EEPROM.
Returns
Noneif the EEPROM image is empty (the EEPROM was erased),FX2Configif it contains a valid configuration, or raisesValueErrorif it does not.If
partialisTrue, only requires any data records present to be complete; if it isFalse, it is an error unless the image contains the final data record.
- class fx2.FX2Device(vendor_id=1204, product_id=34323)[source]
A Cypress FX2 series device.
The initializer of this class locates the device by provided VID:PID pair, or raises a
FX2DeviceError.- usbusb1.USBDeviceHandle
Raw USB device handle.
- control_read(request_type, request, value, index, length, timeout=None)[source]
Issue an USB control read request with timeout defaulting to
self.timeout.
- control_write(request_type, request, value, index, data, timeout=None)[source]
Issue an USB control write request with timeout defaulting to
self.timeout.
- bulk_read(endpoint, length, timeout=None)[source]
Issue an USB bulk read request with timeout defaulting to
self.timeout.
- bulk_write(endpoint, data, timeout=None)[source]
Issue an USB bulk write request with timeout defaulting to
self.timeout.
- read_ram(addr, length)[source]
Read
lengthbytes ataddrfrom internal RAM. Note that not all memory can be addressed this way; consult the TRM.
- write_ram(addr, data)[source]
Write
datatoaddrto internal RAM. Note that not all memory can be addressed this way; consult the TRM.
- load_ram(chunks)[source]
Write
chunks, a list of(address, data)pairs, to internal RAM, and start the CPU core. See alsowrite_ram.
- read_boot_eeprom(addr, length, addr_width, chunk_size=256)[source]
Read
lengthbytes ataddrfrom boot EEPROM inchunk_sizechunks.Requires the second stage bootloader.
- write_boot_eeprom(addr, data, addr_width, chunk_size=16, page_size=0)[source]
Write
datatoaddrin boot EEPROM that has2 ** page_sizebyte pages inchunk_sizechunks.Writing EEPROM is much slower than reading; for best performance, specify
page_sizeper EEPROM datasheet, and setchunk_sizeto a small multiple of2 ** page_size. Otherwise, timeouts may occur.Requires the second stage bootloader or a compatible firmware.
- fx2.format.autodetect(file)[source]
Autodetect file format based on properties of a given file object.
Returns “ihex” for .hex, .ihex and .ihx file extensions, “bin” for .bin file extension, “hex” if
fileis a TTY, and raisesValueErrorotherwise.
- fx2.format.input_data(file_or_data, fmt='auto', offset=0)[source]
Read Intel HEX, hexadecimal, or binary data from
file_or_data. Iffile_or_datais a string, it is treated as hexadecimal. Otherwise, the format is determined by thefmtargument.Raises
ValueErrorif the input data has invalid format.Returns a list of
(address, data)chunks.- Parameters:
fmt –
"ihex"for Intel HEX,"hex"for hexadecimal,"bin"for binary, or"auto"for autodetection viaautodetect().offset – Offset the data by specified amount of bytes.
- fx2.format.output_data(file, data, fmt='auto', offset=0)[source]
Write Intel HEX, hexadecimal, or binary
datatofile.- Parameters:
data – A byte array (
bytes,bytearrayandlistof(addr, chunk)pairs are all valid).fmt –
"ihex"for Intel HEX,"hex"for hexadecimal,"bin"for binary, or"auto"for autodetection viaautodetect().offset – Offset the data by specified amount of bytes.
- fx2.format.flatten_data(data, *, fill=0)[source]
Flatten a list of
(addr, chunk)pairs, such as that returned byinput_data(), to a flat byte array, such as that accepted byoutput_data().