Skip to content

Commit

Permalink
Merge pull request FPGAwars#156 from tinyfpga/support-tinyfpga-bx
Browse files Browse the repository at this point in the history
Support tinyfpga bx
  • Loading branch information
Jesus89 authored Jun 2, 2018
2 parents e330648 + 246b1ce commit 629b9ed
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*.blif
*.eggs
*.egg-info
*.swp
*~
.coverage
.tox/
.cache/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Apio is used by [Icestudio](https://github.com/FPGAwars/icestudio).
| Board name | Interface |
|:-|:-:|
| [TinyFPGA B2](http://tinyfpga.com/b-series-guide.html) | Serial |
| [TinyFPGA BX](http://tinyfpga.com/b-series-guide.html) | Serial |

#### UP5K

Expand Down
26 changes: 19 additions & 7 deletions apio/managers/scons.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def _check_serial(self, board_data, ext_serial_port):
raise Exception('Missing board configuration: usb')

usb_data = board_data.get('usb')
desc_pattern = '^' + (usb_data.get('desc') or '.*') + '$'
hwid = '{0}:{1}'.format(
usb_data.get('vid'),
usb_data.get('pid')
Expand All @@ -233,14 +232,28 @@ def _check_serial(self, board_data, ext_serial_port):
port = serial_port_data.get('port')
if ext_serial_port and ext_serial_port != port:
# If the --device options is set but it doesn't match
# with the detected port, skip the port.
# the detected port, skip the port.
continue
if hwid in serial_port_data.get('hwid') and \
re.match(desc_pattern, serial_port_data.get('description')):
if hwid.lower() in serial_port_data.get('hwid').lower():
if 'tinyprog' in board_data:
# If the board uses tinyprog use its port detection
# to double check the detected port.
if not self._check_tinyprog(board_data, port):
# If the port is not detected, skip the port.
continue
# If the hwid and the description pattern matches
# return the device for the port.
# with the detected port return the port.
return port

def _check_tinyprog(self, board_data, port):
desc_pattern = '^' + board_data.get('tinyprog').get('desc') + '$'
for tinyprog_meta in util.get_tinyprog_meta():
tinyprog_port = tinyprog_meta.get('port')
tinyprog_name = tinyprog_meta.get('boardmeta').get('name')
if port == tinyprog_port and re.match(desc_pattern, tinyprog_name):
# If the port is detected and it matches the pattern
return True

def get_ftdi_id(self, board, board_data, ext_ftdi_id):
# Search device by FTDI id
ftdi_id = self._check_ftdi(board_data, ext_ftdi_id)
Expand All @@ -253,8 +266,7 @@ def _check_ftdi(self, board_data, ext_ftdi_id):
if 'ftdi' not in board_data:
raise Exception('Missing board configuration: ftdi')

ftdi_data = board_data.get('ftdi')
desc_pattern = '^' + ftdi_data.get('desc') + '$'
desc_pattern = '^' + board_data.get('ftdi').get('desc') + '$'

# Match the discovered FTDI chips
for ftdi_device in System().get_ftdi_devices():
Expand Down
2 changes: 2 additions & 0 deletions apio/resources/80-fpga-serial.rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", ENV{ID_MM_DEVICE_IGNORE}="1"
# Disable ModemManager for TinyFPGA B2
ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2100", ENV{ID_MM_DEVICE_IGNORE}="1"
# Disable ModemManager for TinyFPGA BX
ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="6130", ENV{ID_MM_DEVICE_IGNORE}="1"
14 changes: 14 additions & 0 deletions apio/resources/boards.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@
"pid": "2100"
}
},
"TinyFPGA-BX": {
"name": "TinyFPGA BX",
"fpga": "iCE40-LP8K-CM81",
"programmer": {
"type": "tinyprog"
},
"usb": {
"vid": "1d50",
"pid": "6130"
},
"tinyprog": {
"desc": "TinyFPGA BX"
}
},
"alhambra-ii": {
"name": "Alhambra II",
"fpga": "iCE40-HX4K-TQ144",
Expand Down
3 changes: 2 additions & 1 deletion apio/resources/distribution.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"pip_packages": {
"blackiceprog": ">=2.0.0,<3.0.0",
"litterbox": ">=0.2.1,<0.3.0",
"tinyfpgab": ">=1.1.0,<1.2.0"
"tinyfpgab": ">=1.1.0,<1.2.0",
"tinyprog": ">=1.0.0,<1.1.0"
}
}
5 changes: 5 additions & 0 deletions apio/resources/programmers.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
"command": "tinyfpgab",
"args": "-c ${SERIAL_PORT} --program",
"pip_packages": [ "tinyfpgab" ]
},
"tinyprog": {
"command": "tinyprog",
"args": "-c ${SERIAL_PORT} --program",
"pip_packages": [ "tinyprog" ]
}
}
8 changes: 8 additions & 0 deletions apio/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,5 +438,13 @@ def get_serial_ports():
return result


def get_tinyprog_meta():
result = exec_command(['tinyprog', '-m'])
if result:
return json.loads(result.get('out'))
else:
return []


def get_python_version():
return '{0}.{1}'.format(sys.version_info[0], sys.version_info[1])

0 comments on commit 629b9ed

Please sign in to comment.