arduino / arduino/Arduino

Extending communication timeouts

Open
#11,689 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
14.6k
Forks
7k
PR merge metrics
No merged PRs in 30d

Description

---

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.

Contributor guide

Open the contributing guide

Research direction

Start by reading nrf/src/Samba.cpp around line 660, where TIMEOUT_QUICK is used, and compare it with TIMEOUT_NORMAL. Reproduce the SAM-BA failure while uploading through the Renode USB/IP setup described in the issue; done means reliable binary uploads without the operation failing.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.