Skip to content

Commit b41d02a

Browse files
KillerLinkskinner33
authored andcommitted
Board Reset BugFix (#1)
Prevent a Bug that seems to be caused by re-configuration of the usb device. Manifestation of the bug is that (in the worst-case) only one download to the target can be performed. After that, the programmer is unresponsive and a reset of the programmer/target is required.
1 parent d154c9d commit b41d02a

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/CUSBCommunication.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ CUSBCommunication::CUSBCommunication(string device) : transfer(NULL), isoReceive
3333
libusb_device **deviceList;
3434
int busNr = 0;
3535
int deviceNr = 0;
36+
int currentConfig = -1;
3637

3738
// parse device string, should look like "bus:device"
3839
if (device.length() != 0) {
@@ -119,10 +120,22 @@ CUSBCommunication::CUSBCommunication(string device) : transfer(NULL), isoReceive
119120
throw USBCommunicationException("Device not found");
120121
}
121122

122-
// configure the device
123-
ret = libusb_set_configuration(dev, 1);
123+
// get current device configuration
124+
ret = libusb_get_configuration(dev, &currentConfig);
124125
if (ret != LIBUSB_SUCCESS) {
125-
throw USBCommunicationException("Setting Configuration failed");
126+
throw USBCommunicationException("Getting Configuration failed");
127+
}
128+
129+
// configure the device, if necessary
130+
if (currentConfig != USB_DEVICE_TARGET_CONFIGURATION) {
131+
COut::d("Updating USB configuration from "
132+
+ CFormat::intToString(currentConfig)
133+
+ " to "
134+
+ CFormat::intToString(USB_DEVICE_TARGET_CONFIGURATION));
135+
ret = libusb_set_configuration(dev, USB_DEVICE_TARGET_CONFIGURATION);
136+
if (ret != LIBUSB_SUCCESS) {
137+
throw USBCommunicationException("Setting Configuration failed");
138+
}
126139
}
127140

128141
// connect to interface 0

src/CUSBCommunication.h

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2525
#include "avrprog.h"
2626
#include "ExceptionBase.h"
2727

28+
#define USB_DEVICE_TARGET_CONFIGURATION (1)
29+
2830
using namespace std;
2931

3032
/**

0 commit comments

Comments
 (0)