Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tinyprog crashes when running apio upload #75

Open
rej696 opened this issue Aug 11, 2024 · 0 comments
Open

tinyprog crashes when running apio upload #75

rej696 opened this issue Aug 11, 2024 · 0 comments

Comments

@rej696
Copy link

rej696 commented Aug 11, 2024

tinyprog is crashing when running apio upload command:

(venv) [tinyfpga-vhdl/clock_div4] (main) $ apio upload
Info: use custom SConstruct file
[Sun Aug 11 17:31:31 2024] Processing TinyFPGA-BX
---------------------------------------------------------------------------------------------------------------------------------------------------
tinyprog --pyserial -c /dev/ttyACM0 --program hardware.bin

TinyProg CLI
------------
Using device id 1d50:6130
Programming /dev/ttyACM0 with hardware.bin
Programming at addr 028000
Waking up SPI flash
135100 bytes to program
Erasing:   0%|          | 0.00/135k [00:00<?, ?B/s]
Erasing:   0%|          | 0.00/135k [00:01<?, ?B/s]
Traceback (most recent call last):
File "/home/rowan/workspace/vhdl/venv/lib/python3.12/site-packages/tinyprog/__init__.py", line 19, in to_int
return ord(value)
^^^^^^^^^^
TypeError: ord() expected a character, but string of length 0 found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/rowan/workspace/vhdl/venv/bin/tinyprog", line 8, in <module>
sys.exit(main())
^^^^^^
File "/home/rowan/workspace/vhdl/venv/lib/python3.12/site-packages/tinyprog/__main__.py", line 346, in main
if not fpga.program_bitstream(addr, bitstream):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rowan/workspace/vhdl/venv/lib/python3.12/site-packages/tinyprog/__init__.py", line 419, in program_bitstream
return self.program(addr, bitstream)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rowan/workspace/vhdl/venv/lib/python3.12/site-packages/tinyprog/__init__.py", line 375, in program
self.erase(addr, len(data), disable_progress=False)
File "/home/rowan/workspace/vhdl/venv/lib/python3.12/site-packages/tinyprog/__init__.py", line 347, in erase
self._erase(addr, erase_length)
File "/home/rowan/workspace/vhdl/venv/lib/python3.12/site-packages/tinyprog/__init__.py", line 301, in _erase
self.wait_while_busy()
File "/home/rowan/workspace/vhdl/venv/lib/python3.12/site-packages/tinyprog/__init__.py", line 290, in wait_while_busy
while to_int(self.read_sts()) & 1:
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rowan/workspace/vhdl/venv/lib/python3.12/site-packages/tinyprog/__init__.py", line 21, in to_int
return int(value)
^^^^^^^^^^
ValueError: invalid literal for int() with base 10: b''
scons: *** [upload] Error 1
=========================================================== [ ERROR ] Took 1.38 seconds ===========================================================

I debugged the error, and found that the issue was calling to_int on the result of self.read_sts() in the wait_while_busy() method. I was able to resolve this so I could program my board by modifying the to_int function to catch the ValueError raised when int is called on an empty bytes object, and return 0 in that case. I.e.:

def to_int(value):
    try:
        try:
            return ord(value)
        except:
            return int(value)
    except:
        return 0

I am guessing this is something to do with a change in pyserial? maybe older versions didn't return empty bytes object when nothing was read?

I am using apio on linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant