avrdudes / avrdude

AVRDUDE is a utility to program AVR microcontrollers
GNU General Public License v2.0
734 stars 136 forks source link

PICKit 2: MSVC build of avrdude Windows binary does not work #1006

Closed mcuee closed 1 year ago

mcuee commented 2 years ago

Somehow the official avrdude-7.0 Windows binary release and the github action Windows MSVC build do not work with PICKit 2.

C:\work\avr\binary\avrdude-msvc-x64> .\avrdude.exe -p m328p -c pickit2 -P usb -vvvv
executable_abspath = C:/work/avr/binary/avrdude-msvc-x64/avrdude.exe
executable_abspath_len = 47
executable_dirpath = C:/work/avr/binary/avrdude-msvc-x64
executable_dirpath_len = 35
sys_config = C:/work/avr/binary/avrdude-msvc-x64/avrdude.conf
sys_config_found = true

avrdude.exe: Version 7.0-20220619 (1aa59aa)
             Copyright (c) Brian Dean, http://www.bdmicro.com/
             Copyright (c) Joerg Wunsch

             System wide configuration file is "C:/work/avr/binary/avrdude-msvc-x64/avrdude.conf"

             Using Port                    : usb
             Using Programmer              : pickit2
avrdude.exe: error: could not find PICkit2 with vid=0x4d8 pid=0x33
avrdude.exe: opening programmer "pickit2" on port "usb" failed

avrdude.exe done.  Thank you.

MSYS2 build has no issues.

C:\work\avr\binary\avrdude-mingw-x86_64>  .\avrdude.exe -p m328p -c pickit2

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude.exe: Device signature = 0x1e950f (probably m328p)

avrdude.exe done.  Thank you.
mcuee commented 2 years ago

BTW, there is no issue with avrdude msvc CMake related files. I just built avrdude using VS2022 from the source using the instructions mentioned in the Wiki and the binary is okay. Ref: https://github.com/avrdudes/avrdude/wiki/Building-AVRDUDE-for-Windows-using-Visual-Studio

So somehow the github action build is the problem.

Reference: CMake configure output from my VS2022 build

1> CMake generation started for configuration: 'x64'.
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Release" -DCMAKE_INSTALL_PREFIX:PATH="C:\work\avr\avrdude\out\install\x64" -DUSE_EXTERNAL:BOOL="True" -DBUILD_SHARED_LIBS:BOOL="False" -DHAVE_LIBELF:FILEPATH="" -DHAVE_LIBUSB_1_0:FILEPATH="" -DDEBUG_CMAKE:BOOL="True" -DCMAKE_VERBOSE_MAKEFILE:BOOL="True" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\work\avr\avrdude" 2>&1"
1> Working directory: C:\work\avr\avrdude\out\build\x64
1> [CMake] -- Fetching external libraries, please wait...
1> [CMake] -- Using external library 'libelf'
1> [CMake] -- Using external library 'libusb'
1> [CMake] -- Using external library 'libhidapi'
1> [CMake] -- Using external library 'libftdi'
1> [CMake] -- Configuration summary:
1> [CMake] -- ----------------------
1> [CMake] -- CMAKE_HOST_SYSTEM: Windows-10.0.22000
1> [CMake] -- CMAKE_SYSTEM: Windows-10.0.22000
1> [CMake] -- CMAKE_FIND_ROOT_PATH: 
1> [CMake] -- CMAKE_C_COMPILER: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe
1> [CMake] -- CONFIG_DIR: C:/work/avr/avrdude/out/install/x64/etc
1> [CMake] -- AVRDUDE_FULL_VERSION: 7.0-20220619 (1aa59aa)
1> [CMake] -- USE_EXTERNAL: True
1> [CMake] -- USE_LIBUSBWIN32: OFF
1> [CMake] -- HAVE_LIBELF: 1
1> [CMake] -- HAVE_LIBUSB: 1
1> [CMake] -- HAVE_LIBUSB_1_0: 
1> [CMake] -- HAVE_LIBUSB_WIN32: HAVE_LIBUSB_WIN32-NOTFOUND
1> [CMake] -- HAVE_LIBHID: C:/Program Files (x86)/Windows Kits/10/Lib/10.0.22000.0/um/x64/hid.lib
1> [CMake] -- HAVE_LIBHIDAPI: 1
1> [CMake] -- HAVE_LIBFTDI: 1
1> [CMake] -- HAVE_LIBFTDI1: HAVE_LIBFTDI1-NOTFOUND
1> [CMake] -- HAVE_LIBREADLINE: HAVE_LIBREADLINE-NOTFOUND
1> [CMake] -- HAVE_LIBELF_H: 1
1> [CMake] -- HAVE_LIBELF_LIBELF_H: 
1> [CMake] -- HAVE_USB_H: 
1> [CMake] -- HAVE_LUSB0_USB_H: 1
1> [CMake] -- HAVE_LIBUSB_H: 
1> [CMake] -- HAVE_LIBUSB_1_0_LIBUSB_H: 
1> [CMake] -- HAVE_HIDAPI_HIDAPI_H: 1
1> [CMake] -- LIBUSB_COMPAT_DIR: 
1> [CMake] -- ----------------------
1> [CMake] -- DO HAVE    libelf
1> [CMake] -- DO HAVE    libusb
1> [CMake] -- DON'T HAVE libusb_1_0
1> [CMake] -- DO HAVE    libhidapi
1> [CMake] -- DO HAVE    libftdi
1> [CMake] -- DON'T HAVE libftdi1
1> [CMake] -- DISABLED   doc
1> [CMake] -- DISABLED   parport
1> [CMake] -- DISABLED   linuxgpio
1> [CMake] -- DISABLED   linuxspi
1> [CMake] -- ----------------------
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] -- Build files have been written to: C:/work/avr/avrdude/out/build/x64
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted toolchain configurations.
1> Extracted includes paths.
1> CMake generation finished.
mcuee commented 2 years ago

