Programming Lattice MachXO2: "Password key required"? - Page 1
Forum section: electronics / general

author: jrx07
author_rank: Newbie
timestamp: January 11, 2022, 04:14:15 pm
content: Hi everyone,I am running into an issue programming a Lattice MachXO2 LCMXO2-1200ZE. I am using Lattice Diamond 3.12 and an FTDI C232HM-DDHSL-0 cable to program over JTAG.Context: I made a data acquisition PCB using the LCMXO2-1200ZE CPLD (I loved using the TinyFPGA AX2 and wanted to make something with lower standby power consumption). I was able to successfully program the board initially, but when I modified the Verilog and tried to reprogram the chip, I received the following error:QuoteIf I change the Programmer "Access Mode/Operation" to "Advanced Security File Programming/Security Read Status Register" I find that "PWD Enable" is set to '1' and "PWD Protect" is also set to '1'I did not intentionally enable these and I don't have/can't find a password key.My questions:Is it possible to disable the PWD protection?Where in Lattice Diamond are these settings controlled? If I bricked this chip, I just want to make sure I don't repeat this mistake in the future

author: laugensalm
author_rank: Regular Contributor
timestamp: January 12, 2022, 01:04:29 pm
content: If you're using a third party JTAG cable, make sure that signal integrity is met, i.e. TCK has a very fast rise time (< 6 ns) and that the cable length is very short.To do a cheap signal integrity check, you might poll the device IDCODE for a few hours and see if a bit flips.Unfortunately, there is no real protection against accidental misconfiguration on the MachXO* devices, I've seen a few cases getting the wrong settings by a funny sequence caused by their JTAG daemon 'lserver', however those device were in a chain of the MachXO3 types.The internals for XO2 are documented a little sparse, but you should find the details in the Lattice tech notes describing the 'Feature Row'.I don't recall the exact procedure, but I think I got recovery for the XO3 problem just by issueing a full 'ISC_ERASE' sequence. As long as you haven't messed with any OTP fuses, I wouldn't consider it 'bricked'.

author: jrx07
author_rank: Newbie
timestamp: January 13, 2022, 12:24:16 pm
content: Thanks for the tips laugensalm. I did double check the signal integrity with a scope, and the signals seem OK. I like your idea of polling the IDCODE for a few hours though.I'm a bit new to JTAG debugging. Do you have any recommendations for software tools to issue commands/read back data over JTAG?

author: laugensalm
author_rank: Regular Contributor
timestamp: January 13, 2022, 04:44:03 pm
content: From the OpenSource world, I'd check for OpenOCD or urjtag derivatives, at least OpenOCD should allow some TCL-scriped IDCODE polling.That should probably suffice for the paranoia check, plus could also help you with issuing the proper erase sequences in a more low level controlled environment than the sometimes flaky Diamond Programmer. Did you succeed in restoring the feature row?

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 13, 2022, 05:34:48 pm
content: Quote from: jrx07 on January 11, 2022, 04:14:15 pmI've never used the protection features on MachXO2, so I may be missing something. That said, according to the "MachXO2 Programming and Configuration Usage Guide" (TN1204):QuoteIf you ever set those security bits by mistake, there's nothing you can do, as they are OTP.As to how to avoid doing this, I guess if you never use any of the advanced programming modes, you should be fine. What was the programming mode you used?

author: jrx07
author_rank: Newbie
timestamp: January 13, 2022, 07:13:44 pm
content: Quote from: laugensalm on January 13, 2022, 04:44:03 pmThanks I'll try out OpenOCD and post any results! I screwed up my FTDI drivers earlier today intalling urjtag, which has caused my FTDI cable to longer be recognized by Lattice Diamond or FTDI's FT_PROG (cable still recognized by both programs on a different computer though,), so need to solve that problem tonight.I haven't had luck restoring the Feature Row. From the Lattice documentation it seems that's a feature in the standalone "Programming File Utility", but not in Lattice Diamond v3.10 or v3.12. I couldn't seem to install the Programming Utility though...have you tried this in the past?Quote from: SiliconWizard on January 13, 2022, 05:34:48 pmThanks for the info about accidentally setting the fuses. I had used the "Flash Programming Mode" with the "FLASH Erase, Program, Verify" operation. No errors were reported when I did so. Problems only came up afterwords.I do wonder if perhaps when I was programming the power became momentarily disconnected which messed up the configuration?

author: asmi
author_rank: Super Contributor
timestamp: January 13, 2022, 07:26:48 pm
content: It kind of reminds me of AVR micros - I think everybody who ever worked with them as standalone MCUs (not in Arduino) bricked it at least onceFortunately it's reversible in many cases for those MCU, but messing with OTP fuses is always a dangerous affair, infact I don't ever touch them even on my production boards on the off-chance I will ever need to do a field update.

