logo资料库

AN4642应用笔记(DM00155171).pdf

第1页 / 共36页
第2页 / 共36页
第3页 / 共36页
第4页 / 共36页
第5页 / 共36页
第6页 / 共36页
第7页 / 共36页
第8页 / 共36页
资料共36页,剩余部分请下载后查看
1 BLE Profiles application for X-CUBE-BLE1, expansion for STM32Cube
1.1 Profiles application overview
1.1.1 Heart rate monitor
1.1.2 Health thermometer monitor
1.1.3 Glucose monitor
1.1.4 Blood pressure monitor
1.1.5 Find me
1.1.6 Alert notification
1.1.7 Time
1.1.8 Proximity
1.2 Software blocks
Figure 1. Profiles application SW architecture
1.2.1 Profile command interface (PCI)
1.2.2 Low Power Manager (LPM)
Figure 2. Overview of the low power manager
1.2.3 Low power manager API
1.2.4 BLE profile stack
1.2.5 BSP layer
1.3 BLE profiles application files
1.3.1 Heart rate monitor
1.3.2 Health thermometer monitor
1.3.3 Glucose monitor
1.3.4 Blood pressure monitor
1.3.5 Find me target
1.3.6 Alert notification server
1.3.7 Time server
1.3.8 Proximity reporter
1.4 BLE profile initialization
1.4.1 Generic initialization
1.4.2 BLE profile specific initialization
1.5 BLE profiles application state machine
1.5.1 HRM application state machine
Figure 3. HRM application state machine
1.5.2 HTM application state machine
Figure 4. HTM application state machine
1.5.3 GLM application state machine
Figure 5. GLM application state machine
1.5.4 BLP application state machine
Figure 6. BLP application state machine
1.5.5 FMT application state machine
Figure 7. FMT application state machine
1.5.6 ANS application state machine
Figure 8. ANS application state machine
1.5.7 Time server application state machine
Figure 9. Time server application state machine
1.5.8 PXP application state machine
Figure 10. PXP application state machine
1.6 MCU power modes
1.7 BLE profiles event handling
1.7.1 Generic events
1.7.2 Heart rate profile events
1.7.3 Health thermometer profile events
1.7.4 Glucose profile events
1.7.5 Blood pressure profile events
1.7.6 Find me profile events
1.7.7 Alert notification profile events
1.7.8 Time profile events
1.7.9 Proximity profile events
1.8 Running the BLE profiles application
1.8.1 Software setup on STM32 Nucleo
1.8.2 Starting the STM32 Nucleo and app
1.8.3 Software setup on the phone
1.8.4 Starting the phone Profiles App and connecting to central device
Figure 11. Splash screen of the profiles Android app
Figure 12. Screenshot of profiles app showing scanned HRS device
1.8.5 Reading HRM data on a smartphone
Figure 13. Screenshot of profiles app paired with HRS device
Figure 14. Screenshot of profiles app paired with HRS device and being notified
1.8.6 Reading HTM Data on smartphone
Figure 15. Screenshot of profiles app paired with HTS device
Figure 16. Screenshot of profiles app paired with HTS device and being notified
1.8.7 Reading GL Data on smartphone
Figure 17. Screenshot of profiles app paired with GL device
Figure 18. Screenshot of profiles app paired with GL device and being notified
1.8.8 Reading BLP Data on smartphone
Figure 19. Screenshot of profiles app paired with BLP device
Figure 20. Screenshot of profiles app paired with BLP device and being notified
1.8.9 Reading FMT Data on smartphone
Figure 21. Screenshot of profiles app paired with FMT device
Figure 22. Screenshot of profiles app paired with FMT device and respective actions
1.8.10 Reading ANS Data on smartphone
Figure 23. Screenshot of profiles app paired with ANS device
Figure 24. Screenshot of profiles app paired with ANS device and respective actions
1.8.11 Reading TS Data on smartphone
Figure 25. Screenshot of profiles app paired with TS device
Figure 26. Screenshot of profiles app paired with TS device and being notified
1.8.12 Reading PXP Data on smartphone
Figure 27. Screenshot of profiles app paired with PXR device
Figure 28. Screenshot of profiles app paired with PXR device and respective actions
2 System setup guide
2.1 Hardware requirements
2.1.1 STM32 Nucleo platform
Figure 29. STM32 nucleo board
2.1.2 X-NUCLEO-IDB04A1 STM32 expansion board
Figure 30. X-NUCLEO-IDB04A1 STM32 expansion board
2.1.3 Android Smartphone
2.2 Software requirements
2.2.1 Software application
2.2.2 Android app
3 Acronyms and abbreviations
Table 1. Acronyms
4 References
5 Revision history
Table 2. Document revision history
AN4642 Application note Overview of the BLE Profiles application for X-CUBE-BLE1, expansion for STM32Cube Introduction This document describes the BLE Profiles application for X-CUBE-BLE1. X-CUBE-BLE1 provides the complete STM32 middleware to build applications based on Bluetooth Low Energy. It is highly portable across different MCU families thanks to STM32Cube. The software: • provides implementation examples for STM32 Nucleo platforms equipped with the X-NUCLEO-IDB04A1 STM32 expansion board is based on STM32Cube technology and extends STM32Cube-based packages • Information regarding STM32Cube is available on st.com at: http://www.st.com/stm32cube. March 2015 DocID027341 Rev 1 1/36 www.st.com 36
Contents Contents AN4642 1 1.2 BLE Profiles application for X-CUBE-BLE1, expansion for STM32Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Profiles application overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.1 Heart rate monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.1.1 Health thermometer monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.1.2 1.1.3 Glucose monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Blood pressure monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.1.4 Find me . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.1.5 1.1.6 Alert notification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.1.7 1.1.8 Proximity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Software blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Profile command interface (PCI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.2.1 Low Power Manager (LPM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.2.2 1.2.3 Low power manager API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 BLE profile stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.2.4 1.2.5 BSP layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 BLE profiles application files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Heart rate monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.3.1 Health thermometer monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.3.2 1.3.3 Glucose monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Blood pressure monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.3.4 1.3.5 Find me target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Alert notification server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.3.6 Time server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.3.7 1.3.8 Proximity reporter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 BLE profile initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 Generic initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.4.1 1.4.2 BLE profile specific initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 BLE profiles application state machine . . . . . . . . . . . . . . . . . . . . . . . . . . 12 HRM application state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.5.1 1.5.2 HTM application state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 GLM application state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.5.3 1.5.4 BLP application state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 1.3 1.4 1.5 2/36 DocID027341 Rev 1
AN4642 Contents 1.6 1.7 1.8 1.5.5 FMT application state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.5.6 ANS application state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.5.7 Time server application state machine . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.5.8 PXP application state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 MCU power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 BLE profiles event handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Generic events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 1.7.1 Heart rate profile events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 1.7.2 1.7.3 Health thermometer profile events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Glucose profile events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 1.7.4 1.7.5 Blood pressure profile events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Find me profile events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 1.7.6 Alert notification profile events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 1.7.7 1.7.8 Time profile events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 1.7.9 Proximity profile events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Running the BLE profiles application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 1.8.1 Software setup on STM32 Nucleo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Starting the STM32 Nucleo and app . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 1.8.2 Software setup on the phone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 1.8.3 1.8.4 Starting the phone Profiles App and connecting to central device . . . . . 23 Reading HRM data on a smartphone . . . . . . . . . . . . . . . . . . . . . . . . . . 23 1.8.5 Reading HTM Data on smartphone . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 1.8.6 1.8.7 Reading GL Data on smartphone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Reading BLP Data on smartphone . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 1.8.8 Reading FMT Data on smartphone . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 1.8.9 1.8.10 Reading ANS Data on smartphone . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Reading TS Data on smartphone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 1.8.11 1.8.12 Reading PXP Data on smartphone . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2 System setup guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 2.1 2.1.1 STM32 Nucleo platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 X-NUCLEO-IDB04A1 STM32 expansion board . . . . . . . . . . . . . . . . . . 31 2.1.2 2.1.3 Android Smartphone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Software requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Software application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.2.1 2.2.2 Android app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.2 DocID027341 Rev 1 3/36 36
Contents 3 4 5 AN4642 Acronyms and abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 4/36 DocID027341 Rev 1
AN4642 BLE Profiles application for X-CUBE-BLE1, expansion for STM32Cube 1 1.1 BLE Profiles application for X-CUBE-BLE1, expansion for STM32Cube Profiles application overview This chapter describes the BLE Profiles example application running on STM32 Nucleo board connected with an X-NUCLEO-IDB04A1 STM32 expansion board. This application is included as part of the STM32Cube firmware for the X-CUBE-BLE1. It is assumed that the reader has prior knowledge of the Bluetooth Low Energy protocol and its application profiles. The current software release supports the following BLE profiles: • Heart Rate • Health Thermometer • Glucose • Blood Pressure • Find Me • Alert Notification • Time • Proximity The application is based on the standard GATT-based profiles (https://developer.bluetooth.org/TechnologyOverview/Pages/Profiles.aspx) described in the Bluetooth SIG specifications. Please refer to [3] for information on getting started and for details regarding BLE application development for STM32 Nucleo boards equipped with an X-NUCLEO-IDB04A1 STM32 expansion board. The STM32 Nucleo device acts as the GAP peripheral device running the BLE Profiles application. It sends profile-related data to the GAP central device (the collector), which is an Android smartphone in this case. Please refer to Section 2 for details about system setup and configuration. The following sub-sections briefly describe the interaction between the peripheral and the central devices for each BLE Profile. 1.1.1 Heart rate monitor The Heart Rate Monitor (HRM) application runs the Heart Rate Profile described in the Bluetooth Profile Specifications. It exposes the Heart Rate Service and enables the role of the Heart Rate Sensor (HRS) in the STM32 Nucleo device. The application sends periodic data to simulate heart rate measurements as the actual sensor is not present on the STM32 Nucleo board. Any central device running the Heart Rate Profile can collect data from the Heart Rate Monitor. DocID027341 Rev 1 5/36 36
BLE Profiles application for X-CUBE-BLE1, expansion for STM32Cube AN4642 1. The HRS initializes the Heart Rate Profile and starts advertising its address and services. 2. The Collector scans for a HRS device and sends a connection request if it detects one. 3. Once connection is established, the HRS sends data over the connection link. 1.1.2 Health thermometer monitor The Health Thermometer Monitor (HTM) application runs the Health Thermometer Profile described in the Bluetooth Profile Specifications. It exposes the Health Thermometer Service and enables the role of the Health Thermometer Sensor (HTS) in the STM32 Nucleo device. The application sends periodic data to simulate body temperature readings as an actual temperature sensor is not present on the STM32 Nucleo board. Any central device running the Health Thermometer Profile can collect data from the Health Thermometer Monitor. 1. The HTS device initializes the Health Thermometer Profile and starts advertising its address and services. 2. The Collector scans for an HTS and sends a connection request if it detects one. 3. Once connection is established, the HTS sends data over the connection link. 1.1.3 Glucose monitor The Glucose Monitor (GLM) application runs the Glucose Profile as described in the Bluetooth Profile Specifications. It exposes the Glucose Service and enables the role of the Glucose Sensor (GLS) in the STM32 Nucleo device. The application sends periodic data to simulate glucose concentration readings as an actual glucose sensor is not present on the STM32 Nucleo board. Other information describing the sensor position and its supported features is also transmitted. Any central device running the Glucose Profile can collect data from the Glucose Monitor. 1. The GLS initializes the Glucose Profile and then starts advertising its address and services. 2. The Collector scans for a GLS and sends a connection request if it detects one. 3. Once connection is established, the GLS sends data over the connection link. 1.1.4 Blood pressure monitor The Blood Pressure Monitor (BLP) application runs the Blood Pressure Profile as described in the Bluetooth Profile Specifications. It exposes the Blood Pressure Service and enables the role of the Blood Pressure Sensor (BLS) in the STM32 Nucleo device. The application sends periodic data to simulate blood pressure readings (and related data) as an actual blood pressure sensor is not present on the STM32 Nucleo board. Any central device running the Blood Pressure Profile can collect data from the Blood Pressure Monitor. 1. The BLS initializes the Blood Pressure Profile and begins advertising its address and services. 2. The Collector scans for a BLS and sends a connection request if it detects one. 3. Once connection is established, the BLS sends data over the connection link. 6/36 DocID027341 Rev 1
AN4642 BLE Profiles application for X-CUBE-BLE1, expansion for STM32Cube 1.1.5 Find me The Find Me (FMT) application runs the Find Me Profile described in the Bluetooth Profile Specifications. It exposes and enables the role of the Find Me Target (FMT) in the STM32 Nucleo device. It causes the STM32 Nucleo board to produce an alert signal (blinking LED) when a button is pressed on a Find Me Locator device (when acting as the central device). 1. 2. The Locator scans for an FMT and sends a connection request if it detects one. The FMT device initializes the profile and starts advertising its address and services. 1.1.6 Alert notification The Alert Notification (ANS) application runs the Alert Notification Profile described in the Bluetooth Profile Specifications. It exposes and enables the role of the Alert Notification Server (ANS) in the STM32 Nucleo device. A client device can receive different types of alerts and event information, as well as information on the count of new alerts and unread items in the server device (the STM32 Nucleo board). To demonstrate the function, the ANS exposes the "New email" alert with a sample text message. Any central device running the Alert Notification Client is notified when a new email is received. 1. The ANS device initializes the profile and then starts advertising its address and services. 2. The Client device scans for an ANS device and sends a connection request if it detects one, so it can enable alert notification. 1.1.7 Time The Time (TIP) application runs the Time Profile described in the Bluetooth Profile Specifications. It exposes and enables the role of the Time Server (TS) in the STM32 Nucleo device. A client device (when acting as the central device) can obtain date and time, and related information exposed by the Current Time Service in the STM32 Nucleo device. 1. The TS device initializes the profile and then starts advertising its address and services. 2. The Time Client scans for a TS and sends a connection request if it detects one, so it can obtain date and time data. 1.1.8 Proximity The Proximity (PXP) application runs the Proximity Profile described in the Bluetooth Profile Specifications. It exposes and enables the role of the Proximity Reporter in the STM32 Nucleo device. A device running the Proximity Monitor can immediately signal when a peer device moves away and the connection drops or when the path loss exceeds a pre-defined threshold. 1. The Proximity Reporter initializes the profile and then starts advertising its address and services. 2. The Monitor scans for a PXR and sends a connection request if it detects one, to enable alert notifications and/or set the path loss level. DocID027341 Rev 1 7/36 36
BLE Profiles application for X-CUBE-BLE1, expansion for STM32Cube AN4642 1.2 Software blocks This section describes the software layers (shown in the diagram below) present in the BLE Profiles application, running on an STM32 Nucleo development board with the STM32Cube software environment. The most important layers are: • the STM32Cube HAL layer • the Board Support Package (BSP) layer • the BlueNRG HAL layer • the Profile Command Interface (PCI) layer • the GATT profile • the BLE profile stack • the BLE Profiles application The PCI and GATT rely on the HCI layer to send BLE commands to the BlueNRG STM32 expansion board. The Generic Attribute (GATT) profile uses both PCI API and HCI to send BLE commands to the BlueNRG STM32 expansion board. Figure 1. Profiles application SW architecture The most important software layers for the application are briefly described below. 1.2.1 Profile command interface (PCI) The Profile Command Interface (PCI) is the main API for all applications that use the GATT- based profiles on the BlueNRG device. The PCI exposes the APIs used to send commands to the BlueNRG STM32 expansion board. 1.2.2 Low Power Manager (LPM) The Low Power Manager lets the application allow the system drop to low-power states whenever necessary conditions are met. The Low Power Manager provides a set of APIs that enable the application to support active power management. 8/36 DocID027341 Rev 1
分享到:
收藏