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
chunk
ataddr
into 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 raisesValueError
if it is not.
- classmethod decode(data, partial=False)[source]¶
Parse configuration from an image loaded from an EEPROM.
Returns
None
if the EEPROM image is empty (the EEPROM was erased),FX2Config
if it contains a valid configuration, or raisesValueError
if it does not.If
partial
isTrue
, 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
length
bytes ataddr
from internal RAM. Note that not all memory can be addressed this way; consult the TRM.
- write_ram(addr, data)[source]¶
Write
data
toaddr
to 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
length
bytes ataddr
from boot EEPROM inchunk_size
chunks.Requires the second stage bootloader.
- write_boot_eeprom(addr, data, addr_width, chunk_size=16, page_size=0)[source]¶
Write
data
toaddr
in boot EEPROM that has2 ** page_size
byte pages inchunk_size
chunks.Writing EEPROM is much slower than reading; for best performance, specify
page_size
per EEPROM datasheet, and setchunk_size
to 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
file
is a TTY, and raisesValueError
otherwise.
- 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_data
is a string, it is treated as hexadecimal. Otherwise, the format is determined by thefmt
argument.Raises
ValueError
if 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
data
tofile
.- Parameters
data – A byte array (
bytes
,bytearray
andlist
of(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()
.