Python-puzzled

91 views
Skip to first unread message

Mike Butts

unread,
Feb 24, 2013, 5:26:03 PM2/24/13
to fpgalin...@googlegroups.com
Hi Chris and FPGAlinkers,

Last weekend I learned Python, translated a simple assembler I wrote for my FPGA CPU from Java to Python, and was delighted with how quickly that went. Python often seems to have just what I would like, and the interactive mode makes it so easy to work out questions. So now I'm translating my FPGAlink-based runtime monitor from C to Python. That's going pretty well but getting started I ran into a puzzling problem.

I did the interactive execution Chris included in examples/python/README, in a form to suit my Mac (DYLD_LIBRARY_PATH) and my Atlys board (1443:0007). That worked just fine, and lit up the LED on my board.

But when I put the very same statements into a script and run it, flOpen failed. See my transcript below: first the script, then the interactive session, then executing the script.

I must be missing something here. Any ideas? Thanks!

  --Mike

PS: Chris, I'm so into Python I haven't tried out your new Java binding. Hope you don't mind. Everything you've created and the support you're giving users is just above and beyond, thanks.

--
Mike Butts mbu...@ieee.org

MBMBPro:software mike$ more foo.py 
#!/usr/bin/python
#
from fpgalink2 import *
flLoadStandardFirmware("1443:0007", "1443:0007", "D0234")                # 1443:0007 for Nexys3 & Atlys
handle = flOpen("1443:0007")                                             # Open the connection
flPlayXSVF(handle, "libfpgalink-20120621/gen_csvf/ex_cksum_atlys_fx2_verilog.csvf")  # Or other SVF, XSVF or CSVF
flWriteChannel(handle, 1000, 0x00, 0x10)                                 # Write a byte to channel 0
flClose(handle)

MBMBPro:software mike$ python
Python 2.6.1 (r261:67515, Aug  2 2010, 20:10:18) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from fpgalink2 import *
>>> flLoadStandardFirmware("1443:0007", "1443:0007", "D0234")
>>> handle = flOpen("1443:0007") 
>>> flPlayXSVF(handle, "libfpgalink-20120621/gen_csvf/ex_cksum_atlys_fx2_verilog.csvf")
>>> flWriteChannel(handle, 1000, 0x00, 0x10) 
>>> flClose(handle)
>>> ^D
MBMBPro:software mike$ python foo.py 
Traceback (most recent call last):
  File "foo.py", line 5, in <module>
    handle = flOpen("1443:0007")                                             # Open the connection
  File "/Users/mike/ComputeForest/software/fpgalink2.py", line 112, in flOpen
    raise FLException(s)
fpgalink2.FLException: flOpen(): Device 1443:0007 not found
MBMBPro:software mike$ 

Mike Butts

unread,
Feb 24, 2013, 5:50:14 PM2/24/13
to fpgalin...@googlegroups.com, mbu...@ieee.org
It's a race. If I copy the contents of my script and paste them into the python command line, it fails the same way as the script does. But when I copy/paste a line at a time it works fine.

That told me there's some sort of race here, that running flOpen immediately after flLoadStandardFirmware fails, but with manual delay it works fine. So I added time.sleep() between them in my script. With a 1 second delay it fails, but with a 2 second delay it works.

There must be something my code should check after flLoadStandardFirmware and before flOpen, to synchronize properly???

Thanks again!

  --Mike

#!/usr/bin/python
#
from fpgalink2 import *
import time
status = flLoadStandardFirmware("1443:0007", "1443:0007", "D0234")                # 1443:0007 for Nexys3 & Atlys
print "sleep"
time.sleep(2)
print "awake"
handle = flOpen("1443:0007")                                             # Open the connection
flPlayXSVF(handle, "libfpgalink-20120621/gen_csvf/ex_cksum_atlys_fx2_verilog.csvf")  # Or other SVF, XSVF or CSVF
flWriteChannel(handle, 1000, 0x00, 0x10)                                 # Write a byte to channel 0
flClose(handle)


Chris McClelland

unread,
Feb 24, 2013, 6:49:58 PM2/24/13
to fpgalin...@googlegroups.com, mbu...@ieee.org
This is what flAwaitDevice()[1] is for. The fpgalink2.py itself may be
executed directly; it includes an example of flAwaitDevice() usage[2].

