Skip to content

Instantly share code, notes, and snippets.

@jpenalbae
Last active November 6, 2017 07:26
Show Gist options
  • Save jpenalbae/15cdfdf5eefa7e7cbc8afba9b7aa89b1 to your computer and use it in GitHub Desktop.
Save jpenalbae/15cdfdf5eefa7e7cbc8afba9b7aa89b1 to your computer and use it in GitHub Desktop.

Revisions

  1. jpenalbae revised this gist Nov 6, 2017. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions black-iceprog.py
    Original file line number Diff line number Diff line change
    @@ -15,8 +15,7 @@ def send_data(devname, filename):
    data = bstream.read(1024)
    if data == '':
    break
    port.write(data)
    wrote += len(data)
    wrote += port.write(data)

    except Exception as e:
    print 'Error uploading bitstream'
  2. jpenalbae revised this gist Nov 6, 2017. 1 changed file with 3 additions and 24 deletions.
    27 changes: 3 additions & 24 deletions black-iceprog.py
    Original file line number Diff line number Diff line change
    @@ -1,40 +1,19 @@
    #!/usr/bin/python

    import sys
    import platform

    def set_rawmode(port):
    import termios

    orig_attr = termios.tcgetattr(port)
    iflag, oflag, cflag, lflag, ispeed, ospeed, cc = orig_attr

    cflag |= (termios.CLOCAL | termios.CREAD)
    lflag &= ~(termios.ICANON | termios.ECHO | termios.ECHOE |
    termios.ECHOK | termios.ECHONL |
    termios.ISIG | termios.IEXTEN) # |termios.ECHOPRT
    oflag &= ~(termios.OPOST | termios.ONLCR | termios.OCRNL)
    iflag &= ~(termios.INLCR | termios.IGNCR | termios.ICRNL | termios.IGNBRK)

    termios.tcsetattr(
    port,
    termios.TCSANOW,
    [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
    import serial


    def send_data(devname, filename):
    wrote = 0

    try:
    port = open(devname, 'w')
    port = serial.Serial(devname)
    bstream = open(filename, 'r')

    if platform.system() != "Windows":
    set_rawmode(port)

    while True:
    data = bstream.read(1024)
    if data == '' or len(data) == 0:
    if data == '':
    break
    port.write(data)
    wrote += len(data)
  3. jpenalbae revised this gist Nov 6, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions black-iceprog.py
    Original file line number Diff line number Diff line change
    @@ -52,3 +52,4 @@ def send_data(devname, filename):
    sys.exit(1)

    send_data(sys.argv[1], sys.argv[2])

  4. jpenalbae created this gist Nov 6, 2017.
    54 changes: 54 additions & 0 deletions black-iceprog.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #!/usr/bin/python

    import sys
    import platform

    def set_rawmode(port):
    import termios

    orig_attr = termios.tcgetattr(port)
    iflag, oflag, cflag, lflag, ispeed, ospeed, cc = orig_attr

    cflag |= (termios.CLOCAL | termios.CREAD)
    lflag &= ~(termios.ICANON | termios.ECHO | termios.ECHOE |
    termios.ECHOK | termios.ECHONL |
    termios.ISIG | termios.IEXTEN) # |termios.ECHOPRT
    oflag &= ~(termios.OPOST | termios.ONLCR | termios.OCRNL)
    iflag &= ~(termios.INLCR | termios.IGNCR | termios.ICRNL | termios.IGNBRK)

    termios.tcsetattr(
    port,
    termios.TCSANOW,
    [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])


    def send_data(devname, filename):
    wrote = 0

    try:
    port = open(devname, 'w')
    bstream = open(filename, 'r')

    if platform.system() != "Windows":
    set_rawmode(port)

    while True:
    data = bstream.read(1024)
    if data == '' or len(data) == 0:
    break
    port.write(data)
    wrote += len(data)

    except Exception as e:
    print 'Error uploading bitstream'
    print e
    sys.exit(1)

    print 'Wrote %d bytes' % wrote


    if len(sys.argv) != 3:
    print 'Usage: %s serial_device bitstream_file' % sys.argv[0]
    sys.exit(1)

    send_data(sys.argv[1], sys.argv[2])