If I looked at github action MSVC build, somehow it does not detect libhid.

Ref: https://github.com/avrdudes/avrdude/runs/7188141729?check_suite_focus=true#step:4:43

-- USE_EXTERNAL: 1
-- USE_LIBUSBWIN32: OFF
-- HAVE_LIBELF: 1
-- HAVE_LIBUSB: 1
-- HAVE_LIBUSB_1_0: HAVE_LIBUSB_1_0-NOTFOUND
-- HAVE_LIBUSB_WIN32: HAVE_LIBUSB_WIN32-NOTFOUND
-- HAVE_LIBHID: HAVE_LIBHID-NOTFOUND
-- HAVE_LIBHIDAPI: 1
-- HAVE_LIBFTDI: 1
-- HAVE_LIBFTDI1: HAVE_LIBFTDI1-NOTFOUND
-- HAVE_LIBREADLINE: HAVE_LIBREADLINE-NOTFOUND
-- HAVE_LIBELF_H: 1
-- HAVE_LIBELF_LIBELF_H: 
-- HAVE_USB_H: 
-- HAVE_LUSB0_USB_H: 1
-- HAVE_LIBUSB_H: 
-- HAVE_LIBUSB_1_0_LIBUSB_H: 
-- HAVE_HIDAPI_HIDAPI_H: 1
-- LIBUSB_COMPAT_DIR: 
mcuee commented 2 years ago

No idea why this happens, maybe it has something to do with the CI environment.

In the end, probably the following is the ultimate fix.

mcuee commented 1 year ago

This may be related to the Windows SDK version used in github action. As of now, this is used.

https://github.com/avrdudes/avrdude/blob/main/.github/workflows/build.yml#L214

-D CMAKE_SYSTEM_VERSION=11

I am thinking that github actions like the following may help. https://github.com/fbactions/setup-winsdk https://github.com/GuillaumeFalourd/setup-windows10-sdk-action

Ref: or maybe we can just change that to a supported version. I will try this as well. https://github.com/actions/runner-images/blob/main/images/win/Windows2022-Readme.md#installed-windows-sdks

mcuee commented 1 year ago

Unfortunately, the above two methods do not help at all. 1) https://github.com/mcuee/avrdude/actions/runs/3805885737/jobs/6474243087 2) https://github.com/mcuee/avrdude/actions/runs/3805956125/jobs/6474334190

Then it failed to build if I hard code the libhid path. The linking step failed. https://github.com/mcuee/avrdude/actions/runs/3806167734