Compare commits

..

25 Commits

Author SHA1 Message Date
Marius Greuel 91be527265 Add CMakeSettings.json for Visual Studio 2022 2022-02-20 18:17:10 +01:00
Marius Greuel 33bba04124 Update GitHub deploy action 2022-02-20 17:46:09 +01:00
Marius Greuel 231e42ca13 Update README.md 2022-02-20 17:41:49 +01:00
Marius Greuel 8692169f6d Add support for COM port discovery via USB VID/PID Add support for Leonardo USB bootloader auto-reset 2022-02-20 14:44:28 +01:00
Marius Greuel 0a452105f4 Correct endpoint direction for control messages of USBtinyISP devices 2022-02-20 14:44:28 +01:00
Marius Greuel b76c9522e7 Change Intel HEX line length from 32 to 16 to match line length of avr-objcopy 2022-02-20 14:44:28 +01:00
Marius Greuel 6d24d95594 Change program URL to github.com 2022-02-20 14:44:27 +01:00
Joerg Wunsch c7d1ebcf1f Issue #881 also fixed 2022-02-20 14:37:04 +01:00
Joerg Wunsch b891b7c64b Issue #874 is closed 2022-02-20 14:35:50 +01:00
Joerg Wunsch 428cd89e8d PRs #878, #873, #885 done 2022-02-19 21:54:23 +01:00
Jörg Wunsch 3efd3b2052
Merge pull request #873 from MCUdude/add-arduino-programmers
Add missing USBtiny derived programmers
2022-02-19 21:51:31 +01:00
Jörg Wunsch 7c65adba26
Merge pull request #885 from dbuchwald/simple_updi_fix
Smallest possible fix for PL2303HX
2022-02-19 21:50:41 +01:00
Dawid Buchwald 75ab3c418e Fixed warning with unsigned char 2022-02-19 21:18:03 +01:00
Dawid Buchwald de19f203e0 Smallest possible fix for PL2303HX 2022-02-19 15:07:32 +01:00
Jörg Wunsch d054c68b19
Merge pull request #878 from MCUdude/fix-pkob-target-voltage
Fix Curiosity Nano target voltage
2022-02-18 23:01:49 +01:00
Joerg Wunsch 5c90fbbaae PR #877 done 2022-02-18 22:53:45 +01:00
Jörg Wunsch c2fe68ef7d
Merge pull request #877 from MCUdude/jtag3-verbosity
Reduce jtag3 output verbosity
2022-02-18 22:38:40 +01:00
Joerg Wunsch c1ec836fbd PR #882 done 2022-02-18 21:37:27 +01:00
Jörg Wunsch ba01fd7e30
Merge pull request #882 from mariusgreuel/pr-libhid-cleanup-part1
Remove libhid support in ser_avrdoper.c in favor of libhidapi
2022-02-18 21:36:12 +01:00
Marius Greuel 59ecd4cc65 Remove libhid support in ser_avrdoper.c in favor of libhidapi 2022-02-18 20:05:52 +01:00
Marius Greuel e31be88ce0 Add LIB_LIBHID to CMake project to fix MinGW build issue 2022-02-18 19:58:13 +01:00
MCUdude 19e2cae053 Add Curiosity Nano to terminal list 2022-02-14 10:30:21 +01:00
MCUdude 932f68f24c Set target voltage even thoug not target is detected 2022-02-14 10:28:54 +01:00
MCUdude b1d34a510c Reduce jtag3 output verbosity 2022-02-13 19:23:48 +01:00
MCUdude f2bdcbe977 Add missing USBtiny derived programmers
ArduinoISP and the Arduino.org ISP are commercial versions of the USBtiny programmer with different USB VIDs/PIDs
2022-02-11 22:46:11 +01:00
10 changed files with 96 additions and 287 deletions

View File