The timeout is in tenths of a second*. The firmware renumeration delay
will be about 1500ms[3], so unless there's something very wrong with the
OS itself, renumeration should happen within a couple of seconds.

Chris

[1]https://github.com/makestuff/libfpgalink/blob/master/examples/python/fpgalink2.py#L121
[2]https://github.com/makestuff/libfpgalink/blob/master/examples/python/fpgalink2.py#L338
[3]https://github.com/mulicheng/fx2lib/blob/master/include/fx2macros.h#L99

* Actually there's an extra 1s delay inserted initially. This is because
it's legal to set the target VID:PID to be the same as the initial
VID:PID. It wouldn't do to have flAwaitDevice() respond immediately with
"yup, it's there!" before the FX2LP has had a chance to drop off the
bus.
> --
> You received this message because you are subscribed to the "FPGALink
> Users" mailgroup (see
> http://www.makestuff.eu/wordpress/software/fpgalink/).
>
> To post to this group, send email to fpgalin...@googlegroups.com
> To unsubscribe from this group, send email to
> fpgalink-user...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/fpgalink-users?hl=en
>
> ---
> You received this message because you are subscribed to the Google
> Groups "FPGALink Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to fpgalink-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>


Peter Stuge

unread,
Feb 24, 2013, 7:38:52 PM2/24/13
to fpgalin...@googlegroups.com
Chris McClelland wrote:
> it's legal to set the target VID:PID to be the same as the initial VID:PID.

Actually that is quite questionable USB behavior.


> It wouldn't do to have flAwaitDevice() respond immediately

libusb is getting a hotplug API. Hang in there.


//Peter

Mike Butts

unread,
Feb 25, 2013, 12:49:38 AM2/25/13
to fpgalin...@googlegroups.com
Yes! That does the trick. I should have read fpgalink2.py more closely. Thank you!

  --Mike
--
Mike Butts mbu...@ieee.org

Soumitra khair

unread,
Feb 2, 2018, 2:36:04 PM2/2/18
to FPGALink Users
Chris and libfpgalink users

I am using Nexys3 board and python.

In my python script I am having issues in connecting to FPGA . In my script I have tried to connect using the code from flici.

def fpga():
handle = fl.FLHandle()

try:
fl.flInitialise(0)

vp = "1443:0007"
print("Attempting to open connection to FPGALink device {}...".format(vp))
try:
handle = fl.flOpen(vp)
except fl.FLException as ex:
if True:
ivp = "1443:0007"
print("Loading firmware into {}...".format(ivp))
fl.flLoadStandardFirmware(ivp, vp)

print("Awaiting renumeration...")
if (not fl.flAwaitDevice(vp, 600)):
raise fl.FLException("FPGALink device did not renumerate properly as {}".format(vp))

print("Attempting to open connection to FPGALink device {} again...".format(vp))
handle = fl.flOpen(vp)
else:
raise fl.FLException("Could not open FPGALink device at {} and no initial VID:PID was supplied".format(vp))

isNeroCapable = fl.flIsNeroCapable(handle)


except fl.FLException as ex:
print(ex)
finally:
fl.flClose(handle)
print("Exit Finally")


Following output I am getting when I am calling fpga() for connecting to fpga

Attempting to open connection to FPGALink device 1443:0007...
Loading firmware into 1443:0007...
Awaiting renumeration...
FPGALink device did not renumerate properly as 1443:0007
Exit Finally

Although when I am connecting to FPGA in commadline mode its working.Am I missing something in this code ?

Thanks,
SK

Chris McClelland

unread,
Feb 7, 2018, 5:53:26 AM2/7/18
to fpgalin...@googlegroups.com
Start from a known-good state. Fetch and build the latest release (20170708) and try the appropriate command from the "noninteractive execution" section of the examples/python/README[1]. In your reply, show exactly what command you ran, and exactly what response you get.

Chris

You received this message because you are subscribed to the "FPGALink Users" mailgroup (see https://github.com/makestuff/libfpgalink/wiki/FPGALink).
 
To post to this group, send email to fpgalink-users@googlegroups.com

To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/fpgalink-users?hl=en
---
You received this message because you are subscribed to the Google Groups "FPGALink Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fpgalink-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages