Example for updating the MTi-1's firmware. Uses a platform independent, retargetable pure C implementation of the firmware updater protocol.

Dependencies:   mbed-rtos mbed

Important Information

This example is deprecated and no longer maintained. There are new embedded examples available in the MT SDK folder of the MT Software Suite. For more information please visit: https://xsenstechnologies.force.com/knowledgebase/s/article/Introduction-to-the-MT-SDK-programming-examples-for-MTi-devices

Overview

The purpose of this example is to demonstrate how to update the firmware of an MTi-1 series module using the FwUpdate library. The FwUpdate library is provided as C source in the xbus directory. It is setup to be platform independent and easily retargetable. The user must provide an instance of the FwUpdate struct having the platform specific callback function filled in. Refer to fwupdate.h for more information.

The example embeds an Xsens Firmware File (XFF). The XFF used is the official 1.1.1 MTi1-series firmware release. If needed binary copies of specific firmware files can be requested through our support department. We used srecord to convert the XFF to the C data array (See xffdata.c and xffdata.h). When using requested Xsens provided XFF file use srecord as follows:

srec_cat firmware.xff -binary -o xffdata.c -C-array g_xffData -include


This example updates the firmware only. The eMTS (extended Motion Tracker Settings) are not updated. This means that in rare cases (e.g. when hardware filter parameters are updated), you do not take full advantage of the filter update. Most functionality, such as filter behavior, outputs, output formats and communication options are updated with this example. Please use the Windows/Linux FW updater when HW parameters are updated (see release notes to check if HW parameters were changed).

Communication with the MTi-1 series device is implemented using a either a full-duplex UART, I2C or SPI bus. A reset line is used to reset the MTi during initialization. Data is output to a host PC terminal using a second UART.

Supported Platforms

The program has been tested on the following mbed platforms:

Porting to other mbed platforms is relatively be easy by adding its specific port information to board.h. It is however necessary that the board has sufficient code flash/ROM to keep a copy of the XFF (150K). In case you store the XFF data in a different memory (e.g. an external memory) you must re-implement the readXffData callback function.

Using the Example

  1. To use the example program connect one of the supported mbed boards to the host PC and download the application from the mbed online compiler to the target device.
  2. With the mbed board unpowered (USB disconnected) wire the mbed board to the MTi-1 development board. The following connections are required:
    • In all cases:
      • 5V (or 3V3) main supply to VDD (P300-1)
      • MCU IO voltage (IORef) to VDDIO (P300-2)
      • GND to GND (P300-3)
      • MT_NRESET to nRST P(300-5)
    • For I2C communication:
      • MT_SCL to I2C_SCL (P300-9)
      • MT_SDA to I2C_SDA (P300-11)
      • MT_DRDY to DRDY (P300-15)
      • MT_ADD0 to ADD0 (P300-17)
      • MT_ADD1 to ADD0 (P300-19)
      • MT_ADD2 to ADD0 (P300-21)
    • For SPI communication:
      • MT_DRDY to DRDY (P300-15)
      • MT_SCLK to SPI_SCK (P300-17)
      • MT_MISO to SPI_MISO (P300-19)
      • MT_MOSI to SPI_MOSI (P300-21)
      • MT_nCS to SPI_nCS (P300-23)
    • For UART communication:
      • MT_RX to UART_TX (P300-9)
      • MT_TX to UART_RX (P300-11)

Information

Check the defines in board.h to determine which IO pins are used for the MT_xxx connections on each mbed platform.

Information

The active peripheral (I2C, SPI or UART) is selected on the MTi-1 development board through the PSEL0 and PSEL1 switches. Look on the bottom of the development board for the correct settings.

  1. Connect to the target using a serial terminal. The application is configured for:
    • Baudrate = 921600
    • Stop bits = 1
    • No parity bits
    • No flow control
  2. Reset the mbed board.
  3. You should be presented with a simple user interface as shown below:
Embedded firmware updater example
Interface: I2C

