2 This file is part of AutoQuad.
4 AutoQuad is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 AutoQuad is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with AutoQuad. If not, see <http://www.gnu.org/licenses/>.
16 Copyright © 2011 Bill Nesbitt
20 #include "stmbootloader.h"
29 #define DEFAULT_PORT "/dev/ttyUSB0"
30 #define DEFAULT_BAUD 115200
31 #define FIRMWARE_FILENAME "STM32.hex"
37 unsigned char overrideParity
;
38 unsigned char noSendR
;
41 void loaderUsage(void) {
42 fprintf(stderr
, "usage: loader <-h> <-p device_file> <-b baud_rate> <-f firmware_file> <-o> <-n>\n");
45 unsigned int loaderOptions(int argc
, char **argv
) {
48 strncpy(port
, DEFAULT_PORT
, sizeof(port
));
52 strncpy(firmFile
, FIRMWARE_FILENAME
, sizeof(firmFile
));
54 /* options descriptor */
55 static struct option longopts
[] = {
56 { "help", required_argument
, NULL
, 'h' },
57 { "port", required_argument
, NULL
, 'p' },
58 { "baud", required_argument
, NULL
, 's' },
59 { "firm_file", required_argument
, NULL
, 'f' },
60 { "override_parity", no_argument
, NULL
, 'o' },
61 { "no_send_r", no_argument
, NULL
, 'n' },
65 while ((ch
= getopt_long(argc
, argv
, "hp:b:f:o:n", longopts
, NULL
)) != -1)
72 strncpy(port
, optarg
, sizeof(port
));
78 strncpy(firmFile
, optarg
, sizeof(firmFile
));
96 int main(int argc
, char **argv
) {
100 if (!loaderOptions(argc
, argv
)) {
101 fprintf(stderr
, "Init failed, aborting\n");
105 s
= initSerial(port
, baud
, 0);
107 fprintf(stderr
, "Cannot open serial port '%s', aborting.\n", port
);
111 fw
= fopen(firmFile
, "r");
113 fprintf(stderr
, "Cannot open firmware file '%s', aborting.\n", firmFile
);
117 printf("Upgrading STM on port %s from %s...\n", port
, firmFile
);
118 stmLoader(s
, fw
, overrideParity
, noSendR
);