author: jrx07
author_rank: Newbie
timestamp: January 13, 2022, 09:49:16 pm
content: Quote from: asmi on January 13, 2022, 07:26:48 pmThis was my first board with the MachXO2, so hopefully I'm getting the bricks out early in the processFor anyone who encounters this in the future, I figured out the FTDI C232HM cable error...it seems that installing libusb to try have urjtag recognize the cable caused Lattice to no longer recognize the cable. Thinking the FTDI driver didn't install properly, I tried reinstalling it several times. This was my mistake! This essentially created several copies of the driver on my system. To fix the problem, I went to the Device Manager, plugged in the cable, uninstalled the C232HM device that popped up, unplugged the cable...and repeated this process until plugging in the cable no longer caused a device to pop up. At this point, I could reinstall the FTDI drivers and now the cable is recognized by Lattice Diamond. TLDR: don't just reinstall the FTDI drivers multiple times if things aren't workingWill post again soon once I have a chance to try OpenOCD

author: jrx07
author_rank: Newbie
timestamp: January 14, 2022, 08:56:39 pm
content: I tested the MachXO2 again today with Lattice Diamond and with a python script based on PyFTDI(https://github.com/eblot/pyftdi/blob/master/pyftdi/jtag.py).After all of this it seems like the issues might be caused by an unstable physical connection between the JTAG connections and the MachXO2 chip.Using PyFTDI "jtag.py" script and changing the JTAG instructions to match fthe MachXO2 programming commands (p.51,https://www.latticesemi.com/-/media/LatticeSemi/Documents/ApplicationNotes/MO/MachXO2ProgrammingandConfigurationUsageGuide.ashx?document_id=39085) I could successfully query the chip and receive the expected ID code. The FTDI C232H cable is readily recognized by Lattice and by Python (have to run Zadig to switch the driver from FTDI to WinUSB), so the FTDI chip doesn't seem to be the problem.In Lattice Diamond, I found that the chip would occassionally (maybe half the time?) issue the error requiring the programming key. Other times, when trying to perform the operation "FLASH Erase, Program, and Verify," I received an error that the Verify command could not be completed, but no mention that a programming key was necessary.It seems like there's an intermittent failure somewhere in the signal chain based on the inconsistent response. I unfortunately can't run more tests until Monday, but will do so with a QFN breakoutboard and another MachXO2 to see if the physical PCB is the problem. Thanks for all the helpful tips so far.

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 14, 2022, 10:12:39 pm
content: OK, thanks for the heads up.And I wouldn't be hugely surprised if Lattice's programming tool gave funky misleading errors in case of data corruption during the JTAG exchange with the FPGA. It seems to be ridden with dubious error handling and hard-coded pauses here and there. =)So yes, if you can use something else for programming, do not hesitate.

author: laugensalm
author_rank: Regular Contributor
timestamp: January 18, 2022, 10:50:47 am
content: These issues with the Lattice Programmer are also present on a Linux system (which *should* be a more controlled environment with respect to FTDI driver issues). From what I remember looking into it, the dangling JTAG daemon and those reported spurious timeouts would leave the JTAG chain in an undefined state, requiring full restarts/killing the daemon exe manually. However, these are pure software issues that have been reported to Lattice Tech support repeatedly, without any improvement seen up to Diamond v3.12 (last tested).For mass programming, this is (probably still) very frustrating, I had to go for a custom solution.On the JTAG hardware side, it might appear as a surprise, but it may very well be that you don't see TCK glitches on a typical 1GHz scope but still get occasional misbehaviour induced by cross talk due to the very fast input buffer technology of the MACHXO* (assuming the JTAG logic is not any different). So, any programmer based on older FTDI 2232L chips without any extra buffering might likely behave unstable.

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 18, 2022, 06:19:57 pm
content: Quote from: laugensalm on January 18, 2022, 10:50:47 amIt's every bit as horrible on Linux indeed.And for the record, the FTDI "drivers" for Linux (which are not drivers per se, but a library on top of libusb) are rather bad from my experience. So, if this is what Lattice uses (which is very likely), it's not going to help.(To get fast and reliable communication using FTDI parts on Linux, I resorted to writing my own lib (on top of libusb). You can get some inspiration with libftdi - but back when I did this, libftdi was lacking some features, so I wrote my own one.)

author: jrx07
author_rank: Newbie
timestamp: June 21, 2022, 03:32:51 pm
content: For anyone who stumbles on this error in the future, double (triple, quadruple) check the physical connection of your programmer to your device and be sure that the voltage levels are correct. Thanks for the help everyone.