This repository contains platform independent drivers for STMicroelectronics sensors. Sensor drivers and examples were written in C programming language.
This repository contains two types of folders, identifiable using the following naming convention:
-
folder that contains the sensor drivers, named
xxxxxxx_STdC
wherexxxxxxx
identifies the a sensor part number -
folder that contains the demo project, named
_prj_XXXXXXX
whereXXXXXXX
is the name of the ST evaluation board.
Every sensor driver folder contains:
xxxxxxx_STdC\driver
: the C sensor driver (.h and .c) to be included in your project. Driver documentation can be generated using the Doxigen tool.xxxxxxx_STdC\example
: examples showing how to integrate the C driver in a project. They are written for STM32 Microcontrollers using the STM32CubeMX tool, but they can be used as a guideline for every platform.- README: additional info about the specific driver.
Every demo project folder contains a single configuration file for the STM32CubeMX tool named _prj_XXXXXXX\XXXXXX.ioc
where XXXXXXX
is the name of the ST evaluation board.
Using the STM32CubeMX tool ( configured with the related MCU Package ) and the .ioc
file, it is possible to create a project in which you can easily run the examples available in each sensor drivers folder.
The driver is platform-independent, you only need to define the two functions for read and write transactions from the sensor hardware bus (ie. SPI or I²C).
-
Include in your project the driver files of Sensor (.h and .c) located in the
xxxxxxx_STdC\driver
folder of the corresponding product -
Define in your code the read and write functions that use the I²C or SPI platform driver like the following:
/** Please note that is MANDATORY: return 0 -> no Error.**/
int32_t platform_write(void *handle, uint8_t Reg, uint8_t *Bufp, uint16_t len)
int32_t platform_read(void *handle, uint8_t Reg, uint8_t *Bufp, uint16_t len)
- Declare and initialize the structure of device interface:
xxxxxxx_ctx_t dev_ctx; /** xxxxxxx is the used part number **/
dev_ctx.write_reg = platform_write;
dev_ctx.read_reg = platform_read;
- If needed by the platform read and write functions, initialize the handle parameter:
dev_ctx.handle = &platform_handle;
- A standard C language compiler for the target MCU
- A C library for the target MCU and the desired interface (ie. SPI, I2C)
They are written for STM32 Microcontrollers using STM32CubeMX tool, but they can be used as a guideline for every platform.
In case of using the supported STMicroelectronics evaluation boards the examples file(.c) can run without applying any modifications (as is).
In order to do that, please follow the following steps:
- Download and install STM32CubeMX tool and the related MCU package (i.e. STM32CubeF4 for NucleoF411 and STEVAL_MKI109V3).
- Open the
.ioc
configuration file associated to the selected evaluation board with the STM32CubeMX tool. The.ioc
configuration files for the supported evaluation boards can be found in the related ST evaluation board demo project folder. - Generate the project using the STM32CubeMX tool and select your preferred IDE / Toolchain.
- Add to your project the STMicroelectronics sensor driver. Driver files are located in the sensor drivers folder at
xxxxxxx_STdC\driver\xxxxxxx_reg.c(.h)
wherexxxxxxx
identifies the sensor part number. - Add to your project the example source file (.c) that you are interested in. Example files are located in the sensor drivers folder at
xxxxxxx_STdC\example
wherexxxxxxx
identifies a sensor part number. - Uncomment the selected board definition in section
/* STMicroelectronics evaluation boards definition */
in the selected example file (.c). - Add the call to the example function inside the
while(1)
loop in themain()
function themain.c
file automatically generated by the STM32CubeMX tool. - Enjoy :-)
If a different MCU is used, please follow these steps:
-
Add to your project the STMicroelectronics sensor driver. Driver files are located in the sensor drivers folder at
xxxxxxx_STdC\driver\xxxxxxx_reg.c(.h)
wherexxxxxxx
identifies a sensor part number. -
Add to your project the example source file (.c) that you are interested in. Example files are located in the sensor drivers folder at
xxxxxxx_STdC\example
wherexxxxxxx
identifies the sensor part number. -
Comment all the definitions of the boards in section `/* STMicroelectronics evaluation boards definition */ in the selected example file(.c).
-
Add the call to the example function inside the
while(1)
loop in yourmain()
function. -
Modify in the selected example file (.c) the hardware-related functions:
platform_write(void *handle, uint8_t Reg, uint8_t *Bufp,uint16_t len)
platform_read(void *handle, uint8_t Reg, uint8_t *Bufp, uint16_t len)
- if needed add/replace the hardware-related functions reported in the example file.
-
Enjoy :-)
More Information: http://www.st.com
Copyright (C) 2018 STMicroelectronics