ISBootloaderExample.c
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright (c) 2014-2021 Inertial Sense, Inc. - http://inertialsense.com
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
7 
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #include <stdio.h>
14 
15 // STEP 1: Add Includes
16 // Change these include paths to the correct paths for your project
17 #include "../../src/ISComm.h"
18 #include "../../src/serialPortPlatform.h"
19 #include "../../src/inertialSenseBootLoader.h"
20 
21 // print out upload progress
22 static int bootloaderUploadProgress(const void* obj, float percent)
23 {
24  printf("Upload: %d percent... \r", (int)(percent * 100.0f));
25  if (percent >= 1.0f)
26  {
27  printf("\n");
28  }
29  return 1; // return zero to abort
30 }
31 
32 // print out verify progress
33 static int bootloaderVerifyProgress(const void* obj, float percent)
34 {
35  printf("Verify: %d percent... \r", (int)(percent * 100.0f));
36  if (percent >= 1.0f)
37  {
38  printf("\n");
39  }
40  return 1; // return zero to abort
41 }
42 
43 static void bootloaderStatusText(const void* obj, const char* info)
44 {
45  printf("%s\n", info);
46 }
47 
48 int main(int argc, char* argv[])
49 {
50  if (argc < 3 || argc > 4)
51  {
52  printf("Please pass the com port, firmware file name to bootload, and optionally bootloader file name as the only arguments\r\n");
53  printf("usage: %s {COMx} {Firmware file} {Bootloader file (optional)}\r\n", argv[0]);
54  // In Visual Studio IDE, this can be done through "Project Properties -> Debugging -> Command Arguments: COM3 IS_uINS-3.hex"
55  return -1;
56  }
57 
58  // STEP 2: Initialize and open serial port
59 
60  serial_port_t serialPort;
61 
62  // initialize the serial port (Windows, MAC or Linux) - if using an embedded system like Arduino,
63  // you will need to either bootload from Windows, MAC or Linux, or implement your own code that
64  // implements all the function pointers on the serial_port_t struct.
65  serialPortPlatformInit(&serialPort);
66 
67  // set the port - the bootloader uses this to open the port and enable bootload mode, etc.
68  serialPortSetPort(&serialPort, argv[1]);
69 
70  // STEP 3: Set bootloader parameters
71 
72  // bootloader parameters
74 
75  // very important - initialize the bootloader params to zeros
76  memset(&param, 0, sizeof(param));
77 
78  // the file to bootload, *.hex
79  param.fileName = argv[2];
80 
81  // optional - bootloader file, *.bin
82  param.forceBootloaderUpdate = 0; //do not force update of bootloader
83  if (argc == 4)
84  param.bootName = argv[3];
85  else
86  param.bootName = 0;
87 
88  // the serial port
89  param.port = &serialPort;
90 
91  // progress indicators
95 
96  // enable verify to read back the firmware and ensure it is correct
97  param.flags.bitFields.enableVerify = 1;
98 
99  // optional - define baudrate. If not defined standard baud rates will be attempted.
100  // The default bootloader baudrate is 921600. If using a system with known baud limits it is best to specify a lower baudrate.
101 // param.baudRate = IS_BAUD_RATE_BOOTLOADER_RS232;
102 // param.baudRate = IS_BAUD_RATE_BOOTLOADER_SLOW;
103 
104  // enable auto-baud, in the event that fast serial communications is not available,
105  // the bootloader will attempt to fall back to a slower speed
106  // param.flags.bitFields.enableAutoBaud = 1;
107 
108  // STEP 4: Run bootloader
109 
110  if (bootloadFileEx(&param))
111  {
112  printf("Bootloader success on port %s with file %s\n", serialPort.port, param.fileName);
113  return 0;
114  }
115  else
116  {
117  if(param.error[0] != 0)
118  printf("Bootloader failed! Error: %s\n", param.error);
119  else
120  printf("Bootloader failed!\n");
121  return -1;
122  }
123 }
124 
static int bootloaderVerifyProgress(const void *obj, float percent)
bool param(const std::string &param_name, T &param_val, const T &default_val)
static void bootloaderStatusText(const void *obj, const char *info)
void serialPortSetPort(serial_port_t *serialPort, const char *port)
Definition: serialPort.c:18
int serialPortPlatformInit(serial_port_t *serialPort)
struct bootload_params_t::@41::@42 bitFields
char port[MAX_SERIAL_PORT_NAME_LENGTH+1]
Definition: serialPort.h:70
#define printf(...)
Definition: evb_tasks.h:36
pfnBootloadProgress uploadProgress
pfnBootloadStatus statusText
int bootloadFileEx(bootload_params_t *params)
int main(int argc, char *argv[])
char error[BOOTLOADER_ERROR_LENGTH]
static int bootloaderUploadProgress(const void *obj, float percent)
pfnBootloadProgress verifyProgress
union bootload_params_t::@41 flags


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:57