Index: serial_posix.c
===================================================================
--- serial_posix.c	(revision 48)
+++ serial_posix.c	(working copy)
@@ -24,6 +24,7 @@
 #include <termios.h>
 #include <stdio.h>
 #include <assert.h>
+#include <sys/ioctl.h>
 
 #include "serial.h"
 
@@ -207,6 +208,25 @@
 	return SERIAL_ERR_OK;
 }
 
+serial_err_t serial_set_rts(const serial_t *h, int rts) {
+	unsigned int ctl;
+	int r;
+
+	r = ioctl(h->fd, TIOCMGET, &ctl);
+	if (r < 0) return SERIAL_ERR_SYSTEM;
+
+	if (rts) {
+		ctl |= (TIOCM_RTS);
+	} else {
+		ctl &= ~(TIOCM_RTS);
+	}
+
+	r = ioctl(h->fd, TIOCMSET, &ctl);
+	if (r < 0) return SERIAL_ERR_SYSTEM;
+
+	return SERIAL_ERR_OK;
+}
+
 const char* serial_get_setup_str(const serial_t *h) {
 	static char str[11];
 	if (!h->configured)
Index: serial.h
===================================================================
--- serial.h	(revision 48)
+++ serial.h	(working copy)
@@ -75,6 +75,7 @@
 serial_err_t serial_setup(serial_t *h, const serial_baud_t baud, const serial_bits_t bits, const serial_parity_t parity, const serial_stopbit_t stopbit);
 serial_err_t serial_write(const serial_t *h, const void *buffer, unsigned int len);
 serial_err_t serial_read (const serial_t *h, const void *buffer, unsigned int len);
+serial_err_t serial_set_rts(const serial_t *h, int rts);
 const char*  serial_get_setup_str(const serial_t *h);
 
 /* common helper functions */
Index: main.c
===================================================================
--- main.c	(revision 48)
+++ main.c	(working copy)
@@ -53,6 +53,7 @@
 uint32_t	execute		= 0;
 char		init_flag	= 1;
 char		force_binary	= 0;
+char		pre_reset_flag	= 0;
 char		reset_flag	= 1;
 char		*filename;
 
@@ -132,6 +133,16 @@
 	}
 
 	printf("Serial Config: %s\n", serial_get_setup_str(serial));
+
+	if (pre_reset_flag) {
+		printf("Reseting device via RTS...");
+		serial_set_rts(serial, 1);
+		usleep(100000);
+		serial_set_rts(serial, 0);
+		usleep(100000);
+		printf("\n");
+	}
+
 	if (!(stm = stm32_init(serial, init_flag))) goto close;
 
 	printf("Version      : 0x%02x\n", stm->bl_version);
@@ -287,7 +298,7 @@
 
 int parse_options(int argc, char *argv[]) {
 	int c;
-	while((c = getopt(argc, argv, "b:r:w:e:vn:g:fch")) != -1) {
+	while((c = getopt(argc, argv, "b:r:w:e:vn:g:fchp")) != -1) {
 		switch(c) {
 			case 'b':
 				baudRate = serial_get_baud(strtoul(optarg, NULL, 0));
@@ -341,6 +352,10 @@
 			case 'h':
 				show_help(argv[0]);
 				return 1;
+
+			case 'p':
+				pre_reset_flag = 1;
+				break;
 		}
 	}
 

