logo资料库

AN4559应用笔记(DM00127351).pdf

第1页 / 共37页
第2页 / 共37页
第3页 / 共37页
第4页 / 共37页
第5页 / 共37页
第6页 / 共37页
第7页 / 共37页
第8页 / 共37页
资料共37页,剩余部分请下载后查看
1 Acronyms and abbreviations
2 Getting started
2.1 Hardware description
2.1.1 STM32L0 Nucleo
2.1.2 BlueNRG expansion board
2.1.3 BlueNRG USB dongle
2.2 Software description
2.2.1 STM32Cube
2.2.2 Firmware for STM32 Nucleo with X-NUCLEO-IDB04A1 expansion board
2.3 Hardware and software setup
2.3.1 Hardware setup
2.3.2 Software setup
2.3.3 System setup guide
3 Bluetooth low energy (BLE)
3.1 Bluetooth operating modes
3.2 Bluetooth low energy software partitioning
3.3 Profiles and services
3.4 Bluetooth low energy state machine
4 Software overview
4.1 Software architecture
4.2 STM32Cube HAL
4.3 Board support package (BSP)
4.4 BlueNRG HAL
4.5 ACI
5 Guide for writing applications
5.1 Relevant APIs for BlueNRG application
5.1.1 Initialization
5.1.2 Security requirements
5.1.3 Connectable mode
5.1.4 Connection with the central device
5.2 SensorDemo application description
5.3 Time service
5.3.1 Adding time service
5.3.2 Update and notify characteristic value
5.4 LED service
5.4.1 Adding GATT service and characteristics
5.4.2 Obtaining characteristic value
6 Testing the sample application
6.1 Testing the SensorDemo application using the BlueNRG GUI
6.1.1 Initializing the USB dongle
6.1.2 Scanning for a BLE peripheral device
6.1.3 Connecting to BLE peripheral device
6.1.4 Get services supported by a BLE peripheral device
6.1.5 Get characteristics supported by a BLE peripheral device
6.1.6 Read characteristic value
6.1.7 Write characteristic value
6.1.8 Obtain notification for a characteristic
6.1.9 Disconnecting from remote device
7 References
8 Revision history
AN4559 Application note Developer’s guide to creating Bluetooth® low energy applications using STM32 Nucleo and BlueNRG Hem Dutt Dabral and Mridupawan Das Introduction The purpose of the STMCube™ initiative by STMicroelectronics is help application developers to reduce development effort, time and cost. STM32Cube covers the STM32 microcontroller portfolio. STM32Cube Version 1.x includes: • The STM32CubeMX, a graphical software configuration tool that allows the generation of C initialization code using graphical wizards. • A comprehensive embedded software platform, delivered by series (i.e. the STM32CubeF4 for STM32F4 series) – The STM32Cube HAL, an STM32 abstraction-layer embedded software, ensuring optimized portability across STM32 portfolio. – A consistent set of middleware components such as RTOS, USB, TCP/IP, graphics – All embedded software utilities including a full set of examples. This application note describes how to develop a Bluetooth low energy application using the STM32 Nucleo platform and the BlueNRG expansion board (X-NUCLEO-IDB04A1), within the STM32Cube software environment. October 2014 DocID026739 Rev 1 1/37 www.st.com 37
Contents Contents AN4559 1 2 3 4 5 Acronyms and abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Hardware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1 STM32L0 Nucleo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1.1 2.1.2 BlueNRG expansion board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1.3 BlueNRG USB dongle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.2.1 STM32Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Firmware for STM32 Nucleo with X-NUCLEO-IDB04A1 expansion board 2.2.2 7 2.2 2.3 Hardware and software setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Hardware setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.3.1 Software setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.3.2 2.3.3 System setup guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Bluetooth low energy (BLE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Bluetooth operating modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.1 3.2 3.3 3.4 Bluetooth low energy software partitioning . . . . . . . . . . . . . . . . . . . . . . . . 10 Profiles and services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 Bluetooth low energy state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Software overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Software architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.1 4.2 4.3 4.4 4.5 STM32Cube HAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Board support package (BSP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 BlueNRG HAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 ACI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Guide for writing applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Relevant APIs for BlueNRG application . . . . . . . . . . . . . . . . . . . . . . . . . . 16 5.1 5.1.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Security requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 5.1.2 2/37 DocID026739 Rev 1
AN4559 Contents 5.2 5.3 5.4 5.1.3 Connectable mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 5.1.4 Connection with the central device . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 SensorDemo application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Time service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Adding time service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 5.3.1 5.3.2 Update and notify characteristic value . . . . . . . . . . . . . . . . . . . . . . . . . . 20 LED service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 5.4.1 Adding GATT service and characteristics . . . . . . . . . . . . . . . . . . . . . . . 23 Obtaining characteristic value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 5.4.2 Testing the sample application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Testing the SensorDemo application using the BlueNRG GUI . . . . . . . . . 27 6.1 Initializing the USB dongle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 6.1.1 6.1.2 Scanning for a BLE peripheral device . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Connecting to BLE peripheral device . . . . . . . . . . . . . . . . . . . . . . . . . . 29 6.1.3 Get services supported by a BLE peripheral device . . . . . . . . . . . . . . . 29 6.1.4 6.1.5 Get characteristics supported by a BLE peripheral device . . . . . . . . . . 30 Read characteristic value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 6.1.6 Write characteristic value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 6.1.7 6.1.8 Obtain notification for a characteristic . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Disconnecting from remote device . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 6.1.9 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 6 7 8 DocID026739 Rev 1 3/37 37
Acronyms and abbreviations AN4559 1 Acronyms and abbreviations Table 1. Acronyms and abbreviations Acronym Description ACI ATT BLE BLE BSP BT GAP Application controller interface Attribute protocol Bluetooth low energy Bluetooth low energy Board support package Bluetooth Generic access profile GATT Generic attribute profile GUI HAL HCI HRS IDE Graphical user interface Hardware abstraction layer Host controller interface Heart rate sensor Integrated development environment L2CAP Logical link control and adaptation protocol LED LL LPM MCU PCI PHY SIG SM SPI UUID Light emitting diode Link layer Low power manager Micro controller unit Profile command interface Physical layer Special interest group Security manager Serial peripheral interface Universally unique identifier 4/37 DocID026739 Rev 1
AN4559 Getting started 2 Getting started This application note describes how to develop a Bluetooth low energy application using the STM32 Nucleo platform and the BlueNRG expansion board (X-NUCLEO-IDB04A1), within the STM32Cube software environment. The BlueNRG is a very low power Bluetooth low energy (BLE) single-mode network processor, compliant with Bluetooth specifications core 4.0. 2.1 Hardware description This section describes the hardware components needed for developing a BLE application. The following sub-sections describe the individual components. 2.1.1 STM32L0 Nucleo The STM32 L0 Nucleo board is a development platform for low power applications that belongs to the STM32 Nucleo family. It provides an affordable and flexible way for users to try out new ideas and build prototypes with any of the STM32 microcontroller lines. The Arduino™ connectivity support and ST Morpho headers make it easy to expand the functionality of the Nucleo open development platform with a wide choice of specialized expansion boards. The STM32 Nucleo board does not require any separate probe as it integrates the ST-LINK/V2-1 debugger/programmer. The STM32 Nucleo board comes with the STM32 comprehensive HAL software library together with various packaged software examples. The STM32 Nucleo L0 firmware and related documentation is available on st.com at http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF260001. Figure 1. STM32 Nucleo board 2.1.2 BlueNRG expansion board The X-NUCLEO-IDB04A1 expansion board is compatible with the STM32 Nucleo boards. It contains a BlueNRG component, which is a BLE single-mode network processor, compliant DocID026739 Rev 1 5/37 37
Getting started AN4559 with Bluetooth specification v4.0. The BlueNRG can act as master or slave. The entire Bluetooth low energy stack runs on the embedded Cortex M0 core. The BlueNRG offers the option of interfacing with external microcontrollers using SPI transport layer. Figure 2. BlueNRG expansion board connected to STM32 Nucleo board The X-NUCLEO-IDB04A1 firmware and related documentation is available on st.com at http://www.st.com/web/en/catalog/tools/FM116/SC1075/PF260517. 2.1.3 BlueNRG USB dongle The STEVAL-IDB003V1 is an evaluation board based on BlueNRG, a low power Bluetooth Smart IC, compliant with the Bluetooth 4.0 specifications and supporting both master and slave roles. The STEVAL-IDB003V1 has a USB connector for PC GUI interaction and firmware update. Figure 3. STEVAL-IDB003V1 BlueNRG USB dongle The STEVAL-IDB003V1 evaluation board firmware and related documentation is available on st.com at http://www.st.com/web/en/catalog/tools/PF260386. 6/37 DocID026739 Rev 1
AN4559 2.2 Getting started Software description The following software components are needed in order to setup the suitable development environment for creating Bluetooth low energy applications: • STM32Cube environment and related firmware for STM32Nucleo and BlueNRG expansion board Development tool-chain and compiler. IAR embedded workbench is the development environment used for the applications described in this document. • 2.2.1 STM32Cube STM32Cube is a development framework which provides tools and libraries to develop C applications on STM32 series platforms. STM32Cube comprises the STM32CubeL0 platform which includes the STM32Cube HAL (an STM32 abstraction layer embedded software, ensuring maximized portability across STM32 portfolio), plus a consistent set of middleware components (such as RTOS, USB, FatFS and STM32 touch sensing). All embedded software utilities come with a full set of examples. STM32CubeL0 gathers in one single package all the generic embedded software components required to develop an application on STM32L0 microcontrollers. STM32CubeL0 is fully compatible with STM32CubeMX code generator that allows generating initialization code. The package includes a low level hardware abstraction layer (HAL) that covers the microcontroller hardware, together with an extensive set of examples running on STMicroelectronics boards. The HAL is available in open-source BSD license for developer convenience. The STM32CubeL0 firmware and related documentation is available on st.com at http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF260508. 2.2.2 Firmware for STM32 Nucleo with X-NUCLEO-IDB04A1 expansion board X-CUBE-BLE1 is a package that contains firmware with the STM32Cube framework compatible with the STM32 Nucleo and the X-NUCLEO-IDB0401 boards. This package contains some sample applications that are used to explain how to write Bluetooth low energy applications. The same sample applications are referenced in further sections of this document. The firmware and related documentation is available on st.com at http://www.st.com/web/en/catalog/tools/FM116/SC1075/PF260517. 2.3 Hardware and software setup This section describes hardware and software setup procedure for writing BLE applications. It also describes the system setup needed for the above. DocID026739 Rev 1 7/37 37
Getting started 2.3.1 Hardware setup AN4559 To develop a BLE application, the following hardware is needed: 1. One STM32 Nucleo development platform (suggested order code: NUCLEO- L053R8) 2. One BlueNRG expansion board (see Figure 1, order code: X-NUCLEO-IDB04A1) 3. One BlueNRG USB dongle (see Figure 4, order code: STEVAL-IDB003V1) 4. One USB type A to Mini-B USB cable to connect the Nucleo to the PC The BlueNRG USB dongle is not mandatory but is useful for testing BLE applications running on the Nucleo platform, as outlined in Section 6. 2.3.2 Software setup This section lists the minimum requirements for the developer to set up the SDK, run the sample testing scenario based on the GUI utility and customize applications. Development tool-chains and compilers IAR Embedded Workbench for ARM (EWARM) tool-chain V7.20 The IAR tool-chain has the following minimum requirements: • PC with Intel® or AMD® processor running one of the following Microsoft® operating systems – Windows XP SP3 – Windows Vista – Windows7 GUI utility The BlueNRG GUI utility has following minimum requirements: • PC with Intel or AMD processor running one of the following Microsoft operating system: – Windows XP SP3 – Windows Vista – Windows 7 At least 128 MB of RAM 2 USB ports 40 MB of hard disk space • • • 2.3.3 System setup guide This section describes how to set up different hardware parts before writing and executing an application on the STM32 Nucleo board with BlueNRG expansion board. BlueNRG USB dongle setup The BlueNRG USB dongle allows users to easily add BLE functionalities to a user PC by simply plugging it into a PC USB port. The USB dongle can be used as a simple interface between the BlueNRG device and a GUI application on the PC. The on-board STM32L microcontroller can also be programmed, so the board can be used to develop applications that need to use BlueNRG. The board can be powered through the USB connector, which 8/37 DocID026739 Rev 1
分享到:
收藏