Programmer for B2 Dodgy


#1

Hello,
I just got my B2 board and I am super excited about it. However, something is seriously killing my work flow and that is uploading my bitstream. I have used both the command line and the python GUI programmer from git-hub and I have the same problems.

  1. The most concerning problem is sometimes, randomly the programmer software will spit out this error:

TinyFPGA B-series Programmer CLI
--------------------------------
Programming /dev/ttyACM0 with TinyFPGA_B.bin
Waking up SPI flash
135100 bytes to program
Erasing designated flash pages
Traceback (most recent call last):
File “tinyfpgab.py”, line 314, in
fpga.program_bitstream(addr, bitstream)
File “tinyfpgab.py”, line 249, in program_bitstream
if self.program(addr, bitstream):
File “tinyfpgab.py”, line 207, in program
self.erase(addr, len(data))
File “tinyfpgab.py”, line 165, in erase
self._erase(current_addr, erase_length)
File “tinyfpgab.py”, line 115, in _erase
self.wait_while_busy()
File “tinyfpgab.py”, line 96, in wait_while_busy
while (self.read_sts()[0] & 1):
IndexError: list index out of range

It erases the memory on the chip and fails to write the new bitstream which is pretty annoying. Thankfully the bootloader stays intact.

  1. Randomly, I’ll get an error that says the device is busy and I have to remove and plug in the device to clear it.

Has anybody else seen these errors?


A-Series Quick Troubleshooting Checklist
#2

I have the same problems. I have to repeatedly retry uploading to the B2 and eventually it goes through. This is the exact same exception I have.

It is said in the documentation somewhere to try with a good USB cable. This is the only thing I have not done that I feel I should do before starting to debug the Python uploader.


#3

@ssamuelcomeau, @fdgonthier: What OS and version of the programmer are you using? Are you using a hub or plugging directly into your computer?


#4

Also, thanks for reporting your issues, I really want to encourage everyone to report bugs in the programmer software if they encounter it. Just make sure you have installed the latest version. USB is a wide and varied ecosystem, there are many host controllers, OS drivers, hubs, and cables that can cause interesting bugs.

If you do encounter an error, the following information is useful for me to reproduce the issue:

  1. Programmer release version
  2. OS name and version
  3. Host controller (chipset name, or external usb host controller name)
  4. Any hubs you might be using that cause a problem
  5. Any error messages you see. Either a screenshot or cut and paste the text works for me.

Reporting these issues gives me the opportunity to fix them and make both the programmer and bootloader more robust. These fixes are then fed back into the open-source community for anyone else to take advantage of.

There is an arduino sketch to update your board to a new bootloader. If there are any bug fixes for the bootloader that will allow you update to the latest version.


#5
  1. The programmer version was downloaded on 28 Oct at 22:55.
  2. I am using Kali Linux v4.13.0 on an Asus laptop.
  3. My laptop has 3 internal usb hubs. I noticed the problem on USB 2.0, but I will try it on USB 3.0.
  4. I get the error both on a high quality usb hub and directly connected to my computer. I have not tried updating the bootloader, but I will try that next.

#6
  1. There were several commits made on that day, it would be worthwhile to do another pull to make sure you have everything.
  2. Which version of the linux kernel does Kali Linux use? Is it based off of Redhat or Debian? Is it an Intel CPU and chipset, or AMD CPU and chipset? Can you send me the output of lspci?
  3. Would be good to know if there is a difference in behavior depending on which port it is plugged into.
  4. Don’t worry about updating the bootloader, there isn’t a new version out just yet. However, I am working on a new testbench for the bootloader to clean up some outstanding issues and make it more reusable. There’s a good chance any bugs we find will end up with fixes in the bootloader as well as workarounds in the programmer for boards that don’t have the latest bootloader.

Thanks!


#7
  1. Fresh download, error message:
