Motion and Environmental sensor reader application connected via BLE to ST BlueMS iOS/Android application.

Dependencies:   HTS221 LIS3MDL LPS22HB LSM303AGR LSM6DSL

Fork of MOTENV_Mbed by ST Expansion SW Team

This application supports three different sets of ST hardware boards:

  • STEVAL-STLKT01V1 (aka SensorTile)
  • X-NUCLEO-IDB05A1 and X-NUCLEO-IKS01A2 expansion boards
  • B-L475E-IOT01A IoT Discovery board

    and runs over four different target configurations:

  • Nucleo F401RE + X-NUCLEO-IDB05A1 + X-NUCLEO-IKS01A2 (set target NUCLEO_F401RE)
  • DISCO_L475VG_IOT01A (set target DISCO_L475VG_IOT01A)
  • Nucleo L476RG + CRADLE + SENSORTILE (set compile target NUCLEO_L476RG)
  • Nucleo L476RG + CRADLE_EXPANSION_BOARD + SENSORTILE (set compile target NUCLEO_L476RG, remove macro MINI_CRADLE from mbed_app.json)

The first 2 configurations do not require any HW modifications (just use the above indicated targets).

Third configuration (CRADLE ) only requires to remove the two ST-LINK jumpers and JP6 from the Nucleo L476RG board in order to allow flashing the SensorTile through the Nucleo Jtag controller. Once flashed, if the battery is properly plugged and charged, the SensorTile could be mounted in the plastic enclosure being able to run as a small stand alone wearable device. Please note that this configuration do not provide a serial console for printf.

To enable last configuration (CRADLE_EXPANSION_BOARD), follow the steps below:

  • On Nucleo L476RG
    • open the two "ST-LINK" jumpers
    • open the MCU power supply jumper JP6
    • close the solder bridges SB63 and SB62 (to enable the serial console)
  • On SensorTile Arduino Cradle close the solder bridges SB21 and SB10 (to enable the serial console) and move the jumper J2 to the 5V position
  • Plug the Sensor Tile on the Arduino Cradle
  • Plug the Cradle on the Nucleo Arduino connector and connect the debug flat cable between Cradle and Nucleo Jtag connector (the cradle pin1 -identified by a dot- must be connected to the Nucleo pin1 (dot) of SWD CN4 jtag connector)
  • Plug the Nucleo USB cable on PC (a new COM port should appear); no need to plug the micro USB cable on the cradle.
  • Open a PC terminal to see the messages
  • Compile from mbed CLI or on-line compiler removing macro MINI_CRADLE from mbed_app.json file and selecting NUCLEO_ L476RG target
  • Flash the board with the binary

For all configurations on an Android or iOS device download and open the ST BlueMS application and connect to "MotEnvMbedOS" BLE device to see the sensor data.

For all configurations is also possible to add a 9 axis MotionFX sensor fusion library, which is part of the X-CUBE-MEMS package at this link.
The library comes in three flavours, choose your preferred according to the toolchain used (IAR, Keil or GC, Keil version should be used for the online compiler) and copy it in the Middlewares\ST\STM32_MotionFX_Library\Lib directory changing the file extension according to the toolchain used (.a for GCC, .ar for Keil).
In the file mbed_app.json add the macro definition "USE_SENSOR_FUSION_LIB" to the chosen target.
If compiling from CLI and using GCC_ARM toolchain option, in the file \mbed-os\tools\toolchains\gcc.py change the compiling option from

        if target.core == "Cortex-M4F":
            self.cpu.append("-mfpu=fpv4-sp-d16")
            self.cpu.append("-mfloat-abi=softfp")

to

        if target.core == "Cortex-M4F":
            self.cpu.append("-mfpu=fpv4-sp-d16")
            self.cpu.append("-mfloat-abi=hard")

and compile.

main.h

Committer:
mapellil
Date:
2015-10-13
Revision:
3:a24a30b28dd7
Parent:
1:5fb861c45605
Child:
6:c1b8fb74072e

File content as of revision 3:a24a30b28dd7:

/* mbed Microcontroller Library
 * Copyright (c) 2006-2013 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __MAIN_H__
#define __MAIN_H__

/* Enable the following define for printout the calibration value 
 read/written from/to Memory */
 
//#define BLUEMSYS_DEBUG_CALIB

