Guide for writing applications AN4594
10/16 DocID026958 Rev 1
4 Guide for writing applications
This chapter describes how to write applications which use sensors, based on the STM32
Nucleo board equipped with the sensor expansion board.
4.1 Relevant APIs for sensor applications
This section describes generic initialization and setup for writing sensor expansion board
applications.
4.1.1 Initialization
Every application must first execute the following basic initialization steps in order to
configure and set up the STM32 Nucleo with the sensor expansion board hardware and the
software stack for correct operation.
Initializing STM32Cube HAL
The STM32Cube HAL library must be initialized so that the necessary hardware
components are correctly configured.
• HAL_Init();
This API initializes the HAL library: it configures Flash prefetch, Flash preread and
Buffer Cache0; it also configures the time base source, vectored interrupt controller
and low-level hardware.
Initializing Nucleo board peripherals and sensor expansion board
Some of the Nucleo on-board peripherals, hardware and the sensor expansion board must
be configured before they are used. The functions to do this are:
• BSP_LED_Init(Led_TypeDef Led);
This API configures the LED on the Nucleo.
• BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode);
This API configures the user button in GPIO mode or in external interrupt (EXTI) mode.
• BSP_HUM_TEMP_isInitialized()
This API configures the temperature sensor (hts221) on the sensor expansion board.
• BSP_PRESSURE_isInitialized()
This API configures the pressure sensor (lps25h) on the sensor expansion board.
• BSP_IMU_6AXES_isInitialized()
This API configures accelerometer and gyroscope sensor (LSM6DS0) on the sensor
expansion board.
• BSP_MAGNETO_isInitialized
This API configures magnetometer sensor (LIS3MDL) on the sensor expansion board.