eblot / pyftdi

FTDI device driver written in pure Python
Other
509 stars 212 forks source link

Trying to write `channel_a_type = 1` to EEPROM connected to FT232H causes `KeyError: '1'` exception #380

Open FreddieChopin opened 5 months ago

FreddieChopin commented 5 months ago

I have a custom device based on FT232H with external EEPROM. Programming it with pyftdi versions 0.55.0 and below worked fine. However with the most recent 0.55.4 I get an error with the most basic re-programming operation - I cannot write the EEPROM dump that I have just read from exactly the same device:

$ ftconf.py -P 0403:8220 ftdi://0x0403:0x8220/1 -o dump.ini 
$ ftconf.py -P 0403:8220 ftdi://0x0403:0x8220/1 -i dump.ini 
Traceback (most recent call last):
  File "/usr/bin/ftconf.py", line 192, in <module>
    main()
  File "/usr/bin/ftconf.py", line 129, in main
    eeprom.load_config(args.input, args.load)
  File "/usr/lib/python3.12/site-packages/pyftdi/eeprom.py", line 443, in load_config
    self.set_property(opt, value)
  File "/usr/lib/python3.12/site-packages/pyftdi/eeprom.py", line 501, in set_property
    val = self.CHANNEL[value]
          ~~~~~~~~~~~~^^^^^^^
  File "/usr/lib/python3.12/enum.py", line 814, in __getitem__
    return cls._member_map_[name]
           ~~~~~~~~~~~~~~~~^^^^^^
KeyError: '1'

I attach this dump.ini file. dump.zip

Generally the same thing happens if I have an "erased" EEPROM and want to write my configuration there.

I believe this may be related to this commit, however this is just my guess: https://github.com/eblot/pyftdi/commit/e68e4c36a274233744cd07c1dd910a4604094c85

After a bit of debugging it seems that the key-value that causes this is channel_a_type = 1 - if I remove this one line from the dump.ini file, the dry-run programming works fine.

phartleyp commented 4 months ago

I found the same issue, and came to the same conclusion that it is caused by e68e4c3.

Unfortunately ftconf.py with the -o option saves channel_a_type = 1 but ftconf.py with the -i option to ingest the just-generated file expects channel_a_type = FIFO (or one of the CONFIG flags). It looks like you can avoid this issue by updating channel_a_type in your config file as follows: