TELINK SEMICONDUCTOR TLSR8232 Installation and operating instructions

Application Note
Telink TLSR8232 BLE SDK
Developer Handbook
AN-19112700-E1
TELINK SEMICONDUCTOR
Brief:
This document is the developer guide for TLSR8232
BLE SDK 1.3.0.
Version 1.0.0
2019-11-27

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 1 Ver.1.0.0
Published by
Telink Semiconductor
Bldg 3, 1500 Zuchongzhi Rd,
Zhangjiang Hi-Tech Park, Shanghai, China
© Telink Semiconductor
All Right Reserved
Legal Disclaimer
This document is provided as-is. Telink Semiconductor reserves the right to make
improvements without further notice to this document or any products herein. This
document may contain technical inaccuracies or typographical errors. Telink
Semiconductor disclaims any and all liability for any errors, inaccuracies or
incompleteness contained herein.
Copyright © 2019 Telink Semiconductor (Shanghai) Ltd, Co.
Information:
For further information on the technology, product and business term, please contact
Telink Semiconductor Company (www.telink-semi.com).
For sales or technical support, please send email to the address of:
telinkcnsales@telink-semi.com
telinkcnsupport@telink-semi.com

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 2 Ver.1.0.0
Revision History
Version 1.0.0 (2019-11-27)
This is the Initial release.

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 3 Ver.1.0.0
Contents
Revision History...................................................................................................................2
Contents...............................................................................................................................3
Contents of Figures ...........................................................................................................11
1. SDK Overview................................................................................................................14
1.1 Software Architecture...........................................................................................14
1.1.1 main.c.........................................................................................................15
1.1.2 app_config.h...............................................................................................16
1.1.3 Application File...........................................................................................16
1.1.4 BLE Stack Entry.........................................................................................16
1.2 Applied ICs...........................................................................................................17
1.3 library....................................................................................................................17
1.4 Demo....................................................................................................................18
1.4.1 BLE Slave Demo........................................................................................19
1.4.2 Other Demos..............................................................................................20
2. MCU Basic Modules......................................................................................................21
2.1 MCU Address Space............................................................................................21
2.1.1 MCU Address Space Allocation.................................................................21
2.1.2 SRAM Space Allocation.............................................................................21
2.1.2.1 SRAM and Firmware Space............................................................21
2.1.2.2 list File Analysis Demo.....................................................................25
2.1.3 MCU Address Space Access.....................................................................29
2.1.3.1 Peripheral Space Access ................................................................29
2.1.3.2 Flash Space Operation....................................................................30
2.1.4 SDK Flash Space Allocation......................................................................32
2.1.4.1 Space Allocation of 512kB Flash.....................................................33
2.1.4.2 Space Allocation of 128kB Flash.....................................................35
2.2 Clock Module........................................................................................................37
2.2.1 System Clock & System Timer ..................................................................37
2.2.2 System Timer Usage..................................................................................39
2.3 GPIO Module........................................................................................................40
2.3.1 GPIO Definition..........................................................................................40
2.3.2 GPIO State Control....................................................................................40
2.3.3 GPIO Initialization ......................................................................................42

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 4 Ver.1.0.0
2.3.4 Configure SWS Pull-up to Avoid MCU Errors............................................43
3. BLE Module ...................................................................................................................44
3.1 BLE SDK Software Architecture...........................................................................44
3.1.1 Standard BLE SDK Architecture................................................................44
3.1.2 Telink BLE SDK Architecture.....................................................................45
3.1.2.1 Telink BLE Controller.......................................................................45
3.1.2.2 5316 BLE Slave...............................................................................46
3.2 BLE Controller......................................................................................................47
3.2.1 BLE Controller Introduction........................................................................47
3.2.2 Link Layer State Machine ..........................................................................47
3.2.3 Link Layer State Machine Combined Application......................................49
3.2.3.1 Link Layer State Machine Initialization............................................49
3.2.3.2 Idle + Advertising.............................................................................50
3.2.3.3 Idle + Advertising + ConnSlaveRole................................................50
3.2.4 Link Layer Timing Sequence .....................................................................51
3.2.4.1 Timing Sequence in Idle State.........................................................52
3.2.4.2 Timing Sequence in Advertising State ............................................52
3.2.4.3 Timing Sequence in Conn state Slave Role....................................53
3.2.4.4 Conn State Slave Role Timing Protection.......................................54
3.2.5 Link Layer TX FIFO & RX FIFO.................................................................55
3.2.6 Controller HCI Event..................................................................................58
3.2.6.1 HCI Event.........................................................................................59
3.2.6.2 HCI LE Event...................................................................................60
3.2.7 Telink Defined Event..................................................................................62
3.2.7.1 BLT_EV_FLAG_ADV.......................................................................65
3.2.7.2 BLT_EV_FLAG_ADV_DURATION_TIMEOUT...............................65
3.2.7.3 BLT_EV_FLAG_SCAN_RSP ..........................................................65
3.2.7.4 BLT_EV_FLAG_CONNECT............................................................65
3.2.7.5 BLT_EV_FLAG_TERMINATE.........................................................66
3.2.7.6 BLT_EV_FLAG_ENCRYPTION_CONN_DONE.............................67
3.2.7.7 BLT_EV_FLAG_DATA_LENGTH_EXCHANGE.............................67
3.2.7.8 BLT_EV_FLAG_GPIO_EARLY_WAKEUP.....................................68
3.2.7.9 BLT_EV_FLAG_CHN_MAP_REQ ..................................................69
3.2.7.10 BLT_EV_FLAG_CHN_MAP_UPDATE .........................................69

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 5 Ver.1.0.0
3.2.7.11 BLT_EV_FLAG_CONN_PARA_REQ ...........................................69
3.2.7.12 BLT_EV_FLAG_CONN_PARA_UPDATE.....................................70
3.2.7.13 BLT_EV_FLAG_SUSPEND_ENETR............................................70
3.2.7.14 BLT_EV_FLAG_SUSPEND_EXIT ................................................70
3.2.7.15 BLT_EV_FLAG_PHY_UPDATE....................................................70
3.2.8 Controller API.............................................................................................71
3.2.8.1 Controller API Brief..........................................................................71
3.2.8.2 API Return Type ble_sts_t...............................................................71
3.2.8.3 MAC Address Initialization...............................................................71
3.2.8.4 Link Layer State Machine Initialization............................................72
3.2.8.5 bls_ll_setAdvData............................................................................72
3.2.8.6 bls_ll_setScanRspData....................................................................73
3.2.8.7 bls_ll_setAdvParam.........................................................................74
3.2.8.8 bls_ll_setAdvEnable ........................................................................78
3.2.8.9 bls_ll_setAdvDuration......................................................................78
3.2.8.10 blc_ll_setAdvCustomedChannel....................................................79
3.2.8.11 rf_set_power_level_index..............................................................79
3.2.8.12 bls_ll_terminateConnection...........................................................80
3.2.8.13 Get Connection Parameters..........................................................81
3.2.8.14 blc_ll_getCurrentState...................................................................81
3.2.8.15 blc_ll_getLatestAvgRSSI...............................................................81
3.2.8.16 Whitelist & Resolvinglist.................................................................82
3.2.9 2M PHY Supported....................................................................................83
3.2.10 Data Length Extension.............................................................................84
3.3 L2CAP ..................................................................................................................85
3.3.1 Register L2CAP Data Processing Function...............................................86
3.3.2 Update Connection Parameters.................................................................87
3.3.2.1 Slave Requests for Connection Parameter Update........................87
3.3.2.2 Master Responds to Connection Parameter Update Request........88
3.3.2.3 Master Updates Connection Parameters in Link Layer...................90
3.4 ATT & GATT.........................................................................................................90
3.4.1 GATT Basic Unit “Attribute” .......................................................................90
3.4.2 Attribute and ATT Table.............................................................................92
3.4.2.1 attNum .............................................................................................92

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 6 Ver.1.0.0
3.4.2.2 perm.................................................................................................93
3.4.2.3 uuid, uuidLen ...................................................................................94
3.4.2.4 pAttrValue, attrLen...........................................................................94
3.4.2.5 Callback Function w.........................................................................95
3.4.2.6 Callback Function r..........................................................................97
3.4.2.7 Attribute Table Layout......................................................................98
3.4.2.8 ATT Table Initialization....................................................................99
3.4.3 Attribute PDU & GATT API........................................................................99
3.4.3.1 Read by Group Type Request, Read by Group Type Response .100
3.4.3.2 Find by Type Value Request, Find by Type Value Response ......101
3.4.3.3 Read by Type Request, Read by Type Response........................101
3.4.3.4 Find Information Request, Find Information Response ................102
3.4.3.5 Read Request, Read Response....................................................103
3.4.3.6 Read Blob Request, Read Blob Response...................................103
3.4.3.7 Exchange MTU Request, Exchange MTU Response...................104
3.4.3.8 Write Request, Write Response....................................................105
3.4.3.9 Write Command.............................................................................106
3.4.3.10 Handle Value Notification............................................................106
3.4.3.11 Handle Value Indication...............................................................107
3.4.3.12 Handle Value Confirmation..........................................................108
3.5 SMP....................................................................................................................109
3.5.1 SMP Parameter Configuration.................................................................109
3.5.1.1 Device Bonding..............................................................................109
3.5.1.2 Device OOB data verification ........................................................109
3.5.1.3 Secure Connection Pairing (SC) ...................................................109
3.5.2 Enable SMP.............................................................................................110
3.5.3 SMP Event ...............................................................................................111
3.5.3.1 BLT_EV_FLAG_PAIRING_BEGIN................................................111
3.5.3.2 BLT_EV_FLAG_PAIRING_END ...................................................112
3.5.4 SMP Bonding Information........................................................................112
4. Power Management (PM)............................................................................................115
4.1 PM Driver............................................................................................................115
4.1.1 Low Power Modes....................................................................................115
4.1.2 Hardware Wakeup Sources.....................................................................115

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 7 Ver.1.0.0
4.1.3 Low Power Mode Entry and Wakeup ......................................................117
4.2 BLE Low Power Management............................................................................119
4.2.1 PM In Idle State........................................................................................119
4.2.2 PM in BLE Adv State & Conn State.........................................................120
4.3 BLE PM Configuration........................................................................................120
4.3.1 PM Module Initialization...........................................................................120
4.3.2 Set Low Power Modes via “bls_pm_setSuspendMask” ..........................121
4.3.3 bls_pm_setWakeupSource......................................................................121
4.3.4 Working Mechanism of Low Power Managment.....................................122
4.4 “latency_use” Configuration and Calculation .....................................................125
4.5 Other APIs..........................................................................................................125
4.5.1 bls_pm_getSystemWakeupTick...............................................................126
4.5.2 bls_pm_enableAdvMcuStall.....................................................................127
4.6 Notes about GPIO Wakeup................................................................................127
4.6.1 Fail to Enter Suspend/Deepsleep When Wakeup Level is Valid.............127
4.7 BLE System PM Reference................................................................................128
4.8 Timer Wakeup of APP Layer..............................................................................129
5. Low Battery Detect ......................................................................................................131
5.1 Significance of Low Battery Detect....................................................................131
5.2 Implementation of Low Battery Detect...............................................................131
5.2.1 Cautions of Low Battery Detect ...............................................................131
5.2.1.1 MUST Use GPIO Input Channel....................................................132
5.2.1.2 MUST Use ADC Differential Mode................................................133
5.2.1.3 MUST Use DFIFO for ADC Sampling Valu...................................133
5.2.2 Dedicated Low Battery Detect Demo.......................................................133
5.2.2.1 Initialization of Low Battery Detect ................................................134
5.2.2.2 Low Battery Detect Processing .....................................................134
5.2.2.3 Low Battery Voltage Alarm............................................................135
6. OTA..............................................................................................................................137
6.1 Flash Architecture and OTA Procedure.............................................................137
6.1.1 Flash Storage Architecture ......................................................................137
6.1.2 OTA Update Procedure ...........................................................................138
6.1.3 Modify Firmware Size and Boot Address.................................................139
6.2 RF Data Proceesing in OTA Mode.....................................................................141

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 8 Ver.1.0.0
6.2.1 OTA Processing in Attribute Table on Slave Side...................................141
6.2.2 OTA Data Packet Format.........................................................................142
6.2.3 RF Transfer Processing on Master Side..................................................143
6.2.4 RF Receive Processing on Slave Side....................................................146
7. Key Scan......................................................................................................................149
7.1 Key Matrix...........................................................................................................149
7.2 Keyscan, Keymap and Keycode........................................................................151
7.2.1 Keyscan....................................................................................................151
7.2.2 Keymap &kb_event..................................................................................151
7.3 Keycode..............................................................................................................154
7.4 Keyscan Flow.....................................................................................................156
7.4.1 Basic Keyscan Flow.................................................................................156
7.4.2 Keyscan Flow Timing Optimization..........................................................157
7.5 Deepsleep Wakeup Fast Keyscan.....................................................................159
7.6 Repeat Key Processing......................................................................................161
7.7 Stuck Key Processing ........................................................................................162
7.8 Power Optimization for Long Key Press............................................................164
8. LED Management........................................................................................................165
8.1 LED Task Related Functions..............................................................................165
8.2 LED Task Configuration and Management........................................................165
8.2.1 LED Event Definition................................................................................165
8.2.2 LED Event Priority....................................................................................166
9. blt Software Timer........................................................................................................168
9.1 Timer Initialization...............................................................................................168
9.2 Timer Inquiry Processing....................................................................................168
9.3 Add Timer Task..................................................................................................171
9.4 Delete Timer Task..............................................................................................171
9.5 Demo..................................................................................................................171
10. IR................................................................................................................................174
10.1 PWM Driver......................................................................................................174
10.1.1 PWM id and Pin .....................................................................................174
10.1.2 PWM Clock ............................................................................................175
10.1.3 PWM Cycle and Duty.............................................................................176
10.1.4 PWM Revert...........................................................................................177

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 9 Ver.1.0.0
10.1.5 PWM Start and Stop..............................................................................177
10.1.6 PWM Mode ............................................................................................177
10.1.7 PWM Pulse Number...............................................................................177
10.1.8 PWM Phase...........................................................................................178
10.1.9 PWM Interrupt........................................................................................178
10.1.10 API for IR DMA FIFO Mode.................................................................180
10.1.10.1 Configuration of DMA FIFO.......................................................180
10.1.10.2 Set DMA FIFO Buffer.................................................................181
10.1.10.3 Start and Stop of IR DMA FIFO Mode.......................................181
10.2 IR Demo ...........................................................................................................181
10.2.1 PWM Mode Selection ............................................................................181
10.2.2 Demo IR protocol...................................................................................182
10.2.3 IR Timing Design....................................................................................182
10.2.4 IR Initialization........................................................................................185
10.2.4.1 rc_ir_init .......................................................................................185
10.2.4.2 IR Hardware Configuration..........................................................185
10.2.4.3 IR Variable Initialization...............................................................186
10.2.5 FIFO Task Configuration........................................................................186
10.2.5.1 FIFO Task_data...........................................................................186
10.2.5.2 FifoTask_idle................................................................................187
10.2.5.3 FifoTask_repeat...........................................................................188
10.2.5.4 FifoTask_repeat*n&FifoTask_idle_repeat*n ...............................189
10.2.6 Check IR Busy Status in APP Layer......................................................189
11. Drivers in BLE SDK ...................................................................................................190
11.1 External Capacitor for 24 MHz Crystal.............................................................190
11.2 Select 32kHz Clock Sources............................................................................190
11.3 EMI ...................................................................................................................190
11.3.1 EMI Test.................................................................................................190
11.3.1.1 Carrier Mode................................................................................191
11.3.1.2 CD Mode......................................................................................191
11.3.1.3 TX Mode ......................................................................................192
11.3.1.4 RX Mode......................................................................................192
11.3.2 EMI Test Tool.........................................................................................193
11.4 PHY Test..........................................................................................................198

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 10 Ver.1.0.0
12. BLE SPP Module.......................................................................................................199
12.1 Command and Data Packet Format.................................................................199
12.2 Function Description.........................................................................................205
12.2.1 Module Sends Commands and Data.....................................................206
12.2.2 Module Receives Data...........................................................................207
12.3 Power Management of Module........................................................................209
Appendix..........................................................................................................................210
Appendix 1: crc16 Algorithm ....................................................................................210

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 11 Ver.1.0.0
Contents of Figures
Figure 1-1 SDK File Structure....................................................................................14
Figure 1-2 Select library.............................................................................................18
Figure 1-3 Demos in BLE SDK...................................................................................19
Figure 2-1 MCU Address Space Allocation ...............................................................21
Figure 2-2 SRAM and Firmware Space.....................................................................22
Figure 2-3 Section Distribution in list File...................................................................26
Figure 2-4 Section Address in list File........................................................................27
Figure 2-5 512kB FLASH Space Allocation...............................................................33
Figure 2-6 128kB Flash Space Allocation..................................................................35
Figure 2-7 System Clock & System Timer.................................................................37
Figure 3-1 BLE SDK Standard Architecture...............................................................44
Figure 3-2 HCI Data Transfer Between Host and Controller.....................................45
Figure 3-3 5316 hci Architecture................................................................................46
Figure 3-4 Telink BLE Slave Architecture..................................................................46
Figure 3-5 State Diagram of Link Layer State Machine in BLE Spec........................48
Figure 3-6 Telink Link Layer State Machine ..............................................................48
Figure 3-7 Idle + Advertising......................................................................................50
Figure 3-8 BLE Slave LL State...................................................................................50
Figure 3-9 Timing Sequence in Advertising State......................................................52
Figure 3-10 Timing Sequence in Conn state Slave Role...........................................53
Figure 3-11 RX Overflow Case 1...............................................................................56
Figure 3-12 RX Overflow Case 2...............................................................................57
Figure 3-13 HCI Event................................................................................................58
Figure 3-14 Disconnection Complete Event ..............................................................59
Figure 3-15 Read Remote Version Information Complete Event..............................59
Figure 3-16 LE Connection Complete Event .............................................................60
Figure 3-17 LE Advertising Report Event...................................................................61
Figure 3-18 LE Connection Update Complete Event.................................................61
Figure 3-19 Architecture of Telink Defined Event......................................................62
Figure 3-20 Connect Request PDU ...........................................................................66
Figure 3-21 LL_CONNECTION_UPDATE_REQ Format in BLE Stack.....................70
Figure 3-22 Adv Packet Format in BLE Stack ...........................................................72
Figure 3-23 Advertising Event in BLE Stack..............................................................74

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 12 Ver.1.0.0
Figure 3-24 Four Adv Events in BLE Stack ...............................................................75
Figure 3-25 Connection Para Update Req Format in BLE Stack ..............................87
Figure 3-26 BLE Sniffer Packet Sample: conn para Update Request & Response..87
Figure 3-27 conn para update rsp Format in BLE Stack ...........................................88
Figure 3-28 BLE Sniffer Packet Sample: ll conn update req .....................................90
Figure 3-29 GATT Service Containing Attribute Group.............................................91
Figure 3-30 5316 BLE SDK Attribute Table...............................................................92
Figure 3-31 BLE Sniffer Packet Sample When Master Reads hidInformation..........95
Figure 3-32 Write Request in BLE Stack ...................................................................96
Figure 3-33 Write Command in BLE Stack................................................................96
Figure 3-34 Service/Attribute Layout..........................................................................99
Figure 3-35 Read by Group Type Request/Read by Group Type Response..........100
Figure 3-36 Find by Type Value Request/Find by Type Value Response ..............101
Figure 3-37 Read by Type Request/Read by Type Response................................102
Figure 3-38 Find Information Request/Find Information Response.........................102
Figure 3-39 Read Request/Read Response............................................................103
Figure 3-40 Read Blob Request/Read Blob Response...........................................103
Figure 3-41 Exchange MTU Request/Exchange MTU Response...........................104
Figure 3-42 Write Request/Write Response............................................................106
Figure 3-43 Handle Value Notification in BLE Spec................................................106
Figure 3-44 Handle Value Indication in BLE Spec...................................................107
Figure 3-45 Handle Value Confirmation in BLE Spec..............................................108
Figure 3-46 Pairing Disable......................................................................................110
Figure 3-47 Pairing Conn Trigger.............................................................................111
Figure 3-48 Pairing Peer Trigger..............................................................................111
Figure 3-49 Pairing_Req Sent From Master............................................................111
Figure 4-1 Hardware Wakeup Sources for 5316 MCU............................................116
Figure 4-2 PM in Link Layer Idle state .....................................................................120
Figure 4-3 Trigger APP Wakup Tick in Advance.....................................................130
Figure 6-1 5316F512K Flash Storage Structure......................................................137
Figure 6-2 Write Command Format in BLE Stack....................................................142
Figure 6-3 Format of OTA Command and Data.......................................................142
Figure 6-4 Master Obtains OTA Attribute Handle via “Read By Type Request” .....143
Figure 6-5 Firmware: Starting Part...........................................................................144

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 13 Ver.1.0.0
Figure 6-6 Firmware: Ending Part............................................................................144
Figure 6-7 Master Sends “OTA start”.......................................................................144
Figure 6-8 Master OTA Data....................................................................................145
Figure 7-1 Row/Column Key Matrix.........................................................................149
Figure 7-2 Keycode Processing Function................................................................154
Figure 7-3 Keyscan Time Optimization....................................................................159
Figure 10-1 PWM Cycle & Duty ...............................................................................176
Figure 10-2 PWM interrupt.......................................................................................179
Figure 10-3 DMA FIFO Buffer for IR DMA FIFO Mode............................................180
Figure 10-4 Demo IR protocol..................................................................................182
Figure 10-5 IR Timing 1............................................................................................183
Figure 10-6 IR Timing 2............................................................................................184
Figure 11-1 EMI Test Tool........................................................................................193
Figure 11-2 Select Data Bus....................................................................................193
Figure 11-3 Swire synchronization operation...........................................................194
Figure 11-4 Set Channel..........................................................................................194
Figure 11-5 Select RF Mode....................................................................................195
Figure 11-6 Interface After RF Mode Setting...........................................................195
Figure 11-7 Select Test Mode..................................................................................196
Figure 11-8 Set TX Packet Number.........................................................................196
Figure 11-9 TX Mode Interface................................................................................197
Figure 11-10 Read RX Packet Number and RSSI...................................................197
Figure 12-1 Module Hardware Connection..............................................................205
Figure 12-2 Scan Module Device.............................................................................206
Figure 12-3 Connect Module Device........................................................................206
Figure 12-4 Module Sending Data...........................................................................207
Figure 12-5 Phone Receiving Data..........................................................................207
Figure 12-6 Phone Sending Data.............................................................................208
Figure 12-7 Module Receiving Data.........................................................................208
Figure 12-8 Connection of Hardware When Low Power is Enabled.......................209

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 14 Ver.1.0.0
1. SDK Overview
Telink 5316 BLE SDK provides demo code for BLE slave development, based on which
users can develop their own application programs.
Currently 5316 BLE SDK applies to ICs TLSR8232F512 and TLSR8232F128 (5316 and
8232 refer to the same IC, 5316 is the name for Telink internal use, while 8232 is the
name for external use).
1.1 Software Architecture
Software architecture for Telink 5316 BLE SDK includes APP layer and BLE protocol
stack.
Figure 1-1 shows the file structure after the SDK project is imported to Telink IDE, which
mainly contains six top-layer folders: “boot”, ”common”, ”drivers”, ”proj_lib”, ”stack”, and
“vendor”.
Figure 1-1 SDK File Structure
boot: This folder contains software bootloader.
common: This folder contains genericAPIs, such as printf and shift operation.
drivers: This folder contains all the peripheral drivers of 5316, such asADC, I2C,
SPI, and UART.
proj_lib: This folder contains library files necessary for MCU running, including BLE
stack, RF driver, PM driver, etc. This folder is provided in the form of library files, the
source files, like liblt_5316.a, are not open to users.

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 15 Ver.1.0.0
vendor: This folder contains user APP-layer code, e.g. 5316_ble_remote demo
application. The following four basic files are needed for each new user folder.
1.1.1 main.c
The “main.c” file includes the entry function “main”of the program, system
initialization functions and endless loop “while(1)”. It’s not recommended to make any
modification to this file.
int main(void){
blc_pm_select_internal_32k_crystal(); // select internal 32k rc as 32k counter
clock source
cpu_wakeup_init(); // basic MCU hardware initialization, negligible to users
clock_init(SYS_CLK_16M_Crystal); // clock initialization, users only needs to fill
related parameters accordingly.
gpio_init(); // GPIO initialization, users only need to configure related parameters
in app_config.h
rf_drv_init(RF_MODE_BLE_1M); // RF initialization, negligible to users, only support
BLE 1M
user_init (); // BLE initialization, initialization of the whole system, configured by
users
irq_enable(); // enable global interrupt
while (1) {
#if (MODULE_WATCHDOG_ENABLE)
wd_clear(); //clear watch dog
#endif
main_loop ();// include BLE Rx/Tx processing, power management and user
tasks
}
}

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 16 Ver.1.0.0
1.1.2 app_config.h
The user configuration file “app_config.h” serves to configure parameters of the whole
system, including parameters related to BLE, GPIO, PM low-power management, and
etc.
Parameter details of each module will be illustrated in following sections.
1.1.3 Application File
“app.c”: User file for system initialization and adding user task UI.
“app_att.c” of BLE Slave project: configuration files for services and profiles. Based on
Telink Attribute structure, as well as Attributes such as GATT, standard HID, and
proprietary OTA, users can add their own services and profiles as needed.
1.1.4 BLE Stack Entry
There are two entry functions in BLE stack code of Telink BLE SDK.
1) BLE related interrupt processing entry in “irq_handler” function of “main.c” file
“irq_blt_sdk_handler”.
_attribute_ram_code_ void irq_handler(void)
{
……
irq_blt_sdk_handler ();
……
}
2) BLE logic and data processing function entry in application file mainloop
“blt_sdk_main_loop”.
void main_loop (void)
{
tick_loop ++;
///////////////////// BLE entry ////////////////////////////
blt_sdk_main_loop();
////////////////////// UI entry ////////////////////////////
……
}

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 17 Ver.1.0.0
1.2 Applied ICs
TLSR8232F512/ TLSR8232F128: The two ICs share the same IP core, thus their
hardware modules are almost the same except Flash size as shown below.
IC
Flash size
SRAM size
TLSR8232F512
512kB
16kB
TLSR8232F128
128kB
16kB
1.3 library
SDK 1.2.0 provides two libraries, liblt_5316_512K.a and liblt_5316_128K.a. Providing
two libraries is to save some Flash space for 128k Flash IC, which is at the expense of
removing BLE4.2 DLE features, etc.
It is verified that removing some features of BLE saves little space while loses some
functions of BLE and brings inconvenience to users. Therefore, SDK 1.3.0 reduced its
library to liblt_5316.a only.
If the user uses SDK 1.2.0, he should adjust the library according to Flash size. Figure 1-
2shows the adjustment method.

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 18 Ver.1.0.0
Figure 1-2 Select library
1.4 Demo
5316 BLE SDK provides multiple BLE demos for users. Each demo code has its specific
hardware. Through running the demo, a user can observe effects directly and modify
demo code for his own application development.

Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 19 Ver.1.0.0
Figure 1-3 Demos in BLE SDK
1.4.1 BLE Slave Demo
BLE Slave demos and their differences are listed in the table below:
Demo
Stack
Application
MCU function
5316 hci
BLE controller
No
Controller, communicate
with peer MCU hosts via
HCI interface
5316 module
BLE controller + host
Application in Host
MCU
BLE SPP module
5316 remote
BLE controller + host
Remote control
application
Host MCU
5316 sample
BLE controller + host
No
Host MCU
5316 dual mode
BLE + 2.4G
Dual mode
Host MCU
5316 hci is a BLE Slave controller. Through its UART-based HCI, 5316 hci can
communicate with other MCU Host, which therefor forms a complete BLE Slave system.
5316 remote/5316 module/5316 sample are all complete BLE Slave stacks. 5316 module
only acts as BLE SPP module to communicate with Host MCU via UART interface.
Usually applications are written in the (peer) MCU with BLE host. 5316 remote is a demo
of BLE remote controller which supports basic functions of remote. It can connect with
standard iOS/Android device or Telink 826x master kma dongle to control the peer. 5316
sample has the same functions with 5316 remote but different hardware. 5316 sample is
used for TLSR8232 development board. It can save the hardware cost for users for that
users can use Telink BLE without purchasing Telink demo RCU.
5316 dual mode supports both BLE and 2.4G. BLE and 2.4G work in a switch mode,
which means 2.4 cannot work when 5316 dual mode works in BLE and vice versa, but
you can switch the two modes in operation.
This manual suits for next models
2
Table of contents
Other TELINK SEMICONDUCTOR Computer Accessories manuals
Popular Computer Accessories manuals by other brands

Antec
Antec Nine Hundred user manual

Stealkey Customs
Stealkey Customs Lian Li 011D Evo D3 Assembly instructions

Havahart
Havahart 1082 instructions

Mana
Mana Mana136 user manual

Systium Technologies
Systium Technologies MotherBoard Ready 215 User's quick start guide

Alienware
Alienware Tobii Eye Tracker user guide