#define CUST_CONS_SERV          // Uncomment to enable console service 

//#define CUST_BATT_SERV        // Uncomment to enable battery service /** FIXME tb implemented **/

#define CUST_SENS_SERV          // Uncomment to enable env/MEMS sensor service 
#define DS3_ONBOARD  false      // deft DS3 module NOT plugged onto MEMS exp board
//#define DS3_ONBOARD  true     // Uncomment if DS3 module is plugged onto MEMS exp board

#ifdef USE_SENSOR_FUSION_LIB    // if sensor fusion lib present enable calibration service and quaternion service
#define CUST_CONFIG_SERV        // enable magnetometer calibration service
#define BLUEMSYS_STORE_CALIB_FLASH  // enable flash storage of calibration data
#define CUST_SW_SERV            // enable quaternion service
#endif

/*************** Debug Defines ******************/
/* For enabling connection and notification subscriptions debug */
//#define BLUEMSYS_DEBUG_CONNECTION

/* For enabling trasmission for notified services (except for quaternions) */
//#define BLUEMSYS_DEBUG_NOTIFY_TRAMISSION

#define MAX_I2C_SPEED               400000  
//#define NUCLEO_I2C_SHIELDS_SPEED    MAX_I2C_SPEED   // I2C speed in Hz
//#define NUCLEO_I2C_SHIELDS_SPEED    150000   // I2C speed in Hz. Max Speed 400KHz now limited because of MEMS board
#define NUCLEO_I2C_SHIELDS_SPEED    100000   

#define ENV_TIMER       500000      // 500 mSec 
#define CALIB_TIMER      40000      // 40mS
#define MEMS_TIMER       10000      // 10mS

/*************** Don't Change the following defines *************/
/* Calibration mask for Sensor fusion short precision */
#define MASK_CALIB_SENSORFUSION_SHORT 0x00000100
/* Calibration mask for Sensor fusion float precision */
#define MASK_CALIB_SENSORFUSION_FLOAT 0x00000080
/* W2ST command for asking the calibration status */
#define W2ST_COMMAND_CAL_STATUS 0xFF
/* W2ST command for resetting the calibration */
#define W2ST_COMMAND_CAL_RESET  0x00
/* W2ST command for stopping the calibration process */
#define W2ST_COMMAND_CAL_STOP   0x01
/****************************************************************/

#define BLE_DEV_NAME "BlueMbed"
#define BLE_DEV_MAC 0xFF,0x00,0x25,0xAA,0x02,0x04
#define QUAT_FLOAT_UPDATE_MUL_10MS 2
#define ACC_GYRO_MAG_UPDATE_MUL_10MS 10

#define BLUEMSYS_CHECK_CALIBRATION ((uint32_t)0x12345678)

#define BUTTON_TIME 1.0        // 1.0Sec
#define BLUEMSYS_N_BUTTON_PRESS  3  // n push button in BUTTON_TIME

#ifdef BLUEMSYS_STORE_CALIB_FLASH
#define BLUEMSYS_FLASH_ADD ((uint32_t)0x08060000)
#define BLUEMSYS_FLASH_SECTOR FLASH_SECTOR_7
#else /* BLUEMSYS_STORE_CALIB_FLASH */
#if defined (__IAR_SYSTEMS_ICC__)
__no_init uint32_t CalibrationStructureRAM[8];
#elif defined (__CC_ARM) 
uint32_t *CalibrationStructureRAM=(uint32_t *)0x20017FC0;
#elif defined (__GNUC__)
uint32_t CalibrationStructureRAM[8] __attribute__ ((section (".noinit")));
#else
#error "Toolchain not supported"
#endif
#endif /* BLUEMSYS_STORE_CALIB_FLASH */

#define BLE_ADVERTISING_INTERVAL    1000
//#define BLE_ADVERTISING_INTERVAL  160 /* 100ms; in multiples of 0.625ms. */

typedef enum ConnectionStatus_t {
    DISCONNECTED    =0,
    CONNECTED       =1
}cns_t;

const unsigned   LENGTH_OF_LONG_UUID = 16;
typedef uint16_t ShortUUIDBytes_t;
typedef uint8_t  LongUUIDBytes_t[LENGTH_OF_LONG_UUID];

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#endif // ifndef __MAIN_H__