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

Fix flashing with muliple dediprogs #87

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 10 additions & 25 deletions dpcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,27 +546,6 @@ int main(int argc, char* argv[])
g_usb_busnum = (unsigned char)r;
}

// Filter by DP Device num, same as setting --device flag
// Only touches target device since it is before OpenUSB()
env = getenv("DPCMD_DEVNUM");
if (env) {
r = strtoul(env, NULL, 10);
if (r == ULONG_MAX || r >= 256) {
fprintf(stderr, "E: invalid device number in"
" DPCMD_DEVNUM\n");
return 1;
}
g_uiDevNum = (unsigned char)r;
bDevice = true;
}


if (OpenUSB() == 0)
iExitCode = EXCODE_FAIL_USB;

LeaveStandaloneMode(0);
QueryBoard(0);

while ((c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (c) {
case '?':
Expand Down Expand Up @@ -752,6 +731,12 @@ int main(int argc, char* argv[])
}
}

if (OpenUSB() == 0)
iExitCode = EXCODE_FAIL_USB;

LeaveStandaloneMode(0);
QueryBoard(0);

int dev_cnt = get_usb_dev_cnt();

if (CheckProgrammerInfo()) {
Expand Down Expand Up @@ -1113,7 +1098,8 @@ void sin_handler(int sig)

int Handler(void)
{
if (Is_usbworking(0) == true) {
//if (Is_usbworking(0) == true) {
if (Is_usbworking(g_uiDevNum - 1) == true) {
#if 0
if(m_vm.count("fix-device"))
{
Expand All @@ -1123,7 +1109,6 @@ int Handler(void)

AssignedDevice();
#endif

if ((g_ucOperation & BLINK) == BLINK) {
BlinkProgrammer();
return EXCODE_PASS;
Expand Down Expand Up @@ -1173,7 +1158,7 @@ bool InitProject(void)
{
//printf("bool InitProject(void)\n");
int dev_cnt = get_usb_dev_cnt();
if (Is_usbworking(0)) {
if (Is_usbworking(g_uiDevNum-1)) {
int targets[4] = {
STARTUP_APPLI_CARD,
STARTUP_APPLI_SF_1,
Expand Down Expand Up @@ -1246,7 +1231,7 @@ void CloseProject(void)
bool DetectChip(void)
{
int dev_cnt = get_usb_dev_cnt();
Chip_Info = GetFirstDetectionMatch(strTypeName, 0);
Chip_Info = GetFirstDetectionMatch(strTypeName, g_uiDevNum-1);
if (g_uiDevNum == 0) {
for (int i = 0; i < dev_cnt; i++) {
if (!Is_usbworking(i)) {
Expand Down