Arduino
Arduino copied to clipboard
Extending communication timeouts
NOTE: I'm posting an issue in this repository because https://github.com/arduino/BOSSA does not allow to report issues and the bossac
tool is directly used by Arduino IDE.
We are working on an integration of Arduino IDE and an external simulator (Renode, www.renode.io) and noticed SAM-BA operation failed
errors when loading a binary on Linux using bossac
.
In order to make the experience of using our simulator as close as possible to the actual hardware, we are exposing it as a USB device using the USB/IP stack and pretending that we are an Arduino board (Arduino Nano 33 BLE Sense to be exact). This way it's visible in the system as a physical USB device and the IDE can interact with it without even knowing it's a simulator.
Unfortunately we are noticing problems when handling bootloader commands that seem to be related to timeouts. On some systems loading fails with the following output:
Set binary mode
version()=Arduino Bootloader (SAM-BA extended) 2.0 [Arduino:IKXYZ]
Connected at 921600 baud
identifyChip()=nRF52840-QIAA
write(addr=0,size=0x34)
writeWord(addr=0x30,value=0x400)
writeWord(addr=0x20,value=0)
version()=Arduino Bootloader (SAM-BA extended) 2.0 [Arduino:IKXYZ]
Device : nRF52840-QIAA
Version : Arduino Bootloader (SAM-BA extended) 2.0 [Arduino:IKXYZ]
Address : 0x0
Pages : 256
Page Size : 4096 bytes
Total Size : 1024KB
Planes : 1
Lock Regions : 0
Locked : none
Security : false
Erase flash
chipErase(addr=0)
Done in 0.052 seconds
Write 227784 bytes to flash (56 pages)
[ ] 0% (0/56 pages)write(addr=0x34,size=0x1000)
writeBuffer(scr_addr=0x34, dst_addr=0, size=0x1000)
SAM-BA operation failed
After inspecting the code we were able to narrow this down to the TIMEOUT_QUICK
in https://github.com/arduino/BOSSA/blob/nrf/src/Samba.cpp#L660 (more details described in https://github.com/renode/renode/issues/208#issuecomment-834676037).
In short - extending timeouts solved the issued and allowed for successful upload of binaries to the virtual device over USB/IP connection.
I was wondering - what is the reason for having both TIMEOUT_NORMAL
and TIMEOUT_QUICK
and would it be a problem to use TIMEOUT_NORMAL
everywhere? This would allow for more reliable communication with virtual devices and USB over IP connections on Linux.
I can prepare a PR with proposed changes, but wanted to discuss the matter first.