@ -1,51 +0,0 @@
#
# build_extra.yml - GitHub build action for AVRDUDE
# Copyright (C) 2021 Marius Greuel
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
name: Build Extra
on:
push:
pull_request:
workflow_call:
env:
BUILD_TYPE: RelWithDebInfo
jobs:
freebsd-x86_64:
runs-on: macos-10.15
steps:
- uses: actions/checkout@v2
- name: Build
id: build
uses: vmactions/freebsd-vm@v0.1.5
with:
prepare: pkg install -y git cmake flex bison libftdi1 hidapi
run: |
cd src
cmake -D DEBUG_CMAKE=1 -D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -D CMAKE_C_FLAGS=-I/usr/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/local/lib -B ../build
cmake --build ../build
- name: Archive build artifacts
if: always()
uses: actions/upload-artifact@v2
with:
name: freebsd-x86_64
path: |
build/
!**/*.d
!**/*.o

View File

@ -25,7 +25,7 @@
},
{
"name": "x86-Release",
"generator": "Visual Studio 17 2022",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
@ -86,7 +86,7 @@
},
{
"name": "x64-Release",
"generator": "Visual Studio 17 2022 Win64",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",

7
NEWS
View File

@ -68,6 +68,8 @@ Changes since version 6.4:
- Segmentation fault when writing ATtiny104 fuse #823
- USBasp returns ERANGE for unknown error #848
- Compiler warnings #856
- Can't get serialupdi to work #874
- Rework HID support for Windows #881
* Pull requests:
@ -131,6 +133,11 @@ Changes since version 6.4:
- Add fuse name aliases to avrdude.conf + tweak update.c #869
- Print JTAG3 clocks after configuration + string formatting #853
- Tweak programmer info formatting strings #872
- Remove libhid support in ser_avrdoper.c in favor of libhidapi #882
- Reduce jtag3 output verbosity #877
- Fix Curiosity Nano target voltage #878
- Smallest possible fix for PL2303HX #885
- Add missing USBtiny derived programmers #873
* Internals:

View File

@ -853,11 +853,15 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
/* setup for WORD_WRITE */
avr_tpi_setup_rw(pgm, m, 0, TPI_NVMCMD_WORD_WRITE);
/* make sure it's aligned to a word boundary */
if (wsize & 0x1) {
wsize++;
}
/* write words, low byte first */
for (lastaddr = i = 0; i < wsize; i += 2) {
bool have_two_bytes = i + 1 < wsize;
if ((m->tags[i] & TAG_ALLOCATED) != 0 ||
(have_two_bytes && m->tags[i + 1] & TAG_ALLOCATED) != 0) {
(m->tags[i + 1] & TAG_ALLOCATED) != 0) {
if (lastaddr != i) {
/* need to setup new address */
@ -869,11 +873,8 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
cmd[1] = m->buf[i];
rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
if (have_two_bytes)
{
cmd[1] = m->buf[i + 1];
rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
}
cmd[1] = m->buf[i + 1];
rc = pgm->cmd_tpi(pgm, cmd, 2, NULL, 0);
lastaddr += 2;
@ -881,7 +882,7 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
}
report_progress(i, wsize, NULL);
}
return wsize;
return i;
}
if (pgm->paged_write != NULL && m->page_size > 1) {

View File

@ -886,6 +886,24 @@ programmer
usbpid = 0x0c9f;
;
programmer
id = "arduinoisp";
desc = "Arduino ISP Programmer";
type = "usbtiny";
connection_type = usb;
usbvid = 0x2341;
usbpid = 0x0049;
;
programmer
id = "arduinoisporg";
desc = "Arduino ISP Programmer";
type = "usbtiny";
connection_type = usb;
usbvid = 0x2A03;
usbpid = 0x0049;
;
# commercial version of USBtiny, using a separate VID/PID
programmer
id = "ehajo-isp";
@ -896,6 +914,16 @@ programmer
usbpid = 0x0BA5;
;
# commercial version of USBtiny, using a separate VID/PID
programmer
id = "iseavrprog";
desc = "USBtiny-based USB programmer, https://github.com/IowaScaledEngineering/ckt-avrprogrammer";
type = "usbtiny";
connection_type = usb;
usbvid = 0x1209;
usbpid = 0x6570;
;
programmer
id = "micronucleus";
desc = "Micronucleus Bootloader";
@ -914,16 +942,6 @@ programmer
usbpid = 0x0478;
;
# commercial version of USBtiny, using a separate VID/PID
programmer
id = "iseavrprog";
desc = "USBtiny-based USB programmer, https://github.com/IowaScaledEngineering/ckt-avrprogrammer";
type = "usbtiny";
connection_type = usb;
usbvid = 0x1209;
usbpid = 0x6570;
;
programmer
id = "butterfly";
desc = "Atmel Butterfly Development Board";

View File

@ -493,7 +493,7 @@ static int jtag3_edbg_send(PROGRAMMER * pgm, unsigned char * data, size_t len)
}
if (serial_send(&pgm->fd, buf, max_xfer) != 0) {
avrdude_message(MSG_INFO, "%s: jtag3_edbg_send(): failed to send command to serial port\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_send(): failed to send command to serial port\n",
progname);
return -1;
}
@ -509,7 +509,7 @@ static int jtag3_edbg_send(PROGRAMMER * pgm, unsigned char * data, size_t len)
(frag == nfragments - 1 && status[1] != 0x01))
{
/* what to do in this case? */
avrdude_message(MSG_INFO, "%s: jtag3_edbg_send(): Unexpected response 0x%02x, 0x%02x\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_send(): Unexpected response 0x%02x, 0x%02x\n",
progname, status[0], status[1]);
}
data += this_len;
@ -596,36 +596,36 @@ static int jtag3_edbg_signoff(PROGRAMMER * pgm)
buf[1] = CMSISDAP_LED_CONNECT;
buf[2] = 0;
if (serial_send(&pgm->fd, buf, pgm->fd.usb.max_xfer) != 0) {
avrdude_message(MSG_INFO, "%s: jtag3_edbg_signoff(): failed to send command to serial port\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_signoff(): failed to send command to serial port\n",
progname);
return -1;
}
rv = serial_recv(&pgm->fd, status, pgm->fd.usb.max_xfer);
if (rv != pgm->fd.usb.max_xfer) {
avrdude_message(MSG_INFO, "%s: jtag3_edbg_signoff(): failed to read from serial port (%d)\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_signoff(): failed to read from serial port (%d)\n",
progname, rv);
return -1;
}
if (status[0] != CMSISDAP_CMD_LED ||
status[1] != 0)
avrdude_message(MSG_INFO, "%s: jtag3_edbg_signoff(): unexpected response 0x%02x, 0x%02x\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_signoff(): unexpected response 0x%02x, 0x%02x\n",
progname, status[0], status[1]);
buf[0] = CMSISDAP_CMD_DISCONNECT;
if (serial_send(&pgm->fd, buf, pgm->fd.usb.max_xfer) != 0) {
avrdude_message(MSG_INFO, "%s: jtag3_edbg_signoff(): failed to send command to serial port\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_signoff(): failed to send command to serial port\n",
progname);
return -1;
}
rv = serial_recv(&pgm->fd, status, pgm->fd.usb.max_xfer);
if (rv != pgm->fd.usb.max_xfer) {
avrdude_message(MSG_INFO, "%s: jtag3_edbg_signoff(): failed to read from serial port (%d)\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_signoff(): failed to read from serial port (%d)\n",
progname, rv);
return -1;
}
if (status[0] != CMSISDAP_CMD_DISCONNECT ||
status[1] != 0)
avrdude_message(MSG_INFO, "%s: jtag3_edbg_signoff(): unexpected response 0x%02x, 0x%02x\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_signoff(): unexpected response 0x%02x, 0x%02x\n",
progname, status[0], status[1]);
return 0;
@ -686,12 +686,12 @@ static int jtag3_edbg_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
avrdude_message(MSG_TRACE, "%s: jtag3_edbg_recv():\n", progname);
if ((buf = malloc(USBDEV_MAX_XFER_3)) == NULL) {
avrdude_message(MSG_INFO, "%s: jtag3_edbg_recv(): out of memory\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_recv(): out of memory\n",
progname);
return -1;
}
if ((request = malloc(pgm->fd.usb.max_xfer)) == NULL) {
avrdude_message(MSG_INFO, "%s: jtag3_edbg_recv(): out of memory\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_recv(): out of memory\n",
progname);
free(buf);
return -1;
@ -706,7 +706,7 @@ static int jtag3_edbg_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
request[0] = EDBG_VENDOR_AVR_RSP;
if (serial_send(&pgm->fd, request, pgm->fd.usb.max_xfer) != 0) {
avrdude_message(MSG_INFO, "%s: jtag3_edbg_recv(): error sending CMSIS-DAP vendor command\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_recv(): error sending CMSIS-DAP vendor command\n",
progname);
free(request);
free(*msg);
@ -725,7 +725,7 @@ static int jtag3_edbg_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
}
if (buf[0] != EDBG_VENDOR_AVR_RSP) {
avrdude_message(MSG_INFO, "%s: jtag3_edbg_recv(): Unexpected response 0x%02x\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_recv(): Unexpected response 0x%02x\n",
progname, buf[0]);
free(*msg);
free(request);
@ -736,7 +736,7 @@ static int jtag3_edbg_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
// Documentation says:
// "FragmentInfo 0x00 indicates that no response data is
// available, and the rest of the packet is ignored."
avrdude_message(MSG_INFO,
avrdude_message(MSG_NOTICE,
"%s: jtag3_edbg_recv(): "
"No response available\n",
progname);
@ -752,7 +752,7 @@ static int jtag3_edbg_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
thisfrag = 1;
} else {
if (nfrags != (buf[1] & 0x0F)) {
avrdude_message(MSG_INFO,
avrdude_message(MSG_NOTICE,
"%s: jtag3_edbg_recv(): "
"Inconsistent # of fragments; had %d, now %d\n",
progname, nfrags, (buf[1] & 0x0F));
@ -762,7 +762,7 @@ static int jtag3_edbg_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
}
}
if (thisfrag != ((buf[1] >> 4) & 0x0F)) {
avrdude_message(MSG_INFO,
avrdude_message(MSG_NOTICE,
"%s: jtag3_edbg_recv(): "
"Inconsistent fragment number; expect %d, got %d\n",
progname, thisfrag, ((buf[1] >> 4) & 0x0F));
@ -773,12 +773,12 @@ static int jtag3_edbg_recv_frame(PROGRAMMER * pgm, unsigned char **msg) {
int thislen = (buf[2] << 8) | buf[3];
if (thislen > rv + 4) {
avrdude_message(MSG_INFO, "%s: jtag3_edbg_recv(): Unexpected length value (%d > %d)\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_recv(): Unexpected length value (%d > %d)\n",
progname, thislen, rv + 4);
thislen = rv + 4;
}
if (len + thislen > USBDEV_MAX_XFER_3) {
avrdude_message(MSG_INFO, "%s: jtag3_edbg_recv(): Length exceeds max size (%d > %d)\n",
avrdude_message(MSG_NOTICE, "%s: jtag3_edbg_recv(): Length exceeds max size (%d > %d)\n",
progname, len + thislen, USBDEV_MAX_XFER_3);
thislen = USBDEV_MAX_XFER_3 - len;
}
@ -865,7 +865,7 @@ int jtag3_recv(PROGRAMMER * pgm, unsigned char **msg) {
"%s: Device is locked! Chip erase required to unlock.\n",
progname);
} else {
avrdude_message(MSG_INFO, "%s: bad response to %s command: 0x%02x\n",
avrdude_message(MSG_NOTICE, "%s: bad response to %s command: 0x%02x\n",
progname, descr, c);
}
status = (*resp)[3];
@ -1351,13 +1351,14 @@ static int jtag3_initialize(PROGRAMMER * pgm, AVRPART * p)
if ((status = jtag3_command(pgm, cmd, 4, &resp, "AVR sign-on")) >= 0)
break;
avrdude_message(MSG_INFO, "%s: retrying with external reset applied\n",
avrdude_message(MSG_NOTICE, "%s: retrying with external reset applied\n",
progname);
}
if (use_ext_reset > 1) {
avrdude_message(MSG_INFO, "%s: JTAGEN fuse disabled?\n", progname);
return -1;
if(strcmp(pgm->type, "JTAGICE3") == 0 && p->flags & AVRPART_HAS_JTAG)
avrdude_message(MSG_INFO, "%s: JTAGEN fuse disabled?\n", progname);
return -1;
}
/*
@ -2240,7 +2241,7 @@ int jtag3_getparm(PROGRAMMER * pgm, unsigned char scope,
c = resp[1];
if (c != RSP3_DATA || status < 3) {
avrdude_message(MSG_INFO, "%s: jtag3_getparm(): "
avrdude_message(MSG_NOTICE, "%s: jtag3_getparm(): "
"bad response to %s\n",
progname, descr);
free(resp);
@ -2325,9 +2326,8 @@ static int jtag3_set_vtarget(PROGRAMMER * pgm, double v)
utarg = (unsigned)(v * 1000);
if (jtag3_getparm(pgm, SCOPE_GENERAL, 1, PARM3_VTARGET, buf, 2) < 0) {
avrdude_message(MSG_INFO, "%s: jtag3_set_vtarget(): cannot obtain V[aref]\n",
avrdude_message(MSG_INFO, "%s: jtag3_set_vtarget(): cannot obtain V[target]\n",
progname);
return -1;
}
uaref = b2_to_u16(buf);
@ -2336,8 +2336,11 @@ static int jtag3_set_vtarget(PROGRAMMER * pgm, double v)
avrdude_message(MSG_INFO, "%s: jtag3_set_vtarget(): changing V[target] from %.1f to %.1f\n",
progname, uaref / 1000.0, v);
if (jtag3_setparm(pgm, SCOPE_GENERAL, 1, PARM3_VADJUST, buf, sizeof(buf)) < 0)
if (jtag3_setparm(pgm, SCOPE_GENERAL, 1, PARM3_VADJUST, buf, sizeof(buf)) < 0) {
avrdude_message(MSG_INFO, "%s: jtag3_set_vtarget(): cannot confirm new V[target] value\n",
progname);
return -1;
}
return 0;
}
@ -2392,8 +2395,8 @@ static void jtag3_print_parms1(PROGRAMMER * pgm, const char * p)
if (jtag3_getparm(pgm, SCOPE_GENERAL, 1, PARM3_VTARGET, buf, 2) < 0)
return;
avrdude_message(MSG_INFO, "%sVtarget : %.2f V\n", p,
b2_to_u16(buf) / 1000.0);
avrdude_message(MSG_INFO, "%sVtarget %s: %.2f V\n", p,
verbose ? "" : " ", b2_to_u16(buf) / 1000.0);
if (jtag3_getparm(pgm, SCOPE_AVR, 1, PARM3_CLK_MEGA_PROG, buf, 2) < 0)
return;

View File

@ -26,11 +26,12 @@
#include "ac_cfg.h"
#if defined(HAVE_LIBHIDAPI) || (defined(WIN32) && defined(HAVE_LIBHID))
#if defined(HAVE_LIBHIDAPI)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <hidapi/hidapi.h>
#include "avrdude.h"
#include "libavrdude.h"
@ -64,12 +65,6 @@ static int avrdoperRxPosition = 0; /* amount of bytes already consu
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
#if defined(HAVE_LIBHIDAPI)
#include <hidapi/hidapi.h>
/* ------------------------------------------------------------------------- */
static int usbOpenDevice(union filedescriptor *fdp, int vendor, char *vendorName,
int product, char *productName, int doReportIDs)
{
@ -154,181 +149,6 @@ static int usbGetReport(union filedescriptor *fdp, int reportType, int reportNum
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
#else /* !defined(HAVE_LIBHIDAPI) */
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <setupapi.h>
#include <hidsdi.h>
#include <hidpi.h>
#ifdef USB_DEBUG
#define DEBUG_PRINT(arg) printf arg
#else
#define DEBUG_PRINT(arg)
#endif
/* ------------------------------------------------------------------------ */
static void convertUniToAscii(char *buffer)
{
unsigned short *uni = (void *)buffer;
char *ascii = buffer;
while(*uni != 0){
if(*uni >= 256){
*ascii++ = '?';
uni++;
}else{
*ascii++ = *uni++;
}
}
*ascii++ = 0;
}
static int usbOpenDevice(union filedescriptor *fdp, int vendor, char *vendorName,
int product, char *productName, int usesReportIDs)
{
GUID hidGuid; /* GUID for HID driver */
HDEVINFO deviceInfoList;
SP_DEVICE_INTERFACE_DATA deviceInfo;
SP_DEVICE_INTERFACE_DETAIL_DATA *deviceDetails = NULL;
DWORD size;
int i, openFlag = 0; /* may be FILE_FLAG_OVERLAPPED */
int errorCode = USB_ERROR_NOTFOUND;
HANDLE handle = INVALID_HANDLE_VALUE;
HIDD_ATTRIBUTES deviceAttributes;
HidD_GetHidGuid(&hidGuid);
deviceInfoList = SetupDiGetClassDevs(&hidGuid, NULL, NULL,
DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
deviceInfo.cbSize = sizeof(deviceInfo);
for(i=0;;i++){
if(handle != INVALID_HANDLE_VALUE){
CloseHandle(handle);
handle = INVALID_HANDLE_VALUE;
}
if(!SetupDiEnumDeviceInterfaces(deviceInfoList, 0, &hidGuid, i, &deviceInfo))
break; /* no more entries */
/* first do a dummy call just to determine the actual size required */
SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, NULL, 0, &size, NULL);
if(deviceDetails != NULL)
free(deviceDetails);
deviceDetails = malloc(size);
deviceDetails->cbSize = sizeof(*deviceDetails);
/* this call is for real: */
SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, deviceDetails,
size, &size, NULL);
DEBUG_PRINT(("checking HID path \"%s\"\n", deviceDetails->DevicePath));
/* attempt opening for R/W -- we don't care about devices which can't be accessed */
handle = CreateFile(deviceDetails->DevicePath, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
openFlag, NULL);
if(handle == INVALID_HANDLE_VALUE){
DEBUG_PRINT(("opening failed: %d\n", (int)GetLastError()));
/* errorCode = USB_ERROR_ACCESS; opening will always fail for mouse -- ignore */
continue;
}
deviceAttributes.Size = sizeof(deviceAttributes);
HidD_GetAttributes(handle, &deviceAttributes);
DEBUG_PRINT(("device attributes: vid=%d pid=%d\n",
deviceAttributes.VendorID, deviceAttributes.ProductID));
if(deviceAttributes.VendorID != vendor || deviceAttributes.ProductID != product)
continue; /* ignore this device */
errorCode = USB_ERROR_NOTFOUND;
if(vendorName != NULL && productName != NULL){
char buffer[512];
if(!HidD_GetManufacturerString(handle, buffer, sizeof(buffer))){
DEBUG_PRINT(("error obtaining vendor name\n"));
errorCode = USB_ERROR_IO;
continue;
}
convertUniToAscii(buffer);
DEBUG_PRINT(("vendorName = \"%s\"\n", buffer));
if(strcmp(vendorName, buffer) != 0)
continue;
if(!HidD_GetProductString(handle, buffer, sizeof(buffer))){
DEBUG_PRINT(("error obtaining product name\n"));
errorCode = USB_ERROR_IO;
continue;
}
convertUniToAscii(buffer);
DEBUG_PRINT(("productName = \"%s\"\n", buffer));
if(strcmp(productName, buffer) != 0)
continue;
}
break; /* we have found the device we are looking for! */
}
SetupDiDestroyDeviceInfoList(deviceInfoList);
if(deviceDetails != NULL)
free(deviceDetails);
if(handle != INVALID_HANDLE_VALUE){
fdp->pfd = (void *)handle;
errorCode = 0;
}
return errorCode;
}
/* ------------------------------------------------------------------------ */
static void usbCloseDevice(union filedescriptor *fdp)
{
CloseHandle((HANDLE)fdp->pfd);
}
/* ------------------------------------------------------------------------ */
static int usbSetReport(union filedescriptor *fdp, int reportType, char *buffer, int len)
{
HANDLE handle = (HANDLE)fdp->pfd;
BOOLEAN rval = 0;
DWORD bytesWritten;
switch(reportType){
case USB_HID_REPORT_TYPE_INPUT:
break;
case USB_HID_REPORT_TYPE_OUTPUT:
rval = WriteFile(handle, buffer, len, &bytesWritten, NULL);
break;
case USB_HID_REPORT_TYPE_FEATURE:
rval = HidD_SetFeature(handle, buffer, len);
break;
}
return rval == 0 ? USB_ERROR_IO : 0;
}
/* ------------------------------------------------------------------------ */
static int usbGetReport(union filedescriptor *fdp, int reportType, int reportNumber,
char *buffer, int *len)
{
HANDLE handle = (HANDLE)fdp->pfd;
BOOLEAN rval = 0;
DWORD bytesRead;
switch(reportType){
case USB_HID_REPORT_TYPE_INPUT:
buffer[0] = reportNumber;
rval = ReadFile(handle, buffer, *len, &bytesRead, NULL);
if(rval)
*len = bytesRead;
break;
case USB_HID_REPORT_TYPE_OUTPUT:
break;
case USB_HID_REPORT_TYPE_FEATURE:
buffer[0] = reportNumber;
rval = HidD_GetFeature(handle, buffer, *len);
break;
}
return rval == 0 ? USB_ERROR_IO : 0;
}
#endif /* WIN32 */
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
@ -551,4 +371,4 @@ struct serial_device avrdoper_serdev =
.flags = SERDEV_FL_NONE,
};
#endif /* defined(HAVE_LIBHIDAPI) || (defined(WIN32) && defined(HAVE_LIBHID)) */
#endif /* defined(HAVE_LIBHIDAPI) */

View File

@ -1613,11 +1613,11 @@ static int stk500v2_open(PROGRAMMER * pgm, char * port)
PDATA(pgm)->pgmtype = PGMTYPE_UNKNOWN;
if(strcasecmp(port, "avrdoper") == 0){
#if defined(HAVE_LIBHIDAPI) || (defined(WIN32) && defined(HAVE_LIBHID))
#if defined(HAVE_LIBHIDAPI)
serdev = &avrdoper_serdev;
PDATA(pgm)->pgmtype = PGMTYPE_STK500;
#else
avrdude_message(MSG_INFO, "avrdoper requires avrdude with hid support.\n");
avrdude_message(MSG_INFO, "avrdoper requires avrdude with libhidapi support.\n");
return -1;
#endif
}

View File

@ -97,8 +97,8 @@ struct command cmd[] = {
{ "sig", cmd_sig, "display device signature bytes" },
{ "part", cmd_part, "display the current part information" },
{ "send", cmd_send, "send a raw command : %s <b1> <b2> <b3> <b4>" },
{ "parms", cmd_parms, "display adjustable parameters (STK500 only)" },
{ "vtarg", cmd_vtarg, "set <V[target]> (STK500 only)" },
{ "parms", cmd_parms, "display adjustable parameters (STK500 and Curiosity Nano only)" },
{ "vtarg", cmd_vtarg, "set <V[target]> (STK500 and Curiosity Nano only)" },
{ "varef", cmd_varef, "set <V[aref]> (STK500 only)" },
{ "fosc", cmd_fosc, "set <oscillator frequency> (STK500 only)" },
{ "sck", cmd_sck, "set <SCK period> (STK500 only)" },

View File

@ -53,7 +53,7 @@ static void updi_set_rtsdtr_mode(PROGRAMMER* pgm)
static int updi_physical_open(PROGRAMMER* pgm, int baudrate, unsigned long cflags)
{
serial_recv_timeout = 100;
serial_recv_timeout = 1000;
union pinfo pinfo;
pinfo.serialinfo.baud = baudrate;
@ -155,12 +155,19 @@ static int updi_physical_send_double_break(PROGRAMMER * pgm)
serial_send(&pgm->fd, buffer, 1);
serial_recv(&pgm->fd, buffer, 1);
serial_drain(&pgm->fd, 0);
if (serial_setparams(&pgm->fd, pgm->baudrate? pgm->baudrate: 115200, SERIAL_8E2) < 0) {
return -1;
}
updi_set_rtsdtr_mode(pgm);
/*
* drain any extraneous input
*/
serial_drain(&pgm->fd, 0);
return 0;
}
@ -191,10 +198,14 @@ int updi_physical_sib(PROGRAMMER * pgm, unsigned char * buffer, uint8_t size)
int updi_link_open(PROGRAMMER * pgm)
{
unsigned char init_buffer[1];
if (updi_physical_open(pgm, pgm->baudrate? pgm->baudrate: 115200, SERIAL_8E2) < 0) {
return -1;
}
return updi_physical_send_double_break(pgm);
init_buffer[0]=UPDI_BREAK;
return updi_physical_send(pgm, init_buffer, 1);
}
void updi_link_close(PROGRAMMER * pgm)