Skip to content
This repository was archived by the owner on Oct 5, 2021. It is now read-only.

Commit b58ded8

Browse files
author
Geoffrey McRae
committed
added: new -c option to resume a connection, baud rate MUST be the same as the initial init for this to work
added: new init parameter to stm32_init to bypass the INIT handshake added: call to stm32_erase_memory on program, seems that programming fails without it on occasion
1 parent 983b296 commit b58ded8

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

main.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ char verify = 0;
5050
int retry = 10;
5151
char exec_flag = 0;
5252
uint32_t execute = 0;
53+
char init_flag = 1;
5354
char *filename;
5455

5556
/* functions */
@@ -96,7 +97,7 @@ int main(int argc, char* argv[]) {
9697
}
9798

9899
printf("Serial Config: %s\n", serial_get_setup_str(serial));
99-
if (!(stm = stm32_init(serial))) goto close;
100+
if (!(stm = stm32_init(serial, init_flag))) goto close;
100101

101102
printf("Version : 0x%02x\n", stm->bl_version);
102103
printf("Option 1 : 0x%02x\n", stm->option1);
@@ -152,6 +153,8 @@ int main(int argc, char* argv[]) {
152153
goto close;
153154
}
154155

156+
stm32_erase_memory(stm);
157+
155158
addr = stm->dev->fl_start;
156159
fprintf(stdout, "\x1B[s");
157160
fflush(stdout);
@@ -234,7 +237,7 @@ int main(int argc, char* argv[]) {
234237

235238
int parse_options(int argc, char *argv[]) {
236239
int c;
237-
while((c = getopt(argc, argv, "b:r:w:vn:g:h")) != -1) {
240+
while((c = getopt(argc, argv, "b:r:w:vn:g:ch")) != -1) {
238241
switch(c) {
239242
case 'b':
240243
baudRate = serial_get_baud(strtoul(optarg, NULL, 0));
@@ -270,6 +273,10 @@ int parse_options(int argc, char *argv[]) {
270273
execute = strtoul(optarg, NULL, 0);
271274
break;
272275

276+
case 'c':
277+
init_flag = 0;
278+
break;
279+
273280
case 'h':
274281
show_help(argv[0]);
275282
return 1;
@@ -302,14 +309,16 @@ int parse_options(int argc, char *argv[]) {
302309

303310
void show_help(char *name) {
304311
fprintf(stderr,
305-
"Usage: %s [-bvnhg] [-[rw] filename] /dev/ttyS0\n"
312+
"Usage: %s [-bvnhgc] [-[rw] filename] /dev/ttyS0\n"
306313
" -b rate Baud rate (default 57600)\n"
307314
" -r filename Read flash to file\n"
308315
" -w filename Write flash to file\n"
309316
" -v Verify writes\n"
310317
" -n count Retry failed writes up to count times (default 10)\n"
311318
" -g address Start execution at specified address (0 = flash start)\n"
312319
" -h Show this help\n"
320+
" -c Resume the connection (don't send initial INIT)\n"
321+
" *Baud rate must be kept the same as the first init*\n"
313322
"\n"
314323
"Examples:\n"
315324
" Get device information:\n"

serial_linux.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ serial_err_t serial_setup(serial_t *h, const serial_baud_t baud, const serial_bi
134134
h->newtio.c_cflag &= ~(CSIZE | CRTSCTS);
135135
h->newtio.c_iflag &= ~(IXON | IXOFF | IXANY | IGNPAR);
136136
h->newtio.c_lflag &= ~(ECHOK | ECHOCTL | ECHOKE);
137-
h->newtio.c_oflag &= ~(OPOST);
137+
h->newtio.c_oflag &= ~(OPOST | ONLCR);
138138

139139
/* setup the new settings */
140140
cfsetispeed(&h->newtio, port_baud);

stm32.c

+9-7
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,22 @@ char stm32_send_command(const stm32_t *stm, const uint8_t cmd) {
9999
return 1;
100100
}
101101

102-
stm32_t* stm32_init(const serial_t *serial) {
102+
stm32_t* stm32_init(const serial_t *serial, const char init) {
103103
uint8_t len;
104104
stm32_t *stm;
105105

106106
stm = calloc(sizeof(stm32_t), 1);
107107
stm->cmd = calloc(sizeof(stm32_cmd_t), 1);
108108
stm->serial = serial;
109109

110-
stm32_send_byte(stm, STM32_CMD_INIT);
111-
if (stm32_read_byte(stm) != STM32_ACK) {
112-
free(stm->cmd);
113-
free(stm);
114-
fprintf(stderr, "Failed to get init ACK from device\n");
115-
return NULL;
110+
if (init) {
111+
stm32_send_byte(stm, STM32_CMD_INIT);
112+
if (stm32_read_byte(stm) != STM32_ACK) {
113+
free(stm->cmd);
114+
free(stm);
115+
fprintf(stderr, "Failed to get init ACK from device\n");
116+
return NULL;
117+
}
116118
}
117119

118120
/* get the bootloader information */

stm32.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct stm32_dev {
4949
uint32_t mem_start, mem_end;
5050
};
5151

52-
stm32_t* stm32_init (const serial_t *serial);
52+
stm32_t* stm32_init (const serial_t *serial, const char init);
5353
void stm32_close (stm32_t *stm);
5454
char stm32_read_memory (const stm32_t *stm, uint32_t address, uint8_t data[], unsigned int len);
5555
char stm32_write_memory(const stm32_t *stm, uint32_t address, uint8_t data[], unsigned int len);

0 commit comments

Comments
 (0)