
Mbed OS and Pelion Device Management example over WIFI for DISCO_L475VG_IOT01 board
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
DEPRECATED
This example application is not maintained and not recommended. It uses an old version of Mbed OS, Pelion DM and Arm toolchain. It doesn't work with Mbed Studio.
Please use: https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-pelion/
This example is known to work on the following platforms:
- DISCO_L475E_IOT01A over WiFI and using onboard QSPI flash.
Follow the Quick-Start instructions: https://cloud.mbed.com/quick-start
Example functionality
This example showcases the following device functionality:
- Read onboard temperature and humidity sensors, and report them as Pelion LWM2M resources (see image below).
- On user button click, increment Pelion LWM2M button resource.
- Allow the user to change the state of the board LED from Pelion LWM2M led_state resource and PUT request.
- Uses all onboard sensors and reports them as Pelion LWM2M resources.
Use this example with Mbed CLI
1. Import the application into your desktop:
mbed import https://os.mbed.com/teams/ST/code/pelion-example-disco-iot01 cd pelion-example-disco-iot01
2. Install the CLOUD_SDK_API_KEY
mbed config -G CLOUD_SDK_API_KEY <PELION_DM_API_KEY>
For instructions on how to generate your API key, please see the documentation.
3. Initialize firmware credentials (done once per repository). You can use the following command:
mbed dm init -d "<your company name in Pelion DM>" --model-name "<product model identifier>" -q --force
If above command do not work for your Mbed CLI, please consider upgrading Mbed CLI to version 1.8.x or above.
4. Compile and program:
mbed compile -t <toolchain> -m DISCO_L475VG_IOT01A
(supported toolchains : GCC_ARM / ARM / IAR)
5. You can connect on a virtual terminal/COM port to the platform using:
mbed sterm -b 115200
This should give you an output similar to:
[BOOT] Mbed Bootloader [BOOT] ARM: 00000000000000000000 [BOOT] OEM: 00000000000000000000 [BOOT] Layout: 0 80096F4 [BOOT] Active firmware integrity check: [BOOT] SHA256: 0660E360D432225D5251461998FD8617B017098C5F1F90D5FB607BF8C27ED530 [BOOT] Version: 1553615309 [BOOT] Slot 0 is empty [BOOT] Active firmware up-to-date [BOOT] Application's start address: 0x8010400 [BOOT] Application's jump address: 0x8011041 [BOOT] Application's stack address: 0x20018000 [BOOT] Forwarding to application... Starting Simple Pelion Device Management Client example You can hold the user button during boot to format the storage and change the device identity. Sensors configuration: Invalid new address! HTS221 humidity & temperature = 0xBC LPS22HB pressure & temperature = 0xB1 LIS3MDL magnetometer = 0x3D LSM6DSL accelerometer & gyroscope = 0x6A Connecting to the network using Wifi... Connected to the network successfully. IP address: 192.168.1.3 Initializing Pelion Device Management Client... Initialized Pelion Client. Registering... Registered to Pelion Device Management. Endpoint Name: 0169********************001002d5 ADC temp: 23.0037 C, vref: 0.3661 V HTS221 temp: 28.700 C, humidity: 31.90 % LPS22HB temp: 29.600 C, pressure: 1032.01 mbar LIS3MDL mag: 0.217 x, -0.284 y, -0.053 z [gauss] LSM6DSL acc: 0.005 x, -0.014 y, 1.029 z [g] LSM6DSL gyro: 0.910 x, -0.910 y, 1.120 z [dps] VL53L0X dist: 1855 mm
sensors/VL53L0X/VL53L0X_i2c_platform.h
- Committer:
- chris
- Date:
- 2020-03-13
- Revision:
- 36:aaf44d2a6c33
- Parent:
- 18:a15bfe7aaebd
File content as of revision 36:aaf44d2a6c33:
/* * COPYRIGHT (C) STMicroelectronics 2014. All rights reserved. * * This software is the confidential and proprietary information of * STMicroelectronics ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with STMicroelectronics * * Programming Golden Rule: Keep it Simple! * */ /** * @file VL53L0X_platform.h * @brief Function prototype definitions for Ewok Platform layer. * */ #ifndef _VL53L0X_I2C_PLATFORM_H_ #define _VL53L0X_I2C_PLATFORM_H_ #include "VL53L0X_def.h" #ifdef __cplusplus extern "C" { #endif // Include uint8_t, unit16_t etc definitions #include <stdint.h> #include <stdarg.h> /** * @brief Typedef defining .\n * The developer shoud modify this to suit the platform being deployed. * */ // enum {TRUE = true, FALSE = false}; /** * @brief Typedef defining 8 bit unsigned char type.\n * The developer shoud modify this to suit the platform being deployed. * */ #ifndef bool_t typedef unsigned char bool_t; #endif #define I2C 0x01 #define SPI 0x00 #define COMMS_BUFFER_SIZE 64 // MUST be the same size as the SV task buffer #define BYTES_PER_WORD 2 #define BYTES_PER_DWORD 4 #define VL53L0X_MAX_STRING_LENGTH_PLT 256 /** * @brief Initialise platform comms. * * @param comms_type - selects between I2C and SPI * @param comms_speed_khz - unsigned short containing the I2C speed in kHz * * @return status - status 0 = ok, 1 = error * */ int32_t VL53L0X_comms_initialise(uint8_t comms_type, uint16_t comms_speed_khz); /** * @brief Initialise platform serial comms. * * @param comPortStr - String to indicate the comm port * @param baudRate - Bau rate * * @return status - status 0 = ok, 1 = error * */ int VL53L0_i2c_init(char *comPortStr, unsigned int baudRate); /** * @brief Close platform comms. * * @return status - status 0 = ok, 1 = error * */ int32_t VL53L0X_comms_close(void); /** * @brief Cycle Power to Device * * @return status - status 0 = ok, 1 = error * */ int32_t VL53L0X_cycle_power(void); /** * @brief Writes the supplied byte buffer to the device * * Wrapper for SystemVerilog Write Multi task * * @code * * Example: * * uint8_t *spad_enables; * * int status = VL53L0X_write_multi(RET_SPAD_EN_0, spad_enables, 36); * * @endcode * * @param address - uint8_t device address value * @param index - uint8_t register index value * @param pdata - pointer to uint8_t buffer containing the data to be written * @param count - number of bytes in the supplied byte buffer * * @return status - SystemVerilog status 0 = ok, 1 = error * */ int32_t VL53L0X_write_multi(uint8_t address, uint8_t index, uint8_t *pdata, int32_t count); /** * @brief Reads the requested number of bytes from the device * * Wrapper for SystemVerilog Read Multi task * * @code * * Example: * * uint8_t buffer[COMMS_BUFFER_SIZE]; * * int status = status = VL53L0X_read_multi(DEVICE_ID, buffer, 2) * * @endcode * * @param address - uint8_t device address value * @param index - uint8_t register index value * @param pdata - pointer to the uint8_t buffer to store read data * @param count - number of uint8_t's to read * * @return status - SystemVerilog status 0 = ok, 1 = error * */ int32_t VL53L0X_read_multi(uint8_t address, uint8_t index, uint8_t *pdata, int32_t count); /** * @brief Writes a single byte to the device * * Wrapper for SystemVerilog Write Byte task * * @code * * Example: * * uint8_t page_number = MAIN_SELECT_PAGE; * * int status = VL53L0X_write_byte(PAGE_SELECT, page_number); * * @endcode * * @param address - uint8_t device address value * @param index - uint8_t register index value * @param data - uint8_t data value to write * * @return status - SystemVerilog status 0 = ok, 1 = error * */ int32_t VL53L0X_write_byte(uint8_t address, uint8_t index, uint8_t data); /** * @brief Writes a single word (16-bit unsigned) to the device * * Manages the big-endian nature of the device (first byte written is the MS byte). * Uses SystemVerilog Write Multi task. * * @code * * Example: * * uint16_t nvm_ctrl_pulse_width = 0x0004; * * int status = VL53L0X_write_word(NVM_CTRL__PULSE_WIDTH_MSB, nvm_ctrl_pulse_width); * * @endcode * * @param address - uint8_t device address value * @param index - uint8_t register index value * @param data - uin16_t data value write * * @return status - SystemVerilog status 0 = ok, 1 = error * */ int32_t VL53L0X_write_word(uint8_t address, uint8_t index, uint16_t data); /** * @brief Writes a single dword (32-bit unsigned) to the device * * Manages the big-endian nature of the device (first byte written is the MS byte). * Uses SystemVerilog Write Multi task. * * @code * * Example: * * uint32_t nvm_data = 0x0004; * * int status = VL53L0X_write_dword(NVM_CTRL__DATAIN_MMM, nvm_data); * * @endcode * * @param address - uint8_t device address value * @param index - uint8_t register index value * @param data - uint32_t data value to write * * @return status - SystemVerilog status 0 = ok, 1 = error * */ int32_t VL53L0X_write_dword(uint8_t address, uint8_t index, uint32_t data); /** * @brief Reads a single byte from the device * * Uses SystemVerilog Read Byte task. * * @code * * Example: * * uint8_t device_status = 0; * * int status = VL53L0X_read_byte(STATUS, &device_status); * * @endcode * * @param address - uint8_t device address value * @param index - uint8_t register index value * @param pdata - pointer to uint8_t data value * * @return status - SystemVerilog status 0 = ok, 1 = error * */ int32_t VL53L0X_read_byte(uint8_t address, uint8_t index, uint8_t *pdata); /** * @brief Reads a single word (16-bit unsigned) from the device * * Manages the big-endian nature of the device (first byte read is the MS byte). * Uses SystemVerilog Read Multi task. * * @code * * Example: * * uint16_t timeout = 0; * * int status = VL53L0X_read_word(TIMEOUT_OVERALL_PERIODS_MSB, &timeout); * * @endcode * * @param address - uint8_t device address value * @param index - uint8_t register index value * @param pdata - pointer to uint16_t data value * * @return status - SystemVerilog status 0 = ok, 1 = error * */ int32_t VL53L0X_read_word(uint8_t address, uint8_t index, uint16_t *pdata); /** * @brief Reads a single dword (32-bit unsigned) from the device * * Manages the big-endian nature of the device (first byte read is the MS byte). * Uses SystemVerilog Read Multi task. * * @code * * Example: * * uint32_t range_1 = 0; * * int status = VL53L0X_read_dword(RANGE_1_MMM, &range_1); * * @endcode * * @param address - uint8_t device address value * @param index - uint8_t register index value * @param pdata - pointer to uint32_t data value * * @return status - SystemVerilog status 0 = ok, 1 = error * */ int32_t VL53L0X_read_dword(uint8_t address, uint8_t index, uint32_t *pdata); /** * @brief Implements a programmable wait in us * * Wrapper for SystemVerilog Wait in micro seconds task * * @param wait_us - integer wait in micro seconds * * @return status - SystemVerilog status 0 = ok, 1 = error * */ int32_t VL53L0X_platform_wait_us(int32_t wait_us); /** * @brief Implements a programmable wait in ms * * Wrapper for SystemVerilog Wait in milli seconds task * * @param wait_ms - integer wait in milli seconds * * @return status - SystemVerilog status 0 = ok, 1 = error * */ int32_t VL53L0X_wait_ms(int32_t wait_ms); /** * @brief Set GPIO value * * @param level - input level - either 0 or 1 * * @return status - SystemVerilog status 0 = ok, 1 = error * */ int32_t VL53L0X_set_gpio(uint8_t level); /** * @brief Get GPIO value * * @param plevel - uint8_t pointer to store GPIO level (0 or 1) * * @return status - SystemVerilog status 0 = ok, 1 = error * */ int32_t VL53L0X_get_gpio(uint8_t *plevel); /** * @brief Release force on GPIO * * @return status - SystemVerilog status 0 = ok, 1 = error * */ int32_t VL53L0X_release_gpio(void); /** * @brief Get the frequency of the timer used for ranging results time stamps * * @param[out] ptimer_freq_hz : pointer for timer frequency * * @return status : 0 = ok, 1 = error * */ int32_t VL53L0X_get_timer_frequency(int32_t *ptimer_freq_hz); /** * @brief Get the timer value in units of timer_freq_hz (see VL53L0X_get_timestamp_frequency()) * * @param[out] ptimer_count : pointer for timer count value * * @return status : 0 = ok, 1 = error * */ int32_t VL53L0X_get_timer_value(int32_t *ptimer_count); #ifdef __cplusplus } #endif #endif //_VL53L0X_I2C_PLATFORM_H_