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.

Revision:
20:b97e14ade434
Parent:
13:d00147d01d4e
Child:
26:1bc571e52ad9
--- a/main.h	Fri Jun 09 14:00:14 2017 +0200
+++ b/main.h	Wed Sep 20 17:08:56 2017 +0200
@@ -42,18 +42,18 @@
  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
 
+//#define USE_SENSOR_FUSION_LIB
 #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 USE_IKS01A2             // this MotionFX porting is for IKS01A2 only
+//#define CUST_CONFIG_SERV        // enable magnetometer calibration service
+//#define BLUEMSYS_STORE_CALIB_FLASH  // enable flash storage of calibration data only for 401RE
 #define CUST_SW_SERV            // enable quaternion service
 #endif
 
@@ -67,9 +67,19 @@
 #define MAX_I2C_SPEED               400000  
 #define NUCLEO_I2C_SHIELDS_SPEED    MAX_I2C_SPEED   // I2C speed in Hz
 
-#define ENV_TIMER       500000      // 500 mSec 
-#define CALIB_TIMER      40000      // 40mS
-#define MEMS_TIMER       10000      // 10mS
+#define ENV_TIMER        500      // 500 mSec 
+#define CALIB_TIMER      400      // 40mS
+#define MEMS_TIMER       10       // 10mS
+
+#define FROM_MG_TO_G                    0.001f
+#define FROM_G_TO_MG                    1000.0f
+#define FROM_MDPS_TO_DPS                0.001f
+#define FROM_DPS_TO_MDPS                1000.0f
+#define FROM_MGAUSS_TO_UT50             (0.1f/50.0f)
+#define FROM_UT50_TO_MGAUSS             500.0f
+
+#define MOTIONFX_ENGINE_DELTATIME       0.01f
+#define SAMPLE_PERIOD                   ((uint8_t)10)   /* [ms] */
 
 /*************** Don't Change the following defines *************/
 /* Calibration mask for Sensor fusion short precision */
@@ -84,7 +94,7 @@
 #define W2ST_COMMAND_CAL_STOP   0x01
 /****************************************************************/
 
-#define BLE_DEV_NAME "BlueMbed"
+#define BLE_DEV_NAME "BlueMbedOS"
 #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
@@ -94,19 +104,10 @@
 #define BUTTON_TIME 1.0        // 1.0Sec
 #define BLUEMSYS_N_BUTTON_PRESS  3  // n push button in BUTTON_TIME
 
+/** Valid only for F401RE **/ 
 #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_TX_SKIP_NUM   30
@@ -116,6 +117,21 @@
 #define BLE_HANDLE_EN_DIS_OFFSET  2  // Offset from En/Dis UUID 2902 to UUID 2803  (Characteristic UUID)
 #define BLE_HANDLE_VALUE_OFFSET   1  // Offset from Value UUID xxx to to UUID 2803 (Characteristic UUID) 
 
+#ifdef SENSOR_TILE
+#include <stdio.h>
+/* redirect printf on the Sensor Tile UART5 allowing printf throgh the Nucleo USB connector 
+(close the cradle and the Nucleo solder bridges to re-route the UART) */
+static Serial ser(PC_12,PD_2);    
+#define printf(...) ser.printf(__VA_ARGS__)     
+#endif
+
+
+typedef struct
+{
+  int32_t AXIS_X;
+  int32_t AXIS_Y;
+  int32_t AXIS_Z;
+} SensorAxes_t;
 
 typedef enum ConnectionStatus_t {
     DISCONNECTED    =0,
@@ -124,7 +140,7 @@
 
 const unsigned   LENGTH_OF_LONG_UUID = 16;
 typedef uint16_t ShortUUIDBytes_t;
-typedef uint8_t  LongUUIDBytes_t[LENGTH_OF_LONG_UUID];
+//typedef uint8_t  LongUUIDBytes_t[LENGTH_OF_LONG_UUID];
 
 #ifdef __cplusplus
 extern "C" {