queezythegreat / arduino-cmake

Arduino CMake Build system
648 stars 216 forks source link

Reset before Upload #160

Open peterquiel opened 8 years ago

peterquiel commented 8 years ago

The arduino micro rests if an serial connection is open with 1200 baud an closed again. A software reset before uploading makes uploading a new firmware a one click/command action.

A command like

stty /dev/device 1200 && sleep 3 

before uploading did the job for me.

Would be great to have an optional reset command parameter that is executed before uploading the firmeware.

m42e commented 8 years ago
diff --git a/cmake/Platform/Arduino.cmake b/cmake/Platform/Arduino.cmake
index e5003e1..e0c412b 100644
--- a/cmake/Platform/Arduino.cmake
+++ b/cmake/Platform/Arduino.cmake
@@ -1208,10 +1208,14 @@ function(setup_arduino_bootloader_upload TARGET_NAME BOARD_ID PORT AVRDUDE_FLAGS

     list(APPEND AVRDUDE_ARGS "-Uflash:w:${TARGET_PATH}.hex")
     list(APPEND AVRDUDE_ARGS "-Ueeprom:w:${TARGET_PATH}.eep:i")
+    set (RESET_COMMAND stty -f ${PORT} 1200 && sleep 2 )
+    add_custom_target(${UPLOAD_TARGET}-reset
+                        ${RESET_COMMAND}
+        )
     add_custom_target(${UPLOAD_TARGET}
                      ${ARDUINO_AVRDUDE_PROGRAM}
                      ${AVRDUDE_ARGS}
-                     DEPENDS ${TARGET_NAME})
+                     DEPENDS ${TARGET_NAME} ${UPLOAD_TARGET}-reset)

     # Global upload target
     if(NOT TARGET upload)
oldmud0 commented 7 years ago

The only problems is that stty doesn't work on Windows.