h: Print this text
c: GotoConfig
m: GotoMeasurement
r: Soft reset the module
b: GotoBootloader
v: Request firmware revision
d: Request deviceId
u: Start firmware update (make sure module is in bootloader mode)
x: Hard reset the module and make it stay in bootloader 

To do a firmware update

  • Make the MTi-1 enter bootloader mode. Either through 'b' or 'x'
  • You can check if the MTi-1 is in bootloader by requesting the firmware revision ('v'). The bootloader revision always starts with 255
  • Press 'u' to start the firmware update
  • After about 20 seconds the "Firmware update ready" message should appear indicating the update succeeded
  • The device should automatically reboot into its application firmware (use 'v' to verify)
Committer:
tjerkhofmeijer
Date:
Wed Dec 21 09:51:35 2016 +0100
Revision:
6:fd42cb49cdd0
Parent:
5:63985ca16eb9
Updated the embedded MTi1 firmware file to version 1.1.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tjerkhofmeijer 0:6fca643f1aff 1 /*!
tjerkhofmeijer 0:6fca643f1aff 2 * \file
tjerkhofmeijer 0:6fca643f1aff 3 * \copyright Copyright (C) Xsens Technologies B.V., 2015.
tjerkhofmeijer 0:6fca643f1aff 4 *
tjerkhofmeijer 0:6fca643f1aff 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
tjerkhofmeijer 0:6fca643f1aff 6 * use this file except in compliance with the License. You may obtain a copy
tjerkhofmeijer 0:6fca643f1aff 7 * of the License at
tjerkhofmeijer 0:6fca643f1aff 8 *
tjerkhofmeijer 0:6fca643f1aff 9 * http://www.apache.org/licenses/LICENSE-2.0
tjerkhofmeijer 0:6fca643f1aff 10 *
tjerkhofmeijer 0:6fca643f1aff 11 * Unless required by applicable law or agreed to in writing, software
tjerkhofmeijer 0:6fca643f1aff 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
tjerkhofmeijer 0:6fca643f1aff 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
tjerkhofmeijer 0:6fca643f1aff 14 * License for the specific language governing permissions and limitations
tjerkhofmeijer 0:6fca643f1aff 15 * under the License.
tjerkhofmeijer 0:6fca643f1aff 16 */
tjerkhofmeijer 0:6fca643f1aff 17 #include "mtinterface_mtssp.h"
tjerkhofmeijer 0:6fca643f1aff 18 #include "mbed.h"
tjerkhofmeijer 0:6fca643f1aff 19 #include "rtos.h"
tjerkhofmeijer 0:6fca643f1aff 20 #include "board.h"
tjerkhofmeijer 0:6fca643f1aff 21 #include "xbusmessage.h"
tjerkhofmeijer 0:6fca643f1aff 22 #include "xbusparser.h"
tjerkhofmeijer 5:63985ca16eb9 23 #include <assert.h>
tjerkhofmeijer 0:6fca643f1aff 24 #include "xbusdef.h"
tjerkhofmeijer 0:6fca643f1aff 25
tjerkhofmeijer 0:6fca643f1aff 26
tjerkhofmeijer 0:6fca643f1aff 27 /*! \class MtInterfaceMtssp
tjerkhofmeijer 0:6fca643f1aff 28 \brief Implementation of MtInterface for the MTSSP protocol
tjerkhofmeijer 0:6fca643f1aff 29
tjerkhofmeijer 0:6fca643f1aff 30 MTSSP is the protocol used for communicating with an Xsens motion tracker over I2C or SPI.
tjerkhofmeijer 0:6fca643f1aff 31 */
tjerkhofmeijer 0:6fca643f1aff 32
tjerkhofmeijer 0:6fca643f1aff 33
tjerkhofmeijer 0:6fca643f1aff 34 /*! \brief Constructor
tjerkhofmeijer 0:6fca643f1aff 35 \param driver Pointer to an MtsspDriver
tjerkhofmeijer 0:6fca643f1aff 36 */
tjerkhofmeijer 0:6fca643f1aff 37 MtInterfaceMtssp::MtInterfaceMtssp(MtsspDriver *driver)
tjerkhofmeijer 0:6fca643f1aff 38 : m_driver(driver)
tjerkhofmeijer 0:6fca643f1aff 39 {
tjerkhofmeijer 0:6fca643f1aff 40 m_dataReady = new DigitalIn(MT_DRDY);
tjerkhofmeijer 0:6fca643f1aff 41 }
tjerkhofmeijer 0:6fca643f1aff 42
tjerkhofmeijer 0:6fca643f1aff 43
tjerkhofmeijer 0:6fca643f1aff 44 /*! \brief Destructor
tjerkhofmeijer 0:6fca643f1aff 45 */
tjerkhofmeijer 0:6fca643f1aff 46 MtInterfaceMtssp::~MtInterfaceMtssp()
tjerkhofmeijer 0:6fca643f1aff 47 {
tjerkhofmeijer 0:6fca643f1aff 48 delete m_dataReady;
tjerkhofmeijer 0:6fca643f1aff 49 }
tjerkhofmeijer 0:6fca643f1aff 50
tjerkhofmeijer 0:6fca643f1aff 51
tjerkhofmeijer 0:6fca643f1aff 52 /*! \brief Must be polled in the main application loop
tjerkhofmeijer 0:6fca643f1aff 53 */
tjerkhofmeijer 0:6fca643f1aff 54 void MtInterfaceMtssp::process()
tjerkhofmeijer 0:6fca643f1aff 55 {
tjerkhofmeijer 0:6fca643f1aff 56 if (*m_dataReady)
tjerkhofmeijer 0:6fca643f1aff 57 {
tjerkhofmeijer 0:6fca643f1aff 58 handleDataReady();
tjerkhofmeijer 0:6fca643f1aff 59 }
tjerkhofmeijer 0:6fca643f1aff 60 }
tjerkhofmeijer 0:6fca643f1aff 61
tjerkhofmeijer 0:6fca643f1aff 62
tjerkhofmeijer 0:6fca643f1aff 63 /*! \brief Sends an xbus message to the motion tracker
tjerkhofmeijer 0:6fca643f1aff 64 \param xbusMessage Pointer to xbus message which should be send
tjerkhofmeijer 0:6fca643f1aff 65 */
tjerkhofmeijer 0:6fca643f1aff 66 void MtInterfaceMtssp::sendXbusMessage(XbusMessage const* xbusMessage)
tjerkhofmeijer 0:6fca643f1aff 67 {
tjerkhofmeijer 0:6fca643f1aff 68 uint8_t* buf = (uint8_t*)allocateMessageData(xbusMessage->m_length + 4);
tjerkhofmeijer 0:6fca643f1aff 69 size_t rawLength = XbusMessage_createRawMessage(buf, xbusMessage, m_driver->busFormat());
tjerkhofmeijer 0:6fca643f1aff 70 m_driver->writeRaw(buf, rawLength);
tjerkhofmeijer 0:6fca643f1aff 71 deallocateMessageData(buf);
tjerkhofmeijer 0:6fca643f1aff 72 }
tjerkhofmeijer 0:6fca643f1aff 73
tjerkhofmeijer 0:6fca643f1aff 74
tjerkhofmeijer 0:6fca643f1aff 75 /*! \brief Returns the low level bus format used
tjerkhofmeijer 0:6fca643f1aff 76 */
tjerkhofmeijer 0:6fca643f1aff 77 XbusBusFormat MtInterfaceMtssp::busFormat()
tjerkhofmeijer 0:6fca643f1aff 78 {
tjerkhofmeijer 0:6fca643f1aff 79 return m_driver->busFormat();
tjerkhofmeijer 0:6fca643f1aff 80 }
tjerkhofmeijer 0:6fca643f1aff 81
tjerkhofmeijer 0:6fca643f1aff 82
tjerkhofmeijer 0:6fca643f1aff 83 /*! \brief Should be called if the data ready line from the motion tracker signals that there is data pending
tjerkhofmeijer 0:6fca643f1aff 84 */
tjerkhofmeijer 0:6fca643f1aff 85 void MtInterfaceMtssp::handleDataReady()
tjerkhofmeijer 0:6fca643f1aff 86 {
tjerkhofmeijer 0:6fca643f1aff 87 uint16_t notificationMessageSize = 0;
tjerkhofmeijer 0:6fca643f1aff 88 uint16_t measurementMessageSize = 0;
tjerkhofmeijer 0:6fca643f1aff 89 readPipeStatus(&notificationMessageSize, &measurementMessageSize);
tjerkhofmeijer 0:6fca643f1aff 90
tjerkhofmeijer 0:6fca643f1aff 91 uint16_t size;
tjerkhofmeijer 0:6fca643f1aff 92 uint8_t pipe;
tjerkhofmeijer 0:6fca643f1aff 93 if (notificationMessageSize)
tjerkhofmeijer 0:6fca643f1aff 94 {
tjerkhofmeijer 0:6fca643f1aff 95 size = notificationMessageSize;
tjerkhofmeijer 0:6fca643f1aff 96 pipe = XBUS_NOTIFICATION_PIPE;
tjerkhofmeijer 0:6fca643f1aff 97 }
tjerkhofmeijer 0:6fca643f1aff 98 else if (measurementMessageSize)
tjerkhofmeijer 0:6fca643f1aff 99 {
tjerkhofmeijer 0:6fca643f1aff 100 size = measurementMessageSize;
tjerkhofmeijer 0:6fca643f1aff 101 pipe = XBUS_MEASUREMENT_PIPE;
tjerkhofmeijer 0:6fca643f1aff 102 }
tjerkhofmeijer 0:6fca643f1aff 103 else
tjerkhofmeijer 0:6fca643f1aff 104 {
tjerkhofmeijer 0:6fca643f1aff 105 return;
tjerkhofmeijer 0:6fca643f1aff 106 }
tjerkhofmeijer 0:6fca643f1aff 107
tjerkhofmeijer 0:6fca643f1aff 108 uint8_t* buffer = (uint8_t*)allocateMessageData(size + 3);
tjerkhofmeijer 0:6fca643f1aff 109 buffer[0] = XBUS_PREAMBLE;
tjerkhofmeijer 0:6fca643f1aff 110 buffer[1] = XBUS_MASTERDEVICE;
tjerkhofmeijer 0:6fca643f1aff 111 readFromPipe(&buffer[2], size, pipe);
tjerkhofmeijer 0:6fca643f1aff 112 XbusParser_parseBuffer(m_xbusParser, buffer, 2 + size);
tjerkhofmeijer 0:6fca643f1aff 113 deallocateMessageData(buffer);
tjerkhofmeijer 0:6fca643f1aff 114 }
tjerkhofmeijer 0:6fca643f1aff 115
tjerkhofmeijer 0:6fca643f1aff 116
tjerkhofmeijer 0:6fca643f1aff 117 /*! \brief Read MTSSP protocol info
tjerkhofmeijer 0:6fca643f1aff 118 \param[out] version Pointer to receive the version byte
tjerkhofmeijer 0:6fca643f1aff 119 \param[out] dataReadyConfig Pointer to receive the data ready configuration byte
tjerkhofmeijer 0:6fca643f1aff 120 \sa configureProtocol
tjerkhofmeijer 0:6fca643f1aff 121 */
tjerkhofmeijer 0:6fca643f1aff 122 void MtInterfaceMtssp::readProtocolInfo(uint8_t* version, uint8_t* dataReadyConfig)
tjerkhofmeijer 0:6fca643f1aff 123 {
tjerkhofmeijer 0:6fca643f1aff 124 uint8_t rxdata[2];
tjerkhofmeijer 0:6fca643f1aff 125 m_driver->read(XBUS_PROTOCOL_INFO, rxdata, sizeof(rxdata));
tjerkhofmeijer 0:6fca643f1aff 126 *version = rxdata[0];
tjerkhofmeijer 0:6fca643f1aff 127 *dataReadyConfig = rxdata[1];
tjerkhofmeijer 0:6fca643f1aff 128 }
tjerkhofmeijer 0:6fca643f1aff 129
tjerkhofmeijer 0:6fca643f1aff 130
tjerkhofmeijer 0:6fca643f1aff 131 /*! \brief Write MTSSP protocol settings
tjerkhofmeijer 0:6fca643f1aff 132 \param dataReadyConfig The data ready configuration which must be set
tjerkhofmeijer 0:6fca643f1aff 133
tjerkhofmeijer 0:6fca643f1aff 134 Bit 7:4 Reserved \n
tjerkhofmeijer 0:6fca643f1aff 135 Bit 3 Measurement pipe DRDY event enable: 0 = disabled, 1 = enabled \n
tjerkhofmeijer 0:6fca643f1aff 136 Bit 2 Notification pipe DRDY event enable: 0 = disabled, 1 = enabled \n
tjerkhofmeijer 0:6fca643f1aff 137 Bit 1 Output type of DRDY pin: = 0 Push/pull, 1 = open drain \n
tjerkhofmeijer 0:6fca643f1aff 138 Bit 0 Polarity of DRDY signal: 0 = Idle low, 1 = Idle high \n
tjerkhofmeijer 0:6fca643f1aff 139 \sa readProtocolInfo
tjerkhofmeijer 0:6fca643f1aff 140 */
tjerkhofmeijer 0:6fca643f1aff 141 void MtInterfaceMtssp::configureProtocol(uint8_t dataReadyConfig)
tjerkhofmeijer 0:6fca643f1aff 142 {
tjerkhofmeijer 0:6fca643f1aff 143 m_driver->write(XBUS_CONFIGURE_PROTOCOL, &dataReadyConfig, sizeof(dataReadyConfig));
tjerkhofmeijer 0:6fca643f1aff 144 }
tjerkhofmeijer 0:6fca643f1aff 145
tjerkhofmeijer 0:6fca643f1aff 146
tjerkhofmeijer 0:6fca643f1aff 147 /*! \brief Read the pipe status
tjerkhofmeijer 0:6fca643f1aff 148 \param[out] notificationMessageSize Pointer for returning the number of pending notification bytes
tjerkhofmeijer 0:6fca643f1aff 149 \param[out] measurementMessageSize Pointer for returning the number of pending measurement bytes
tjerkhofmeijer 0:6fca643f1aff 150 */
tjerkhofmeijer 0:6fca643f1aff 151 void MtInterfaceMtssp::readPipeStatus(uint16_t *notificationMessageSize, uint16_t* measurementMessageSize)
tjerkhofmeijer 0:6fca643f1aff 152 {
tjerkhofmeijer 0:6fca643f1aff 153 uint8_t status[4];
tjerkhofmeijer 0:6fca643f1aff 154 m_driver->read(XBUS_PIPE_STATUS, status, sizeof(status));
tjerkhofmeijer 0:6fca643f1aff 155 *notificationMessageSize = status[0] | (status[1] << 8);
tjerkhofmeijer 0:6fca643f1aff 156 *measurementMessageSize = status[2] | (status[3] << 8);
tjerkhofmeijer 0:6fca643f1aff 157 }
tjerkhofmeijer 0:6fca643f1aff 158
tjerkhofmeijer 0:6fca643f1aff 159
tjerkhofmeijer 0:6fca643f1aff 160 /*! \brief Read from notification or measurement data pipe
tjerkhofmeijer 0:6fca643f1aff 161 \param buffer Result buffer
tjerkhofmeijer 0:6fca643f1aff 162 \param size Number of bytes to read
tjerkhofmeijer 0:6fca643f1aff 163 \param pipe Pipe from which to read, XBUS_NOTIFICATION_PIPE or XBUS_MEASUREMENT_PIPE
tjerkhofmeijer 0:6fca643f1aff 164 */
tjerkhofmeijer 0:6fca643f1aff 165 void MtInterfaceMtssp::readFromPipe(uint8_t* buffer, uint16_t size, uint8_t pipe)
tjerkhofmeijer 0:6fca643f1aff 166 {
tjerkhofmeijer 0:6fca643f1aff 167 m_driver->read(pipe, buffer, size);
tjerkhofmeijer 0:6fca643f1aff 168 }