2017-03-25 119 views
1

我想在Leonardo板上自己編譯和傳輸一個Arduino程序。如何強制Leonardo使用avrdude重置?

一切正常工作與Arduino官方IDE。我已經啓用詳細模式來編譯和字節碼傳輸。

我可以看到每個命令行。 我想了解每一行。

除了最後一步之外,一切都很好:轉移到avrdude。 如果我準確鍵入相同的命令,我得到一個錯誤:如果我與Arduino的IDE上傳代碼

.avrdude: butterfly_recv(): programmer is not responding 

此錯誤是不存在的。

我可以看到一個區別 - Arduino的IDE顯示該行的AVRDUDE呼叫前:

Forcing reset using 1200bps open/close on port /dev/cu.usbmodem1431 

所以我的問題是我怎麼能做出這種復位通過命令行?

回答

1

那麼你幾乎自己寫了答案。您需要以波特率1200打開串口連接到Arduino,然後關閉連接。然後Arduino將啓動進入SAM-BA,並重置自身,現在已準備好用於新程序。

+0

我不明白arduino會明白如何通過打開/關閉端口來重置? – Bob5421

+0

以下是您需要閱讀的內容,https://www.arduino.cc/en/main/arduinoBoardLeonardo - 請參閱「自動(軟件)重置和引導加載程序啓動」部分 – XerXeX

2

從Windows上傳我製作了avrdude的bat文件包裝器。

它通過WMI識別Leonardo COM端口,使用模式命令將此COM端口重置爲1200波特,然後識別引導加載程序COM端口並調用avrdude。

固件應該被放置到firmware.hex,但它可以被改變爲從命令線供給

代碼是在GitHub回購這裏https://github.com/p1ne/arduino-leonardo-uploader

或以下:

@echo off 
setlocal 

for /f "tokens=1* delims==" %%I in ('wmic path win32_pnpentity get caption /format:list ^| find "SparkFun Pro Micro"') do (
    call :resetCOM "%%~J" 
) 

:continue 

:: wmic /format:list strips trailing spaces (at least for path win32_pnpentity) 
for /f "tokens=1* delims==" %%I in ('wmic path win32_pnpentity get caption /format:list ^| find "Arduino Leonardo bootloader"') do (
    call :setCOM "%%~J" 
) 

:: end main batch 
goto :EOF 

:resetCOM <WMIC_output_line> 
:: sets _COM#=line 
setlocal 
set "str=%~1" 
set "num=%str:*(COM=%" 
set "num=%num:)=%" 
set port=COM%num% 
echo %port% 
mode %port%: BAUD=1200 parity=N data=8 stop=1 
goto :continue 

:setCOM <WMIC_output_line> 
:: sets _COM#=line 
setlocal 
set "str=%~1" 
set "num=%str:*(COM=%" 
set "num=%num:)=%" 
set port=COM%num% 
echo %port% 
goto :flash 

:flash 
avrdude -v -C./avrdude.conf -patmega32u4 -cavr109 -P%port% -b57600 -D -V -Uflash:w:./firmware.hex:i 
2

我在macOS上有同樣的問題,我想出了以下bash腳本:

# find the Arduino port 
ARDUINO_UPLOAD_PORT="$(find /dev/cu.usbmodem* | head -n 1)" 

# reset the Arduino 
stty -f "${ARDUINO_UPLOAD_PORT}" 1200 

# wait for it... 
while :; do 
    sleep 0.5 
    [ -c "${ARDUINO_UPLOAD_PORT}" ] && break 
done 

# ...upload! 
avrdude "${OPTIONS[@]}" 

while循環是絕招!只要Arduino端口恢復在線狀態,它就會繼續進行。

這是一個Makefile我寫了這個項目的一部分: github.com/gibatronic/sesame

0

在Windows上,在命令提示符下,相同的解決方案,略有不同的批處理文件。 也確定引導加載程序com端口。 請注意,只有萊昂納多被閃現應該連接!

@echo off 
echo Upgrade procedure starting. 
if %1.==. goto error 
set hexfile=%1 
set comportA=NONE 
set comportB=NONE 
if not exist %hexfile% goto error 
for /f "usebackq" %%B in (`wmic path Win32_SerialPort Where "Caption LIKE '%%Leonardo%%'" Get DeviceID ^| FIND "COM"`) do set comportA=%%B 
if %comportA%==NONE goto nodevice 
echo Com Port for Arduino device is detected as %comportA%. 
echo Reset Arduino into bootloader 
mode %comportA%: baud=12 > nul 
timeout 2 > nul 
for /f "usebackq" %%B in (`wmic path Win32_SerialPort Where "Caption LIKE '%%Leonardo%%'" Get DeviceID ^| FIND "COM"`) do set comportB=%%B 
if %comportB%==NONE goto nobldevice 
echo Com Port for Arduino bootloader device is detected as %comportB%. 
echo. 
echo Starting AVR Downloader/UploaDEr..... 
avrdude -pm32u4 -cavr109 -D -P%comportB% -b57600 -Uflash:w:%hexfile% 
goto upgradedone 
:nodevice 
echo No matching module found, you should connect the module you want to upgrade. 
goto end 
:nobldevice 
echo Reset into bootloader failed, please try again... 
goto end 
:error 
Echo Missing parameter or file, you should provide the full filename of an existing .hex file you want to use. 
goto end 
:upgradedone 
echo. 
echo Upgrade done! 
:end 
相關問題