TinyFPGA B-series Programmer CLI -------------------------------- Using device id 1209:2100 Only one board with active bootloader, using it. Programming /dev/ttyACM0 with TinyFPGA_B.bin Programming at addr 030000 Waking up SPI flash 135100 bytes to program Erasing designated flash pages Writing bitstream Traceback (most recent call last): File "tinyfpgab.py", line 299, in if not fpga.program_bitstream(addr, bitstream): File "tinyfpgab.py", line 204, in program_bitstream if self.program(addr, bitstream): File "tinyfpgab.py", line 163, in program self.write(addr, data) File "tinyfpgab.py", line 154, in write self._write(addr, data[:write_length]) File "tinyfpgab.py", line 147, in _write self.wait_while_busy() File "tinyfpgab.py", line 70, in wait_while_busy while ord(self.read_sts()) & 1: TypeError: ord() expected a character, but string of length 0 found
  1. I believe it is Debian based. I have an AMD 64 chipset.

    00:00.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 15h (Models 30h-3fh) Processor Root Complex
    00:01.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Kaveri [Radeon R6 Graphics]
    00:01.1 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] Kaveri HDMI/DP Audio Controller
    00:02.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1424
    00:03.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1424
    00:04.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1424
    00:10.0 USB controller: Advanced Micro Devices, Inc. [AMD] FCH USB XHCI Controller (rev 09)
    00:11.0 SATA controller: Advanced Micro Devices, Inc. [AMD] FCH SATA Controller [AHCI mode] (rev 40)
    00:12.0 USB controller: Advanced Micro Devices, Inc. [AMD] FCH USB OHCI Controller (rev 11)
    00:12.2 USB controller: Advanced Micro Devices, Inc. [AMD] FCH USB EHCI Controller (rev 11)
    00:13.0 USB controller: Advanced Micro Devices, Inc. [AMD] FCH USB OHCI Controller (rev 11)
    00:13.2 USB controller: Advanced Micro Devices, Inc. [AMD] FCH USB EHCI Controller (rev 11)
    00:14.0 SMBus: Advanced Micro Devices, Inc. [AMD] FCH SMBus Controller (rev 16)
    00:14.2 Audio device: Advanced Micro Devices, Inc. [AMD] FCH Azalia Controller (rev 01)
    00:14.3 ISA bridge: Advanced Micro Devices, Inc. [AMD] FCH LPC Bridge (rev 11)
    00:14.4 PCI bridge: Advanced Micro Devices, Inc. [AMD] FCH PCI Bridge (rev 40)
    00:14.7 SD Host controller: Advanced Micro Devices, Inc. [AMD] FCH SD Flash Controller
    00:15.0 PCI bridge: Advanced Micro Devices, Inc. [AMD] Hudson PCI to PCI bridge (PCIE port 0)
    00:15.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Hudson PCI to PCI bridge (PCIE port 1)
    00:15.2 PCI bridge: Advanced Micro Devices, Inc. [AMD] Hudson PCI to PCI bridge (PCIE port 2)
    00:18.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 15h (Models 30h-3fh) Processor Function 0
    00:18.1 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 15h (Models 30h-3fh) Processor Function 1
    00:18.2 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 15h (Models 30h-3fh) Processor Function 2
    00:18.3 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 15h (Models 30h-3fh) Processor Function 3
    00:18.4 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 15h (Models 30h-3fh) Processor Function 4
    00:18.5 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 15h (Models 30h-3fh) Processor Function 5
    03:00.0 Network controller: Qualcomm Atheros AR9485 Wireless Network Adapter (rev 01)
    04:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 0c)
  2. Using USB 2.0 or 3.0 makes no difference.

#8

Great, this gives me a baseline to work with. I’ll take a close look at that exception and see if there’s something we can try.


#9

Hello everyone,

I’m trying to give it a shot.

Could you try to use this modified CLI and report your results ?
https://raw.githubusercontent.com/Rogdham/TinyFPGA-B-Series/programmer-timeout/programmer/tinyfpgab.py


#10

Ohh my gosh @Rogdham, I can’t believe you beat me to it! I’ll have to chalk this up to the timezone difference :laughing:

BTW, can you point me to the change you are trying out here?


#11

Ok, let me see if I can break it.


#12

I am disabling the timeout after is_bootloader_active is successful: in that case the reads will never timeout, so that exception should not occur https://github.com/Rogdham/TinyFPGA-B-Series/commit/1915d1339f2c1476f840a91d0a9b3c42c86345cd


#13

Gotchya, was going after the same thing. I was thinking a SerialTimeoutException should be thrown for a read timeout, but it turns out that’s only for write timeouts.

200 ms is a very long time already to be waiting for the read response, but it’s possible the Linux USB stack is doing something very different from Windows and MacOS to cause this latency.


#14

On that note, I don’t know if you have actually fixed the problem. It seems that the programmer just hangs while somehow spitting out a continuous stream of data on the USB. Sometimes it hangs in the erasing routine and sometimes in the writing routine. I think it is an overall improvement, however.
For instance, my current write attempt is over 4min and there is still data streaming over USB.


#15

I guess it makes some sense… in that case it may be not fixable on the programmer side, but would need a bootloader fix? I let @lukevalenty share his thoughts on the topic


#16

Ohh man, that’s just too long. How do you know there is data streaming over USB? Do you have some sort of USB data capture setup? If you do, I would love to see what you are capturing. I have a USB protocol analyzer that connects to the USB data lines for my own debugging purposes.


#17

Without detailed USB traces, I think a workaround would be to wait the maximum amount of time the corresponding operation takes according to the SPI datasheet. It’s not optimal, but it would avoid this issue. Could be via command-line switch or potentially by automatic detection.


#18

I’ve got a logic analyzer hooked up, but it doesn’t do a good job of capturing packets only of showing there is something there. Let me see what I can yank. It seems to be repeating the same sequence over and over again.


#19

Sample at 48MHz or 50MHz if you can. What kind of logic analyzer is it? Can it decode the USB protocol?
Does it work with sigrock and Pulseview (https://sigrok.org/wiki/PulseView)?


#20

It’s a MSO-19 mixed signal usb scope. It doesn’t work with sigrok. It doesn’t decode USB. I can give a CSV, but thats about it.