Table of Contents

Advertisement

Quick Links

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

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the TLSR8232 and is the answer not in the manual?

Questions and answers

Summary of Contents for TELINK SEMICONDUCTOR TLSR8232

  • Page 1 Application Note Telink TLSR8232 BLE SDK Developer Handbook AN-19112700-E1 Version 1.0.0 2019-11-27 Brief: This document is the developer guide for TLSR8232 BLE SDK 1.3.0.
  • Page 2 © 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.
  • Page 3: Revision History

    Telink TLSR8232 BLE SDK Developer Handbook Revision History Version 1.0.0 (2019-11-27) This is the Initial release. AN-19112700-E1 Ver.1.0.0...
  • Page 4: Table Of Contents

    Telink TLSR8232 BLE SDK Developer Handbook 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 ..................
  • Page 5 Telink TLSR8232 BLE SDK Developer Handbook 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 ...............
  • Page 6 Telink TLSR8232 BLE SDK Developer Handbook 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 ...............
  • Page 7 Telink TLSR8232 BLE SDK Developer Handbook 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 &...
  • Page 8 Telink TLSR8232 BLE SDK Developer Handbook 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 ..................
  • Page 9 Telink TLSR8232 BLE SDK Developer Handbook 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.
  • Page 10 Telink TLSR8232 BLE SDK Developer Handbook 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 ............
  • Page 11 Telink TLSR8232 BLE SDK Developer Handbook 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 ..........................
  • Page 12: Contents Of Figures

    Telink TLSR8232 BLE SDK Developer Handbook 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 ..............
  • Page 13 Telink TLSR8232 BLE SDK Developer Handbook 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 ...........
  • Page 14 Telink TLSR8232 BLE SDK Developer Handbook 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 ..............
  • Page 15: Sdk Overview

    Telink TLSR8232 BLE SDK Developer Handbook 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).
  • Page 16: Main.c

    Telink TLSR8232 BLE SDK Developer Handbook  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)”.
  • Page 17: App_Config.h

    Telink TLSR8232 BLE SDK Developer Handbook 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.
  • Page 18: Applied Ics

    Telink TLSR8232 BLE SDK Developer Handbook 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. Flash size SRAM size TLSR8232F512 512kB 16kB...
  • Page 19: Demo

    Telink TLSR8232 BLE SDK Developer Handbook 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.
  • Page 20: Ble Slave Demo

    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.
  • Page 21: Other Demos

    Telink TLSR8232 BLE SDK Developer Handbook 1.4.2 Other Demos 5316 feature test provides demo code for some common features related to BLE. Users can implement their own functions based on these demos. All features will be introduced in BLE section.
  • Page 22: Mcu Basic Modules

    Telink TLSR8232 BLE SDK Developer Handbook 2. MCU Basic Modules 2.1 MCU Address Space 2.1.1 MCU Address Space Allocation Telink 5316 MCU supports maximum addressing space of 16M bytes, including 8M-byte program space from 0 to 0x7FFFFF (Please see the datasheet for Flash sizes) and 8M- byte peripheral space from 0x800000 to 0xffffff.
  • Page 23 Telink TLSR8232 BLE SDK Developer Handbook Flash Sram 0x00000 0x808000 vector vector power on real_ramcode_size ram_code _ramcode_size_ ram_code load wasted Sram area 0x808000+real_ramcode_size Cache 2.25K 0x808900+real_ramcode_size data + bss Firmware unused area …… text stack 0x80C000 rodata & data init value ……...
  • Page 24 Telink TLSR8232 BLE SDK Developer Handbook  Whenever functions resident in RAM are called, it isn’t needed to re-read them from Flash, thus time will be saved. Therefore, the functions with limited execution time should be memory resident to increase execution efficiency. In SDK, some functions related to BLE timing sequence need frequent execution, in order to decrease execution time and save power consumption, these functions are memory resident.
  • Page 25 Telink TLSR8232 BLE SDK Developer Handbook 2-2, the “text” in firmware is the Flash code not placed in SRAM. As shown in Figure According to program locality principle, this part needs to be loaded to cache for execution. Though cache size is fixed as 2.25K, its starting address in SRAM is configurable.
  • Page 26: List File Analysis Demo

    Telink TLSR8232 BLE SDK Developer Handbook By default, the size of stack used by SDK library does not exceed 256 bytes. However, since the size of used stack depends on the deepest stack address, the stack’s final size is related to users’ upper-layer program design. Any case which causes deep stack, e.g.
  • Page 27 Telink TLSR8232 BLE SDK Developer Handbook All screenshots herein are from files “boot.link”, “cstartup_5316.s”, “5316_ble_remote.bin” and “5316_ble_remote.lst”. In the list file, each code of a specific function is called a “section”. The figure below shows section distribution in the list file “5316_ble_remote.lst”.
  • Page 28 Telink TLSR8232 BLE SDK Developer Handbook Figure 2-4 Section Address in list File Figure 2-4 shows the starting/ending addresses of various sections by searching “section” in the list file. From this figure and Figure 2-3 Section Distribution in list File, the...
  • Page 29 Telink TLSR8232 BLE SDK Developer Handbook cache The starting address and ending address of cache are: 0x808000 + real_ramcode_size ~ 0x808900 + real_ramcode_size 0x809800 ~ 0x80a100 cache related information is not shown in the list file. text “text” section contains 0x6f30 bytes (size = 0x86c0 – 0x1790) with starting address being 0x1790 (ending address of “ram_code”), ending address 0x86c0, the same as what...
  • Page 30: Mcu Address Space Access

    Telink TLSR8232 BLE SDK Developer Handbook “data” is followed by “bss”. Since the first array “_start_bss_” should be 16-byte aligned, the “bss” section starts from 0x80a2a0, and its size is 0xc98, as shown in Figure 2-3. The final variable in “bss” is “blt_ota_start_tick”, a int variable. Its address is 0x80af34, and its size is 4-byte.
  • Page 31: Flash Space Operation

    Telink TLSR8232 BLE SDK Developer Handbook The correct formats should be: u16 x = *(volatile u16*)0x808000; // 0x808000 is 2-byte aligned *(volatile u32*)0x808004 = 0x12345678; // 0x808004 is 4-byte aligned 2.1.3.2 Flash Space Operation Reading or writing Flash space is implemented via functions “flash_read_page” and “flash_write_page”.
  • Page 32 Telink TLSR8232 BLE SDK Developer Handbook One sector contains 4096 bytes, e.g. 0x13000 ~0x13fff. The “addr” must be the starting address of one sector, and every time the function erases a complete sector. Erasing a sector takes some time. In the case of a 16M system clock, it takes about 30~100ms or even longer time to erase a sector.
  • Page 33: Sdk Flash Space Allocation

    Telink TLSR8232 BLE SDK Developer Handbook static inline void blc_app_loadCustomizedParameters(void); Flash can be read by using function “flash_read_page” or pointer, but it can be written via function “flash_write_page” only. Pointer does not support Flash writing operation. Please note that when Flash is read by pointer, since data read by system bus will be...
  • Page 34: Space Allocation Of 512Kb Flash

    Telink TLSR8232 BLE SDK Developer Handbook 2.1.4.1 Space Allocation of 512kB Flash Figure 2-5 512kB FLASH Space Allocation The figure above shows the default FLASH space allocation for TLSR8232F512 IC. Corresponding interfaces are provided to users for modifying Flash space allocation. The following introduces the default address space allocation and corresponding interfaces.
  • Page 35 Telink TLSR8232 BLE SDK Developer Handbook address to store MAC address, please ensure the consistency. The “user_init” function in the SDK will read MAC address from Flash area starting from the macro “CFG_ADR_MAC”. This macro can be modified in the “drivers/5316/flash.h”.
  • Page 36: Space Allocation Of 128Kb Flash

    Telink TLSR8232 BLE SDK Developer Handbook  If firmware doesn’t need to occupy the whole 128kB space 0x00000~0x3FFFF, users can use corresponding API to modify the allocation as needed, thus the remaining space can be used as data storage space. Please refer to OTA section for details.
  • Page 37 Telink TLSR8232 BLE SDK Developer Handbook address to store MAC address, please ensure the burning addresses of Telink jig system are also modified correspondingly. The “user_init” function in the SDK will read MAC address from Flash area starting from the macro “CFG_ADR_MAC”. This macro can be modified in “drivers/5316/flash.h”.
  • Page 38: Clock Module

    For last generation IC of Telink (826x), the clock for system timer is the system clock, while for TLSR8232, as the figure shown below, though system timer has multiple sources SDK divides the external 24MHz crystal oscillator by 2/3 and obtains 16M clock which will not change with the change of system clock.
  • Page 39 Telink TLSR8232 BLE SDK Developer Handbook In BLE SDK, we recommend using crystal clock. In initialization, call API below to configure system clock and choose the corresponding clock from the definition of enumeration variable SYS_CLK_TYPEDEF: void clock_init(SYS_CLK_TYPEDEF SYS_CLK) As 5316 System Timer is different from system clock, users need to know whether the clock of each MCU hardware module is derived from system clock or System Timer.
  • Page 40: System Timer Usage

    Telink TLSR8232 BLE SDK Developer Handbook 2.2.2 System Timer Usage After the Main function “cpu_wakeup_init” is initialized System Timer starts running, and users can read the counter value of System Timer (“System Timer tick” for short). The 32-bit System Timer tick will increase by 1 for each clock cycle (i.e. 1/16us). It takes 268 seconds or so (i.e.
  • Page 41: Gpio Module

    Telink TLSR8232 BLE SDK Developer Handbook a_trig_tick = clock_time(); a_trig_flg = 1; if(a_trig_flg &&clock_time_exceed(a_trig_tick,2 *1000 * 1000)){ a_trig_flg = 0; B(); 2.3 GPIO Module For details about GPIO module, please refer to source code in “drivers/5316/gpio_default.h”, “gpio.c” and “gpio.h”. Please refer to document Hawk_gpio_lookuptable for understanding register operations in the code.
  • Page 42 Telink TLSR8232 BLE SDK Developer Handbook static inline unsigned char gpio_read(GPIO_PinTypeDef pin); Note: If GPIO input is low level, 0 is returned; if GPIO input is high level, non-zero value (may not be 1) is returned. In firmware, it’s recommended to invert the read values rather than using the format such as “if( gpio_read(GPIO_PA0) == 1)”.
  • Page 43: Gpio Initialization

    Telink TLSR8232 BLE SDK Developer Handbook gpio_write(GPIO_PA4,1) Configure GPIO_PC6 as input, and check if it’s low-level input. Enable 10K pull up resistor to avoid influence of float level. gpio_set_func(GPIO_PC6, AS_GPIO) ; // PC6 is used as general GPIO function by default, so this step to configure “func”...
  • Page 44: Configure Sws Pull-Up To Avoid Mcu Errors

    Telink TLSR8232 BLE SDK Developer Handbook If these macros are pre-defined in app_config.h, they will not use the default values above. PA7 is taken as an example to illustrate GPIO state configuration in app_config.h. Configure func: #define PA7_FUNC AS_GPIO Configure ie:...
  • Page 45: Ble Module

    Telink TLSR8232 BLE SDK Developer Handbook 3. BLE Module 3.1 BLE SDK Software Architecture 3.1.1 Standard BLE SDK Architecture Figure 3-1 shows a standard BLE SDK software architecture compliant with BLE Spec. Application Profile 1 Profile 2 Profile n Generic Access Profile...
  • Page 46: Telink Ble Sdk Architecture

    Telink TLSR8232 BLE SDK Developer Handbook BLE Host data data event BLE Controller Figure 3-2 HCI Data Transfer Between Host and Controller BLE Host will use HCI cmd to operate and set Controller. Controller API corresponding to each HCI cmd will be introduced in section 3.2.8.
  • Page 47: 5316 Ble Slave

    Telink TLSR8232 BLE SDK Developer Handbook Other MCU Host UART Link Layer Controller Physical Layer Figure 3-3 5316 hci Architecture 3.1.2.2 5316 BLE Slave 5316 BLE SDK in BLE Host fully supports stack of Slave. When users only need to use standard BLE Slave, and 5316 BLE SDK runs Host (Slave...
  • Page 48: Ble Controller

    Telink TLSR8232 BLE SDK Developer Handbook Figure 3-4, solid arrows indicate data transfer controllable via user APIs, while hollow arrows indicate data transfer within the protocol stack which users are unable to involve Controller can still communicate with Host (L2CAP layer) via HCI; however, the HCI is no longer the sole interface, and the APP layer can directly transfer data with Link Layer of the Controller.
  • Page 49 Telink TLSR8232 BLE SDK Developer Handbook Figure 3-5 State Diagram of Link Layer State Machine in BLE Spec Telink BLE SDK Link Layer state machine is shown as below. Scanning Advertising Idle initiating Power Slave Master Management role role connection...
  • Page 50: Link Layer State Machine Combined Application

    Telink TLSR8232 BLE SDK Developer Handbook “Power Management” in Figure 3-6 is not a state of LL, but a functional module which indicates SDK only implements low power processing for Advertising and Connection Slave Role. If Idle state needs low power, user can invoke related APIs in the APP layer.
  • Page 51: Idle + Advertising

    Telink TLSR8232 BLE SDK Developer Handbook 3.2.3.2 Idle + Advertising bls_ll_setAdvEnable(0) Idle Advertising bls_ll_setAdvEnable(1) Figure 3-7 Idle + Advertising As shown above, only Idle module and Advertising module are initialized, and it applies to applications which use basic advertising function to advertise product information in single direction, e.g.
  • Page 52: Link Layer Timing Sequence

    Telink TLSR8232 BLE SDK Developer Handbook The figure above shows a Link Layer state machine combination for a basic BLE Slave application. In SDK, 5316 hci/5316 remote/5316 module/5316 sample/5316 dual mode are all based on this combination. The module initialization code of Link Layer state machine is: u8 tbl_mac [6] = {……};...
  • Page 53: Timing Sequence In Idle State

    Telink TLSR8232 BLE SDK Developer Handbook irq_blt_sdk_handler (); …… void main_loop (void) ///////////////////// BLE entry //////////////////////////// blt_sdk_main_loop(); ////////////////////// UI entry //////////////////////////// …… Function “blt_sdk_main_loop” at BLE entry serves to process data and events related to BLE protocol stack. UI entry is for user application code.
  • Page 54: Timing Sequence In Conn State Slave Role

    Telink TLSR8232 BLE SDK Developer Handbook Code of UI entry in mainloop is executed during UI task/suspend part in Figure 3-9. This duration can be used for UI task only, or MCU can enter suspend for the redundant time so as to reduce power consumption.
  • Page 55: Conn State Slave Role Timing Protection

    Telink TLSR8232 BLE SDK Developer Handbook In ConnSlaveRole, “blt_sdk_main_loop” needs to process the data received during the brx process. During the brx working phase, the data packet received from Master will be copied out during RX interrupt irq handler; these data won’t be processed immediately, but buffered in software RX FIFO (corresponding to my_fifo_t blt_rxfifo in code).
  • Page 56: Link Layer Tx Fifo & Rx Fifo

    Telink TLSR8232 BLE SDK Developer Handbook After the API “bls_ll_requestConnBrxEventDisable” is called and the request is accepted, if the time (ms) corresponding to the return value is enough to process user task, the task will be executed. Before the task starts, the API “bls_ll_disableConnBrxEvent” should be called to disable Brx Event.
  • Page 57 Telink TLSR8232 BLE SDK Developer Handbook Take RX overflow for example, if: The number RX FIFOs is 8; The read pointer and write pointer is 0 and 2 respectively before brx_event(n) is enabled; main_loop is blocked by task in brx_event(n) and brx_event(n+1) and does not process RX FIFOs in time;...
  • Page 58 Telink TLSR8232 BLE SDK Developer Handbook start brx working post UI task RX3 TX3 RX4 TX4 RX5 TX5 RX6 TX6 RX7 TX7 RX8 TX8 RX1 TX1 RX2 TX2 UI task/sleep Brx event(n) rptr:0 wptr(2+8)&(8-1)=2 0(6) 7(5) If the RX fifo rptr is 0 before the...
  • Page 59: Controller Hci Event

    Telink TLSR8232 BLE SDK Developer Handbook 3.2.6 Controller HCI Event Considering users may need to record and process some key actions of BLE stack bottom layer in APP layer, 5316 BLE SDK provides two types of events: standard HCI event defined by BLE Controller; Telink defined event.
  • Page 60: Hci Event

    Telink TLSR8232 BLE SDK Developer Handbook #define HCI_FLAG_EVENT_BT_STD (1<<25) “HCI_FLAG_EVENT_TLK_MODULE” will be introduced in “Telink defined event”, while “HCI_FLAG_EVENT_BT_STD” indicates the current event is Controller HCI event. In the callback function prototype, “para” and “n” indicate data and data length of event.
  • Page 61: Hci Le Event

    Telink TLSR8232 BLE SDK Developer Handbook HCI_EVT_LE_META It indicates the current event is HCI LE event, and event types can be checked according to sub event code. Except for HCI_EVT_LE_META, other HCI events should use the API below to enable corresponding event masks.
  • Page 62 Telink TLSR8232 BLE SDK Developer Handbook When Controller Link Layer scans the right adv packet, the packet will be reported to Host via “HCI_SUB_EVT_LE_ADVERTISING_REPORT”. Data length of this event is not fixed and it depends on payload of the adv packet, as shown below.
  • Page 63: Telink Defined Event

    Telink TLSR8232 BLE SDK Developer Handbook 3.2.7 Telink Defined Event Besides the standard Controller HCI event, SDK also provides Telink defined event, the architecture is shown below. In terms of user application, events are from Host and Controller (equivalent to the whole BLE stack).
  • Page 64 Telink TLSR8232 BLE SDK Developer Handbook #define BLT_EV_FLAG_RX_DATA_ABANDOM #define BLT_EV_FLAG_SMP_PINCODE_PROCESS #define BLT_EV_FLAG_SMP_KEY_MISSING #define BLT_EV_FLAG_PHY_UPDATE Telink defined event is only used in BLE Slave applications (remote/module). There are two methods to call back Telink defined events in BLE slave applications. The first: Registering the callback function of each event independently, which we call “independent registration.”...
  • Page 65 Telink TLSR8232 BLE SDK Developer Handbook The two methods to implement Telink defined event is mutually exclusive. It is recommended to use the first one “independent registration” as most SDKs use this one. Only 5316 module uses the second one “shared event entry”.
  • Page 66: Blt_Ev_Flag_Adv

    Telink TLSR8232 BLE SDK Developer Handbook spp_send_data(HCI_FLAG_EVENT_TLK_MODULE, pEvt); break; blc_hci_registerControllerEventHandler(controller_event_handler); bls_hci_mod_setEventMask_cmd(0xfffff); In the following sub-sections, all events, event trigger conditions and parameters of corresponding callback functions for Controller will be introduced in details. Events “BLT_EV_FLAG_PAIRING_BEGIN” and “BLT_EV_FLAG_PAIRING_END”, which do not belong to Controller, will be introduced in Host SMP.
  • Page 67: Blt_Ev_Flag_Terminate

    Telink TLSR8232 BLE SDK Developer Handbook Data length “n”: 34. Pointer “p”: p points to one 34-byte RAM area, corresponding to the “connect request PDU” below. Figure 3-20 Connect Request PDU Please refer to “rf_packet_connect_t” defined in “ble_common.h”. In the structure below,...
  • Page 68: Blt_Ev_Flag_Encryption_Conn_Done

    Telink TLSR8232 BLE SDK Developer Handbook Data length “n”: 1. Three cases to exit Conn state Slave role and corresponding reasons are listed as below: If Slave fails to receive packet from Master for a duration due to RF communication problem (e.g.
  • Page 69: Blt_Ev_Flag_Gpio_Early_Wakeup

    Telink TLSR8232 BLE SDK Developer Handbook connRemoteMaxRxOctets; connRemoteMaxTxOctets; supportedMaxRxOctets; supportedMaxTxOctets; connInitialMaxTxOctets; connMaxTxRxOctets_req; }ll_data_extension_t; “connEffectiveMaxRxOctets” and “connEffectiveMaxTxOctets” are max RX and TX data length finally allowed in current connection; “connMaxRxOctets” and “connMaxTxOctets” are max RX and TX data length of the device; “connRemoteMaxRxOctets” and “connRemoteMaxTxOctets”...
  • Page 70: Blt_Ev_Flag_Chn_Map_Req

    Telink TLSR8232 BLE SDK Developer Handbook For definitions of the parameters above, please refer to the return value “int” of the API in “Power Management”: int cpu_sleep_wakeup (int deepsleep, int wakeup_src, u32 wakeup_tick); 3.2.7.9 BLT_EV_FLAG_CHN_MAP_REQ Event trigger condition: When Slave is in Conn state, if Master needs to update current connection channel list, it will send a “LL_CHANNEL_MAP_REQ”...
  • Page 71: Blt_Ev_Flag_Conn_Para_Update

    Telink TLSR8232 BLE SDK Developer Handbook Figure 3-21 LL_CONNECTION_UPDATE_REQ Format in BLE Stack 3.2.7.12 BLT_EV_FLAG_CONN_PARA_UPDATE Event trigger condition: When Slave is in connection state, this event will be triggered if Slave has updated connection parameters after it receives the “LL_CONNECTION_UPDATE_REQ” from Master.
  • Page 72: Controller Api

    BLE_PHY_1M = BIT(0), BLE_PHY_2M = BIT(1), Note: TLSR8232 could only use symmetric PHY, that is, Rx and Tx use the same PHY. Please see section 2M PHY Supported for usage. 3.2.8 Controller API 3.2.8.1 Controller API Brief In standard BLE stack architecture (see Figure 3-1), APP layer cannot directly communicate with Link Layer of Controller, i.e.
  • Page 73: Link Layer State Machine Initialization

    Telink TLSR8232 BLE SDK Developer Handbook In 5316 BLE SDK, by calling the interface below “public address” and “random static address” will be obtained. void blc_initMacAddress(int flash_addr, *mac_public, *mac_random_static); Fill “flash_addr” with the address for storing MAC address in Flash. From the content above, the address of 5316 512K Flash should be 0x76000.
  • Page 74: Bls_Ll_Setscanrspdata

    Telink TLSR8232 BLE SDK Developer Handbook The “data” pointer points to the starting address of AdvData, while the “len” indicates data length. The table below lists possible results for the return type “ble_sts_t”. ble_sts_t Value ERR Reason BLE_SUCCESS Len exceeds the...
  • Page 75: Bls_Ll_Setadvparam

    Telink TLSR8232 BLE SDK Developer Handbook tbl_scanRsp [] = { 0x08, 0x09, 'G', 'R', 'e', 'm', 'o', 't', 'e', Since device names configured in advertising data and scan response data are different, the device names scanned by a mobile phone or IOS system may be different: If some devices only listen for Adv packets, the scanned device name is "...
  • Page 76 Telink TLSR8232 BLE SDK Developer Handbook As required by BLE Spec, it’s not recommended to set adv interval as fixed value; in Telink BLE SDK, the eventual adv interval is random variable within the range of intervalMin ~ intervalMax. If intervalMin and intervalMax are set as same value, adv interval will be fixed as the intervalMin.
  • Page 77 Telink TLSR8232 BLE SDK Developer Handbook ADV_TYPE_NONCONNECTABLE_UNDIRECTED = 0x03, //ADV_NONCONN_IND ADV_TYPE_CONNECTABLE_DIRECTED_LOW_DUTY = 0x04, //ADV_INDIRECT_IND (low duty cycle) }advertising_type; By default, the most common adv event type is ADV_TYPE_CONNECTABLE_UNDIRECTED ownAddrType It is used to specify MAC address type in adv packets.
  • Page 78 Telink TLSR8232 BLE SDK Developer Handbook adv_channelMap The “adv_channelMap” is used to set advertising channel. It can choose any one or more of channel 37, 38, 39. The value “adv_channelMap” can be the following three or any combination of the three.
  • Page 79: Bls_Ll_Setadvenable

    Telink TLSR8232 BLE SDK Developer Handbook ble_sts_t bls_ll_setAdvFilterPolicy(u8 advFilterPolicy); The parameters of the three APIs are the same as “bls_ll_setAdvParam”. ble_sts_t: Return value “bls_ll_setAdvChannelMap” and “bls_ll_setAdvFilterPolicy” will always return “BLE_SUCCESS”. “bls_ll_setAdvInterval” will return “BLE_SUCCESS” or “HCI_ERR_INVALID_HCI_CMD_PARAMS”. 3.2.8.8 bls_ll_setAdvEnable Please refer to Core_v5.0 (Vol 2/Part E/ 7.8.9 “LE Set Advertising Enable Command”).
  • Page 80: Blc_Ll_Setadvcustomedchannel

    Telink TLSR8232 BLE SDK Developer Handbook Duration Time can’t be configured for “ADV_TYPE_CONNECTABLE_DIR HCI_ERR_INVALID_HCI_CMD_PARAMS 0x12 ECTED_HIGH_DUTY”. When Adv Duratrion Time expires, advertising is stopped, if users want to re-configure adv parameters (such as AdvType, AdvInterval, AdvChannelMap), first the parameters should be set in the callback function of the event “BLT_EV_FLAG_ADV_DURATION_TIMEOUT”, then the “bls_ll_setAdvEnable(1)”...
  • Page 81: Bls_Ll_Terminateconnection

    Telink TLSR8232 BLE SDK Developer Handbook The Tx power configured by this API is valid for both adv packets and conn packets, and it can be set anywhere in the firmware. The actual Tx power is subject to the latest setting.
  • Page 82: Get Connection Parameters

    Telink TLSR8232 BLE SDK Developer Handbook 3.2.8.13 Get Connection Parameters The following APIs are used to obtain current connection parameters including Connection Interval, Connection Latency and Connection Timeout (only apply to Slave role). bls_ll_getConnectionInterval(void); bls_ll_getConnectionLatency(void); bls_ll_getConnectionTimeout(void); If return value is 0, it indicates current Link Layer state is None Conn state without connection parameters available.
  • Page 83: Whitelist & Resolvinglist

    Telink TLSR8232 BLE SDK Developer Handbook 3.2.8.16 Whitelist & Resolvinglist As introduced above, “filter_policy” of Advertising involves Whitelist, and actual operations depend on devices in Whitelist. Actually Whitelist contains two parts: Whitelist and Resolvinglist. Users can check whether address type of peer device is RPA (Resolvable Private Address) via “peer_addr_type”...
  • Page 84: Phy Supported

    Telink TLSR8232 BLE SDK Developer Handbook process, and corresponding interfaces to obtain the info are available in SMP part. “local_irk” is not processed in current SDK, and it can be set as “NULL”. ble_sts_t ll_resolvingList_delete(u8 peerIdAddrType, *peerIdAddr); This API is used to delete a RPA device from Resolvinglist.
  • Page 85: Data Length Extension

    Telink TLSR8232 BLE SDK Developer Handbook connHandle Connect handle. Use BLS_CONN_HANDLE by default. all_phys Set if there are preferred Tx PHY and Rx PHY. An enum variable. PHY_TRX_PREFER is the common value. See the definitions le_phy_prefer_mask_t for other values. tx_phys Preferred Tx PHY.
  • Page 86: L2Cap

    Telink TLSR8232 BLE SDK Developer Handbook Users should balance on it. There are requirements for configurations of Tx FIFO and Rx FIFO. Misconfigurations will lead to unexpected errors. The following provides the configurations and examples. If users want to set the maximum transmission data length to 251 Bytes, Tx FIFO should be set as 251 + 12 = 263 Bytes, considering 4-byte alignment, Tx FIFO should be set to 264 Bytes finally.
  • Page 87: Register L2Cap Data Processing Function

    Telink TLSR8232 BLE SDK Developer Handbook As specified in BLE Spec, L2CAP is mainly used for data transfer between Controller and Host. Most work is finished in stack bottom layer with little involvement of the user. Users only need to call the following APIs to set correspondingly.
  • Page 88: Update Connection Parameters

    Telink TLSR8232 BLE SDK Developer Handbook 3.3.2 Update Connection Parameters 3.3.2.1 Slave Requests for Connection Parameter Update In BLE stack, Slave can actively apply for a new set of connection parameters by sending command “CONNECTION PARAMETER UPDATE REQUEST” to Master in L2CAP layer.
  • Page 89: Master Responds To Connection Parameter Update Request

    Telink TLSR8232 BLE SDK Developer Handbook 3.3.2.2 Master Responds to Connection Parameter Update Request After Master receives the “CONNECTION PARAMETER UPDATE REQUEST” command from Slave, it will respond with command “CONNECTION PARAMETER UPDATE RESPONSE”. Please refer to Core_v5.0 (Vol 3/Part A/ 4.20 “CONNECTION PARAMETER UPDATE RESPONSE”).
  • Page 90 Telink TLSR8232 BLE SDK Developer Handbook After “L2CAP_CMD_CONN_UPD_PARA_REQ” is received in “L2CAP_CID_SIG_CHANNEL”, it will read interval_min (used as eventual interval), supervision timeout and long suspend time (interval * (latency +1)), and check the rationality of these data. If interval < 200ms, long suspend time<20s and supervision timeout >= 2* long suspend time, this request will be accepted;...
  • Page 91: Master Updates Connection Parameters In Link Layer

    Telink TLSR8232 BLE SDK Developer Handbook 3.3.2.3 Master Updates Connection Parameters in Link Layer After Master responds with “conn para update rsp” to accept the “conn para update req” from Slave, Master will send a “LL_CONNECTION_UPDATE_REQ” command in Link Layer.
  • Page 92 Telink TLSR8232 BLE SDK Developer Handbook Figure 3-29 GATT Service Containing Attribute Group The basic contents and properties of an Attribute are shown as below: Attribute Type: UUID The UUID is used to identify Attribute type, and its total length is 16 bytes. In BLE standard protocol, the UUID length is defined as two bytes, since Master devices follow the same method to transform 2-byte UUID into 16 bytes.
  • Page 93: Attribute And Att Table

    Telink TLSR8232 BLE SDK Developer Handbook 3.4.2 Attribute and ATT Table To implement GATT Service on Slave, an Attribute Table is defined in 5316 BLE SDK and it consists of multiple basic Attributes. Attribute definition is shown as below. typedef struct attribute attNum;...
  • Page 94: Perm

    Telink TLSR8232 BLE SDK Developer Handbook The “attNum” can be used to indicate the number of valid Attributes in current Attribute Table, i.e. the maximum Attribute Handle value. This number is only used in the invalid Attribute item 0 of Attribute Table array.
  • Page 95: Uuid, Uuidlen

    Telink TLSR8232 BLE SDK Developer Handbook 3.4.2.3 uuid, uuidLen As introduced above, UUID supports two types: BLE standard 2-byte UUID, and Telink proprietary 16-byte UUID. The “uuid” and “uuidLen” can be used to describe the two UUID types simultaneously. The “uuid” is an u8-type pointer, and “uuidLen” specifies current UUID length, i.e. the uuidLen bytes starting from the pointer are current UUID.
  • Page 96: Callback Function W

    Telink TLSR8232 BLE SDK Developer Handbook U16_LO(0x0111), U16_HI(0x0111), // bcdHID (USB HID version), 0x11,0x01 0x00, // bCountryCode 0x01 // Flags {0, 2, sizeof(hidInformation), sizeof(hidInformation), (u8*)(&hidinformationUUID), (u8*)(hidInformation), 0,0}, In practical application, the key word “const” can be used to store the read-only 4-byte hid information “0x01 0x00 0x01 0x11”...
  • Page 97 Telink TLSR8232 BLE SDK Developer Handbook opcode = 0x52, see Core_v5.0. Write Command, After Slave receives a write command above, if the callback function w is not set, Slave will automatically write the area pointed by the “pAttrValue” with the value sent from Master, and the data length equals the “l2capLen”...
  • Page 98: Callback Function R

    Telink TLSR8232 BLE SDK Developer Handbook att; //opcode //low byte of Atthandle //high byte of Atthandle dat[20]; }rf_packet_att_data_t; “p” points to “dma_len”, valid length of data is l2cap minus 3, and the first valid data is pw->dat[0]. my_WriteCallback (void rf_packet_att_data_t...
  • Page 99: Attribute Table Layout

    Telink TLSR8232 BLE SDK Developer Handbook If the callback read function is not set, Slave will automatically read “attrLen” bytes of data from the area pointed by the “pAttrValue”, and the data will be responded to Master via “Read Response/Read Blob Response”.
  • Page 100: Att Table Initialization

    Telink TLSR8232 BLE SDK Developer Handbook Figure 3-34 Service/Attribute Layout 3.4.2.8 ATT Table Initialization GATT & ATT initialization only needs to transfer the pointer of Attribute Table in APP layer to protocol stack, and the API is: void bls_att_setAttributeTable *p);...
  • Page 101: Read By Group Type Request, Read By Group Type Response

    Telink TLSR8232 BLE SDK Developer Handbook Responses:Data response sent by Server after it receives request from Client. Commands:Command sent from Client to Server. Notifications: Data sent from Server to Client. Indications: Data sent from Server to Client. Confirmations: Confirmation sent from Client after it receives data from Server.
  • Page 102: Find By Type Value Request, Find By Type Value Response

    Telink TLSR8232 BLE SDK Developer Handbook The following groups in Slave Attribute Table meet the requirement according to current demo code. Attribute Group with attHandle from 0x0001 to 0x0007, Attribute Value is SERVICE_UUID_GENERIC_ACCESS (0x1800). Attribute Group with attHandle from 0x0008 to 0x000a, Attribute Value is SERVICE_UUID_DEVICE_INFORMATION (0x180A).
  • Page 103: Find Information Request, Find Information Response

    Telink TLSR8232 BLE SDK Developer Handbook Figure 3-37 Read by Type Request/Read by Type Response As shown above, Master reads the Attribute with attType of 0x2A00, i.e. the Attribute with Attribute Handle of 00 03 in Slave. const u8 my_devName [] = {'t', 'S', 'e', 'l', 'f', 'i'};...
  • Page 104: Read Request, Read Response

    Telink TLSR8232 BLE SDK Developer Handbook 3.4.3.5 Read Request, Read Response Please refer to Core_v5.0 (Vol 3/Part F/3.4.4.3 and 3.4.4.4) for details about “Read Request” and “Read Response”. The “Read Request” command sent by Master specifies certain attHandle. After the request is received, Slave will respond to Master with the Attribute Value of the specified Attribute via the “Read Response”...
  • Page 105: Exchange Mtu Request, Exchange Mtu Response

    Telink TLSR8232 BLE SDK Developer Handbook 3.4.3.7 Exchange MTU Request, Exchange MTU Response Please refer to Core_v5.0 (Vol 3/Part F/3.4.2.1 and 3.4.2.2) for details about “Exchange MTU Request” and “Exchange MTU Response”. As shown below, Master and Slave obtain MTU size of the other via the “Exchange MTU Request”...
  • Page 106: Write Request, Write Response

    Telink TLSR8232 BLE SDK Developer Handbook ATT_ERR_INVALID_PARAMETE mtu_size exceeds the max value 0x85 247. When Master GATT layer needs to send long packet data to Slave, Master will actively initiate “ATT_Exchange_MTU_req”, and Slave will respond with “ATT_Exchange_MTU_rsp”. “ServerRxMTU” is the configured value of the API “blc_att_setRxMtuSize”.
  • Page 107: Write Command

    Telink TLSR8232 BLE SDK Developer Handbook Figure 3-42 Write Request/Write Response 3.4.3.9 Write Command Please refer to Core_v5.0 (Vol 3/Part F/3.4.5.3) for details about “Write Command”. The “Write Command” sent by Master specifies certain attHandle and attaches related data. After the command is received, Slave will find the specified Attribute, determine...
  • Page 108: Handle Value Indication

    Telink TLSR8232 BLE SDK Developer Handbook result in invoking failure, and the return value “ble_sts_t” will indicate the corresponding error reason. When this API is called in APP layer, it’s recommended to check whether the return value is “BLE_SUCCESS”. If the return value is not “BLE_SUCCESS”, a delay is needed to re- push the data.
  • Page 109: Handle Value Confirmation

    Telink TLSR8232 BLE SDK Developer Handbook As specified in BLE Spec, Slave won’t regard data indication as success until Master confirms the data, and the next indicate data won’t be sent until the previous data indication is successful. When Link Layer is in Conn state, generally data will be successfully pushed into bottom- layer software FIFO by invoking this API;...
  • Page 110: Smp

    Telink TLSR8232 BLE SDK Developer Handbook A callback function is supplied in SDK for the APP layer to check whether the indicate data has already been confirmed by Master. The registered callback function will be executed once when a Handle Value Confirmation is received.
  • Page 111: Enable Smp

    Telink TLSR8232 BLE SDK Developer Handbook 5316 BLE SDK supports both Legacy Pairing and Secure Connection Pairing, SDK uses Legacy Pairing by default. If users want to use SC, call the function below: void blc_smp_enableScFlag(int en); en = 1, enable SC;...
  • Page 112: Smp Event

    Telink TLSR8232 BLE SDK Developer Handbook Figure 3-47 Pairing Conn Trigger encrypt_en = SMP_PARING_PEER_TRRIGER; It indicates current device won’t actively intiate pairing request, and it will only respond to the pairing request from peer device. If peer device does not send pairing request, current device won’t implement encrypted pairing.
  • Page 113: Blt_Ev_Flag_Pairing_End

    Telink TLSR8232 BLE SDK Developer Handbook 3.5.3.2 BLT_EV_FLAG_PAIRING_END Event trigger condition: This event will be triggered when pairing is finished in success or failure. If Slave or Master fails to follow standard pairing procedure, or communication abnormity occurs (e.g. report error), pairing will fail.
  • Page 114 Telink TLSR8232 BLE SDK Developer Handbook blc_smp_param_getCurrentBondingDeviceNumber(void); If the return value is 3, it indicates three paired devices are stored in Flash currently, and all of the three devices can be re-connected successfully. “index” is related to “BondingDeviceNumber”: If “BondingDeviceNumber” is 1, there is only one bonding device, and its index is 0.
  • Page 115 Telink TLSR8232 BLE SDK Developer Handbook If the return value is 0, it indicates info obtaining failure; if the return value is non-zero value, it indicates the starting address of the info in Flash. For example, if there are three bonding devices currently, to obtain info of the latest connected device, “index”...
  • Page 116: Power Management (Pm)

    MCU. 4.1.2 Hardware Wakeup Sources Figure 4-1 shows wakeup sources available for TLSR8232: In suspend mode, it can be woken up by PAD, CORE and timer sources; while in deepsleep mode, it can be woken AN-19112700-E1...
  • Page 117 Telink TLSR8232 BLE SDK Developer Handbook up by PAD and timer sources. In 5316 BLE SDK, the following three types of wakeup sources are available. enum PM_WAKEUP_PAD = BIT(4), PM_WAKEUP_CORE = BIT(5), PM_WAKEUP_TIMER = BIT(6), wakeup CORE wakeup Suspend Mode...
  • Page 118: Low Power Mode Entry And Wakeup

    Telink TLSR8232 BLE SDK Developer Handbook Examples: gpio_set_wakeup(GPIO_PC2, 1, 1); // Enable GPIO_PC2 CORE high level wakeup gpio_set_wakeup(GPIO_PC2, 1, 0); // Disable GPIO_PC2 CORE wakeup gpio_set_wakeup(GPIO_PB5, 0, 1); // Enable GPIO_PB5 CORE low level wakeup gpio_set_wakeup(GPIO_PB5, 0, 0); // Disable GPIO_PB5 CORE wakeup Configure GPIO PAD as wakeup source for deepsleep: void cpu_set_gpio_wakeup (int pin, int pol, int en);...
  • Page 119 Telink TLSR8232 BLE SDK Developer Handbook The absolute wakeup_tick value must be within the range 32 bits can represent, the maximum sleep time configured by this API is limited. In current design, maximum sleep time is set as 3/4 of the maximum scope 32 bits can represent. For 16MHz clock, 32 bits can represent about 268s, the maximum suspend/deepsleep should be 268s*3/4=201s.
  • Page 120: Ble Low Power Management

    Telink TLSR8232 BLE SDK Developer Handbook cpu_sleep_wakeup (0, PM_WAKEUP_CORE | PM_WAKEUP_TIMER,clock_time() + CLOCK_SYS_CLOCK_1MS MCU enters suspend mode when this function is executed, and it can be woke up by GPIO CORE and TIMER. Timer wakeup time is set as 50ms relative to function execution moment;...
  • Page 121: Pm In Ble Adv State & Conn State

    Telink TLSR8232 BLE SDK Developer Handbook Figure 4-2 PM in Link Layer Idle state The figure above shows simple reference code: When Link Layer is in Idle state, there’s 10ms suspend during each mainloop. In Idle state, MCU can also enter deepsleep mode directly.
  • Page 122: Set Low Power Modes Via "Bls_Pm_Setsuspendmask

    Telink TLSR8232 BLE SDK Developer Handbook not need to be called, thus PM related code and variables won’t be compiled to the firmeware, and resources can be saved. void blc_ll_initPowerManagement_module(void); 4.3.2 Set Low Power Modes via “bls_pm_setSuspendMask” The API used to configure PM for Link Layer Advertising state and Conn state in 5316...
  • Page 123: Working Mechanism Of Low Power Managment

    Telink TLSR8232 BLE SDK Developer Handbook void bls_pm_setWakeupSource(u8 source); This API sets a bottom-layer variable “WakeupSource”. The actual variable in code is “bls_pm.wakeup_src”. The WakeupSource includes PM_WAKEUP_PAD, PM_WAKEUP_CORE, PM_WAKEUP_TIMER, and their “or” combinations. If MCU enters suspend mode from Advertising state or Conn state Slave role, actual...
  • Page 124 Telink TLSR8232 BLE SDK Developer Handbook if(Link Layer State is in Advertising state orConn state Slave role) if(Link Layer in Adv Event or Brx Event) // BLE packet transfer is ongoing, not enter low power mode return 0; else blt_brx_sleep ();...
  • Page 125 Telink TLSR8232 BLE SDK Developer Handbook Execute callback function of event “BLT_EV_FLAG_GPIO_EARLY_WAKEUP” Re-enter suspend, until wakeup at “T_advertising + advInterval” else if((Link Layer state == Conn state Slave role)&& (SuspendMask&SUSPEND_CONN) ) //enter suspend from current Conn state u32 wakeup_tick; if(conn_latency is not 0) // conn_latency != 0 // refer to section 4.4 for latency_use...
  • Page 126: Latency_Use" Configuration And Calculation

    Telink TLSR8232 BLE SDK Developer Handbook 4.4 “latency_use” Configuration and Calculation As introduced in working mechanism of low power management (section 4.3.4), if the “suspendMask” is set as “SUSPEND_CONN” in Conn state Slave role, the actual wakeup time should be: wakeup_tick = T_brx + (latency_use+1) * conn_interval;...
  • Page 127: Bls_Pm_Getsystemwakeuptick

    Telink TLSR8232 BLE SDK Developer Handbook 4.5.1 bls_pm_getSystemWakeupTick The API below is used to obtain suspend wakeup time (system tick value) calculated by PM module. u32 bls_pm_getSystemWakeupTick(void); According to section 4.3.4, this API can be invoked only in the callback function of “BLT_EV_FLAG_SUSPEND_ENTER”...
  • Page 128: Bls_Pm_Enableadvmcustall

    4.6.1 Fail to Enter Suspend/Deepsleep When Wakeup Level is Valid Since TLSR8232 CORE/PAD wakeup is triggered by high/low level rather than positive/negative edge, after GPIO CORE or PAD source is configured, e.g. MCU is configured to wake up from suspend by high level of certain GPIO CORE, the GPIO input must be low level when MCU invokes “cpu_wakeup_sleep”...
  • Page 129: Ble System Pm Reference

    Telink TLSR8232 BLE SDK Developer Handbook MCU will enter deepsleep in following cases: There is no task (including key press task) for successive 60s duration. In this case, the problem MCU can’t enter deepsleep due to high level from drive pin can be avoided.
  • Page 130: Timer Wakeup Of App Layer

    Telink TLSR8232 BLE SDK Developer Handbook wakeup in advance). It will be recorded in the retention register DEEP_ANA_REG0 it’s the Conn state from which MCU enters current deepsleep. After wakeup, Slave can configure fast adv packet to establish connection with Master as soon as possible.
  • Page 131 Telink TLSR8232 BLE SDK Developer Handbook wakeup tick is within current suspend time. If yes, suspend will be triggered to wake up in advance at app wakeup_tick (as shown in Figure 4-3). If not, this wakeup_tick is negligible to bottom layer, and wakeup time depends on BLE timing sequence.
  • Page 132: Low Battery Detect

    5.2 Implementation of Low Battery Detect For Low Battery Detect, ADC should be used to measure supply voltage. It’s recommended to read TLSR8232 datasheet or ADC driver related document and get familiar with ADC module. In the SDK, Low Battery Detect is implemented in the “battery_check.h” and “battery_check.c”.
  • Page 133: Must Use Gpio Input Channel

    For Telink 826x family, ADC module supports “VCC/VBAT” input channel to sample supply voltage. For TLSR8232, though this design is reserved (corresponding to “VBAT” in the enum type “ADC_InputPchTypeDef”), based on certain reasons, it’s not allowed to use the “VBAT” channel. Therefore, user must adopt GPIO input channel of ADC instead, which includes PA6, PA7, and PB0~PB7.
  • Page 134: Must Use Adc Differential Mode

    SDK for code. 5.2.1.3 MUST Use DFIFO for ADC Sampling Valu For Telink 826x family, ADC result is readable via related register. For TLSR8232, DFIFO mode is used instead to get ADC result. Please refer to the following function in driver.
  • Page 135: Initialization Of Low Battery Detect

    Refer to function “adc_vbat_init”. ADC initialization must always follow the flow: power off SAR ADC; configure ADC parameters; power on SAR ADC. TLSR8232 sets SAR ADC as power down by default, so “adc_vbat_init” does not set power down of “adc_power_on(0)”. TLSR8232 enables ADC power Every time before reading ADC data and disables ADC power after reading is completed.
  • Page 136: Low Battery Voltage Alarm

    Telink TLSR8232 BLE SDK Developer Handbook The “lowBattDet_tick” can be used to set frequency of battery detect. In the demo, the period is set as 500ms by default, and it can be modified as needed. Implementation of the “battery_power_check” involves details of battery detect initialization, DFIFO setup, data acquisition and processing, as well as low voltage alarming.
  • Page 137 Telink TLSR8232 BLE SDK Developer Handbook analog_write(DEEP_ANA_REG2, BATTERY_VOL_LOW); cpu_sleep_wakeup(PM_SLeepMode_Deep, PM_WAKEUP_PAD, 0); For “5316_ble_remote”, after shutdown at low battery, MCU enters deepsleep which supports key press wakeup. At the moment of wakeup by key press, SDK will perform one fast battery detect in user initialization (function user_init) rather than in main_loop, so as to avoid errors as shown below.
  • Page 138: Ota

    TLSR8232 supports Flash multi-address booting, addresses including 0, 0x10000, 0x20000, and 0x40000. To implement OTA for TLSR8232 slave, a device is needed to act as BLE OTA Master, which can be the Bluetooth device (supporting OTA in APP) combined with Slave, or simply Telink BLE Master Dongle.
  • Page 139: Ota Update Procedure

    By modifying flag bit value of Flash 0x8 and 0x20008, the part of Flash code to be executed will be determined. In TLSR8232 SDK with OTA function support, the OTA upgrade process of the (2n+1)-th or (2n+2)-th time is shown as below: After MCU is powered on, read Flash address 0x8 and 0x20008, and compare the value with 0x4b to determine the booting address;...
  • Page 140: Modify Firmware Size And Boot Address

    Telink TLSR8232 BLE SDK Developer Handbook Slave OTA Service Data Attribute (The handle value can be pre-appointed by Slave and Master, or obtained via “read_by_type”.) After the Atrribute Handle value is obtained, OTA Master may need to obtain version number of current Slave Flash firmware, and compare it with the version number of local stored new firmware.
  • Page 141 Telink TLSR8232 BLE SDK Developer Handbook In the main function, since “cpu_sleep_wakeup” contains settings related to “firmware_size_k” and “boot_addr”, this API must be called before “cpu_wakeup_init” takes effect. If maximum firmware_size exceeds 128kB, booting address needs to be changed to 0x40000.
  • Page 142: Rf Data Proceesing In Ota Mode

    Telink TLSR8232 BLE SDK Developer Handbook Case 1 is the default distribution, the maximum firmware size is 48kB with 16kB left for User Data Area. If 52K < firmware size <=56K, users can use Case 2 which has no extra Flash space for user data.
  • Page 143: Ota Data Packet Format

    Telink TLSR8232 BLE SDK Developer Handbook 6.2.2 OTA Data Packet Format Master sends command and data to Slave via “Write Command” in L2CAP layer. Figure 6-2 Write Command Format in BLE Stack The Attribute Handle value is the handle_value of OTA data on Slave side. The Attribute Value length is set as 20, and the format is shown as below.
  • Page 144: Rf Transfer Processing On Master Side

    Telink TLSR8232 BLE SDK Developer Handbook will be regarded as valid only when the result matches the CRC (19 byte) of the data. 6.2.3 RF Transfer Processing on Master Side Since BLE link-layer RF data will be automatically responded with ack to avoid packet loss, during OTA data transfer Master won’t check if every OTA data is responded with...
  • Page 145 Telink TLSR8232 BLE SDK Developer Handbook directly rebooted; the link layer can’t respond to Master with ack, and Master fails to send data until timeout. Read four bytes of Master Flash 0x20018~0x2001b to determine firmware size which is realized by compiler. Suppose firmware size is 20k (0x5000), the value of firmware 0x18~0x1b is 0x00005000, so the firmware size can be read from 20018~0x2001b.
  • Page 146 Telink TLSR8232 BLE SDK Developer Handbook Data for second transfer: 0x01 0x00 0x5e 0x80 ... (12 bytes not listed)... 0x00 0x00 0xJK 0xHI Data for third transfer: 0x02 0x00 0x25 0x08 ... (12 bytes not listed)... 0xfa 0x87 0xNO 0xLM ..
  • Page 147: Rf Receive Processing On Slave Side

    Telink TLSR8232 BLE SDK Developer Handbook The maximal adr_index and inverted value of “5316_remote.bin” are “0x05a9” and “0xfa56”, respectively. Figure 6-8 shows the final OTA end packet. Check if link-layer TX FIFO on Master side is empty: If it’s empty, it indicates all data and commands in above steps are sent successfully, i.e.
  • Page 148 Telink TLSR8232 BLE SDK Developer Handbook influence OTA speed), and modify this timeout duration accordingly via the interface as shown below. void bls_ota_setTimeout(u32 timeout_us);// unit: us Valid OTA data are received (first two bytes are 0~0x1000): Whenever Slave receives one 20-byte OTA data packet, it will first check if the adr_index equals slave_adr_index plus 1.
  • Page 149 Telink TLSR8232 BLE SDK Developer Handbook used for debugging: When OTA fails, user can read the “result”, stop MCU by using “while(1)”, and find the reason for current OTA failure. LED indication can be added to indicate OTA success, as shown below:...
  • Page 150: Key Scan

    {GPIO_PC6, GPIO_PC5, GPIO_PC4, GPIO_PC3, GPIO_PC2, GPIO_PC1} Keyscan adopts analog pull-up/pull-down resistor in TLSR8232 IC: drive pins use 100K pull-down resistor, and scan pins use 10K pull-up resistor. When no button is pressed, scan pins act as input GPIOs and read high level due to 10K pull-up resistor. When key scan starts, drive pins output low level;...
  • Page 151 Telink TLSR8232 BLE SDK Developer Handbook is not enabled, scan pins still detect high level due to voltage division of 100K and 10K resistor.) Define valid voltage level detected on scan pins when drive pins output low level in Row/Column scan:...
  • Page 152: Keyscan, Keymap And Keycode

    Telink TLSR8232 BLE SDK Developer Handbook #define PA4_INPUT_ENABLE #define PA3_INPUT_ENABLE #define PA2_INPUT_ENABLE #define PA1_INPUT_ENABLE 7.2 Keyscan, Keymap and Keycode 7.2.1 Keyscan After configuration as shown in section 7.1, the function below is invoked in mainloop to implement keyscan. kb_scan_key (int...
  • Page 153 Telink TLSR8232 BLE SDK Developer Handbook #define KB_RETURN_KEY_MAX typedef struct{ cnt; ctrl_key; keycode[KB_RETURN_KEY_MAX]; }kb_data_t; kb_data_t kb_event; The “kb_event” consists of 8 bytes: “cnt” is used to indicate valid count number of pressed buttons currently; “ctrl_key” is not used generally, and it will be used only for standard USB HID keyboard (user is not allowed to set keycode in keymap as 0xe0~0xe7).
  • Page 154 Telink TLSR8232 BLE SDK Developer Handbook same time; if previous kb_event.cnt is 1, it indicates the update is another button is pressed with one button held; if previous kb_event.cnt is 3, it indicates the update is one of the three pressed buttons is released……...
  • Page 155: Keycode

    Telink TLSR8232 BLE SDK Developer Handbook 7.3 Keycode The section above introduces keymap definition in app_config.h and keycode filling in KB_MAP_NORMAL. To realize standard USB HID keyboard, some special keycodes need to be processed, so user should pay attention to details for keycode definition.
  • Page 156 Telink TLSR8232 BLE SDK Developer Handbook For the following key values, after they are transferred by Slave to Telink Master Dongle, special processing will be realized by PC, and it depends on report descriptor configuration of BLE HID in app_att.c.
  • Page 157: Keyscan Flow

    Telink TLSR8232 BLE SDK Developer Handbook VK_ZOOM_IN (VK_MEDIA_END 1),//0xb6 VK_ZOOM_OUT //0xb7 7.4 Keyscan Flow 7.4.1 Basic Keyscan Flow When kb_scan_key is called, a basic keyscan flow is shown as below: Initial full scan through the whole matrix. All drive pins output drive level (0). Meanwhile read all scan pins, check for valid level, and record the column on which valid level is read.
  • Page 158: Keyscan Flow Timing Optimization

    Telink TLSR8232 BLE SDK Developer Handbook The following methods are used to optimize code execution time for row-by-row scan.  When a row outputs drive level, it’s not needed to read level of all columns (CoL0~CoL5). Since the scan_pin_need marks valid column number, user can read the marked columns only.
  • Page 159 Telink TLSR8232 BLE SDK Developer Handbook for (int i=0; i<(sizeof (pin)/sizeof(*pin)); i++) gpio_set_wakeup(pin[i],1,1); //drive pin core(gpio) high wakeup suspend The “gpio_set_wakeup(pin[i],1,1)” sets wakeup polarity of drive pins as high level and enables wakeup. Since GPIO interrupt enabling and polarity adopts the same configuration registers as wakeup, the “gpio_set_wakeup(pin[i],1,1)”...
  • Page 160: Deepsleep Wakeup Fast Keyscan

    Telink TLSR8232 BLE SDK Developer Handbook Figure 7-3 Keyscan Time Optimization As shown above, it will first check whether IRQ flag bit is set after previous keyscan is finished. If yes, it indicates there’s button press action during this duration; since manual...
  • Page 161 Telink TLSR8232 BLE SDK Developer Handbook keyscan in mainloop. Data buffer is designed considering valid button data detected in adv state and pushed into BLE TX FIFO will be cleared after entering connection state. The macro “DEEPBACK_FAST_KEYSCAN_ENABLE” in app_config.h is used to control fast keyscan and data buffer.
  • Page 162: Repeat Key Processing

    Telink TLSR8232 BLE SDK Developer Handbook #if(DEEPBACK_FAST_KEYSCAN_ENABLE) if(deepback_key_state != DEEPBACK_KEY_IDLE){ deepback_post_proc(); #endif The “deepback_pre_proc” realizes buffer processing of fast keyscan value, as shown below: After connection is established between Slave and Master, if no button state update is detected in a kb_key_scan, the buffered kb_event_cache value will be used as the current newest button state update.
  • Page 163: Stuck Key Processing

    Telink TLSR8232 BLE SDK Developer Handbook The two macros serve to define current repeat key values: KB_REPEAT_KEY_NUM specifies the number of keycodes, while the KB_MAP_REPEAT defines a map to specify all repeat keycodes. Note that the keycodes in the KB_MAP_REPEAT must be the values in the KB_MAP_NORMAL.
  • Page 164 Telink TLSR8232 BLE SDK Developer Handbook det_key = kb_scan_key (0, 1); (det_key){ (STUCK_KEY_PROCESS_ENABLE) if(kb_event.cnt){ //key press stuckKey_keyPressTime = clock_time(); #endif ..For each button state update, when button press is detected (i.e. kb_event.cnt is non- zero value), the “stuckKey_keyPressTime” is used to record the time for the latest button press state.
  • Page 165: Power Optimization For Long Key Press

    Telink TLSR8232 BLE SDK Developer Handbook 7.8 Power Optimization for Long Key Press Power optimization can be enabled for long pressed keys, by enabling the macro “LONG_PRESS_KEY_POWER_OPTIMIZE”. Please refer to the PM section for details. AN-19112700-E1 Ver.1.0.0...
  • Page 166: Led Management

    Telink TLSR8232 BLE SDK Developer Handbook 8. LED Management 8.1 LED Task Related Functions Source code about LED management is available in vendor/common/blt_led.c of 5316 BLE SDK for user reference. Users can directly include the “vendor/common/blt_led.h” into their C files.
  • Page 167: Led Event Priority

    Telink TLSR8232 BLE SDK Developer Handbook Blink for 3s with the frequency of 1Hz: turn on for 500ms, turn off for 500ms, and repeat for 3 times. led_cfg_t led_event1 = {500, 500 , 0x00, }; Blink for 50s with the frequency of 4Hz: turn on for 125ms, turn off for 125ms, and repeat for 200 times.
  • Page 168 Telink TLSR8232 BLE SDK Developer Handbook Users can refer to the code in current 5316 ble remote project for LED related processing. AN-19112700-E1 Ver.1.0.0...
  • Page 169: Blt Software Timer

    Telink TLSR8232 BLE SDK Developer Handbook 9. blt Software Timer Telink BLE SDK supplies source code of blt software timer demo for user reference on timer task. Users can directly use this timer or modify it as needed. Source code is available in “vendor/common/blt_soft_timer.c” and “blt_soft_timer.h”. To use this timer, the macro below should be set as 1.
  • Page 170 Telink TLSR8232 BLE SDK Developer Handbook The parameter “type” of the “blt_soft_timer_process” indicates two cases to enter this function: If “type” is 0, it indicates entering this function via inquiry in mainloop; if “type” is 1, it indicates entering this function when MCU is woke up in advance by timer.
  • Page 171 Telink TLSR8232 BLE SDK Developer Handbook The code above shows processing of timer task function: If the return value of this function is less than 0, this timer task will be deleted and won’t be responded; if the return value is 0, the previous timing value will be retained; if the return value is more than 0, this return value will be used as the new timing cycle (unit: us).
  • Page 172: Add Timer Task

    Telink TLSR8232 BLE SDK Developer Handbook 9.3 Add Timer Task The API below is used to add timer task. typedef int (*blt_timer_callback_t)(void); blt_soft_timer_add(blt_timer_callback_t func, interval_us); “func”: timer task function;“interval_us”: timing value (unit: us). The int-type return value corresponds to three processing methods: If the return value is less than 0, this executed task will be automatically deleted.
  • Page 173 Telink TLSR8232 BLE SDK Developer Handbook DBG_CHN0_TOGGLE; //gpio 0 toggle to see the effect return gpio_test1(void) DBG_CHN1_TOGGLE; //gpio 1 toggle to see the effect static flg = 0; flg = !flg; if(flg){ return 7000; else{ return 17000; gpio_test2(void) DBG_CHN2_TOGGLE; //gpio 2 toggle to see the effect...
  • Page 174 Telink TLSR8232 BLE SDK Developer Handbook Initialization: blt_soft_timer_init(); blt_soft_timer_add(&gpio_test0, 23000); blt_soft_timer_add(&gpio_test1, 7000); blt_soft_timer_add(&gpio_test2, 13000); blt_soft_timer_add(&gpio_test3, 27000); Four tasks are defined with differenet features: Toggle gpio_test0 once every 23ms. gpio_test1 uses 7ms/17ms toggle timer. Delete gpio_test2 after 5s, which can be implemented by invoking “blt_soft_timer_delete(&gpio_test2)”...
  • Page 175: Pwm Driver

    10. IR 10.1 PWM Driver Please refer to PWM section in TLSR8232 datasheet to better understand PWM driver. PWM related hardware configurations are very simple and are basically implemented by operating registers. APIs are all defined in “pwm.h” (c files not needed) and are implemented by using “static inline function”, which improves efficiency and saves code...
  • Page 176: Pwm Clock

    Telink TLSR8232 BLE SDK Developer Handbook Use “void gpio_set_func(GPIO_PinTypeDef pin, GPIO_FuncTypeDef func)” to set PWM function of pins. Pin: actual output pins of PWM waveform. func must select from AS_PWM0 ~ AS_PWM5_N in the definition of GPIO_FuncTypeDef according to actual PWM functions of GPIOs in the table above.
  • Page 177: Pwm Cycle And Duty

    Telink TLSR8232 BLE SDK Developer Handbook 10.1.3 PWM Cycle and Duty PWM waveform consists of PWM Signal Frames. For a PWM Signal Frame, “cycle” and “cmp” need to be configured via related APIs. void pwm_set_cycle(pwm_id unsigned short cycle_tick) This API is used to set PWM cycle, the unit is the number of PWM clocks.
  • Page 178: Pwm Revert

    IR DMA FIFO mod, while PWM1 ~ PWM5 only support normal mode. In other words, PWM0 supports other four special modes besides normal mode. Please section 8.5 in TLSR8232 datasheet for details of PWM modes. 10.1.7 PWM Pulse Number...
  • Page 179: Pwm Phase

    Telink TLSR8232 BLE SDK Developer Handbook 10.1.8 PWM Phase void pwm_set_phase(pwm_id unsigned short phase) is used to set delay time before PWM is started. “phase” is the delay time, the unit is the number of PWM clocks. Generally it can be set as 0 (no delay).
  • Page 180 Telink TLSR8232 BLE SDK Developer Handbook IR task IR task (pulse number = 3) (pulse number = 3) Signal Frame Signal Frame Signal Frame Signal Frame Signal Frame Signal Frame IRQ_PWM0_FRAME IRQ_PWM0_FRAME IRQ_PWM0_PNUM IRQ_PWM0_PNUM Figure 10-2 PWM interrupt IRQ_PWMn_FRAME(n=0,1,2,3,4,5) for PWM0~PWM5: After each signal frame, PWM#n (n=0~5) will generate a frame-done IRQ (Interrupt Request) signal “IRQ_PWMn_FRAME”.
  • Page 181: Api For Ir Dma Fifo Mode

    There are n FIFOs, and each FIFO has two bytes to indicate one PWM waveform. For TLSR8232, “n” can be up to 256. After DMA data buffer takes effect, PWM HW module will send out waveform 1 ~ waveform n successively.
  • Page 182: Set Dma Fifo Buffer

    Telink TLSR8232 BLE SDK Developer Handbook The “pulse_num” specifies the number of Signal Frames for current PWM waveform. The “pulse” supports two definitions below: Typedef enum{ PWM0_PULSE_NORMAL PWM0_PULSE_SHADOW BIT(14), }Pwm0Pulse_SelectDef;  When “pulse” is PWM0_PULSE_NORMAL, Signal Frame uses the configuration of the API “pwm_set_cycle_and_duty”.
  • Page 183: Demo Ir Protocol

    Telink TLSR8232 BLE SDK Developer Handbook As described in Link Layer timing sequence (section 3.2.4), Link Layers uses system interrupt to process brx event. (In the new SDK, adv event is processed in the main_loop and does not occupy system interrupt time.) When IR is about to switch PWM output soon, if brx event related interrupt comes first and occupies MCU time, the time to switch PWM output may be delayed, thus to result in IR error.
  • Page 184 Telink TLSR8232 BLE SDK Developer Handbook In IR DMA FIFO mode, a complete task is defined as FifoTask. Herein the processing of IR repeat signal adopts the method of “add repeat one by one”, i.e. the macro below is defined as 1.
  • Page 185 Telink TLSR8232 BLE SDK Developer Handbook FifoTask_data FifoTask_idle_repeat*n FifoTask_repeat*n 110 mS * n 110 mS * n 110mS …… …… data …… …… 2,3... 2,3... IR start IR dma fifo done IR dma fifo done IR dma fifo done interrupt...
  • Page 186: Ir Initialization

    Telink TLSR8232 BLE SDK Developer Handbook else if(ir_send_ctrl.is_sending == IR_SENDING_REPEAT){ //Add FifoTask_repeat*n to Dma pwm_start_dma_ir_sending(); else{ ir_send_release(); 10.2.4 IR Initialization 10.2.4.1 rc_ir_init IR initialization function is shown as below. Please refer to demo code in SDK. void rc_ir_init(void) 10.2.4.2 IR Hardware Configuration The demo code is as below: pwm_n_revert(PWM0_ID);...
  • Page 187: Ir Variable Initialization

    Telink TLSR8232 BLE SDK Developer Handbook Clear system status “FLD_IRQ_PWM0_IR_DMA_FIFO_DONE”. 10.2.4.3 IR Variable Initialization Related variables in the SDK demo includes waveform_start_bit_1st, waveform_start_bit_2nd, and etc. As introduced in IR timing design, FifoTask_data and FifoTask_repeat should be configured. Start signal = 9ms carrier signal + 4.5ms low level signal (no carrier). Call “pwm_config_dma_fifo_waveform”...
  • Page 188: Fifotask_Idle

    Telink TLSR8232 BLE SDK Developer Handbook T_dmaData_buf.data[T_dmaData_buf.data_num ++]= waveform_start_bit_1st; T_dmaData_buf.data[T_dmaData_buf.data_num ++]= waveform_start_bit_2nd; //add data data = (~cmd)<<24 | cmd<<16 | addr2<<8 | addr1; for(int i=0;i<32;i++){ if(data & BIT(i)){ //waveform for logic_1 T_dmaData_buf.data[T_dmaData_buf.data_num ++] = waveform_logic_1_1st; T_dmaData_buf.data[T_dmaData_buf.data_num ++] = waveform_logic_1_2nd; else{ //waveform for logic_0 T_dmaData_buf.data[T_dmaData_buf.data_num...
  • Page 189: Fifotask_Repeat

    Telink TLSR8232 BLE SDK Developer Handbook ir_send_ctrl.sending_start_time = clock_time(); Then calculate FifoTask_idle time in the interrupt triggered by completion of FifoTask_data: 110mS – (clock_time() - ir_send_ctrl.sending_start_time) Demo code: tick_2_repeat_sysClockTimer16M = 110*CLOCK_16M_SYS_TIMER_CLK_1MS – (clock_time() - ir_send_ctrl.sending_start_time); tick_2_repeat_sysTimer = (tick_2_repeat_sysClockTimer16M*CLOCK_SYS_CLOCK_1US>>4); Please pay attention to time unit switch. As introduced in Clock module, System Timer frequency used in software timer is fixed as 16MHz.
  • Page 190: Fifotask_Repeat*N&Fifotask_Idle_Repeat*N

    Telink TLSR8232 BLE SDK Developer Handbook T_dmaData_buf.data[T_dmaData_buf.data_num ++] = waveform_repeat_1st; T_dmaData_buf.data[T_dmaData_buf.data_num ++] = waveform_repeat_2nd; T_dmaData_buf.data[T_dmaData_buf.data_num ++] = waveform_repeat_3rd; T_dmaData_buf.data[T_dmaData_buf.data_num ++] = waveform_repeat_4th; 10.2.5.4 FifoTask_repeat*n&FifoTask_idle_repeat*n By simple superposition in DMA Fifo buffer, “FifoTask_repeat*n” and “FifoTask_idle_repeat*n” can be implemented on the basis of FifoTask_idle and FifoTask_repeat.
  • Page 191: Drivers In Ble Sdk

    11. Drivers in BLE SDK 11.1 External Capacitor for 24 MHz Crystal By default, SDK uses internal capacitor of TLSR8232 MCU (i.e. cap corresponding to ana_81<4:0>) as matching capacitor of 24MHz crystal oscillator, which is measurable and adjustable in Telink jig system to reach optimal frequency point value of final application product.
  • Page 192: Carrier Mode

    Telink TLSR8232 BLE SDK Developer Handbook EMI Test supports four test mode: Carrire mode (send carrier only), CD mode (send Carrirer with data), RX mode, TX mode. TX mode supports three sub-modes with different packet types. struct test_list_s ate_list[] = {...
  • Page 193: Tx Mode

    Telink TLSR8232 BLE SDK Developer Handbook rf_chn Set RF channel, the channel actually used is (2400+rf_chn). 11.3.1.3 TX Mode Tx mode can send packets of three different types, PRBS9 packet payload, 00001111 packet payload, 10101010 packet payload. Users can choose different Tx modes by cmd.
  • Page 194: Emi Test Tool

    Telink TLSR8232 BLE SDK Developer Handbook rf_mode Set RF mode, RF_MODE_BLE_1M and RF_MODE_BLE_2M are optional. Set tx power, see the definition of RF_TxPowerTypeDef for its values. rf_chn Set RF channel, the channel actually used is 2400+rf_chn). Note: EMI test is a demo project provided by Telink. Users can use this project to complete their own testing, and customize their own testing methods by calling related functions.
  • Page 195 Telink TLSR8232 BLE SDK Developer Handbook Figure 11-3 Swire synchronization operation Step 2: Set “chn”, i.e. input frequency (e.g. 2402) in the corresponding box and click “Set_Channel”. The log window will show “Swire OK” to indicate normal communication, as shown below.
  • Page 196 Telink TLSR8232 BLE SDK Developer Handbook Step 3: Select power level and BLE mode via the corresponding drop-down box, and click “Set_Power”/”Set_RF_Mode”. Figure 11-5 Select RF Mode Figure 11-6 Interface After RF Mode Setting Step 4: Click “Carrier”/“CarrierData”/“RXTest”/“PRBS9”/“0x55”/“0x0f” to enter corresponding test mode.
  • Page 197 Telink TLSR8232 BLE SDK Developer Handbook Figure 11-7 Select Test Mode Step 5: In TX mode, user can select to send 1000 packets or unlimited packets. Figure 11-8 Set TX Packet Number AN-19112700-E1 Ver.1.0.0...
  • Page 198 Telink TLSR8232 BLE SDK Developer Handbook Figure 11-9 TX Mode Interface Step 6: In RX mode, number of received packets can be read by clicking “Read_Rx_Cnt”, while current RSSI can be obtained by clicking “ReadRssi”, as shown below. Figure 11-10 Read RX Packet Number and RSSI AN-19112700-E1 Ver.1.0.0...
  • Page 199: Phy Test

    Telink TLSR8232 BLE SDK Developer Handbook 11.4 PHY Test To be added. AN-19112700-E1 Ver.1.0.0...
  • Page 200: Ble Spp Module

    Telink TLSR8232 BLE SDK Developer Handbook 12. BLE SPP Module Telink’s BLE module provides SPP (Serial Port Profile) data transmission, therefore users do not need to care about the implementation details of BLE and can focus on the data. 12.1 Command and Data Packet Format Telink BLE module use UART interface to communicate with Host.
  • Page 201 Telink TLSR8232 BLE SDK Developer Handbook Please refer to Table 12-3 and Table 12-4 for general commands and events. Table 12-3 General AT Command Set Corresponding CmdFunction cmdID ParaLen Parameters Format event Interval: e.g. Set Advertising e.g. 0x0050 Command 0xFF01...
  • Page 202 Telink TLSR8232 BLE SDK Developer Handbook Corresponding CmdFunction cmdID ParaLen Parameters Format event Parameter 1: addrType 0x00: Public Address 0F FF 07 00 Add White List Command 0xFF0F 0x0007 0x01: Random Address 00 01 02 03 Entry Complete event 04 05 06...
  • Page 203 Telink TLSR8232 BLE SDK Developer Handbook Corresponding CmdFunction cmdID ParaLen Parameters Format event Parameters: u16 intervalMin; e.g. 0x00A0 means current device accepts minimum connection interval 0xA0*1.25ms=200ms u16 intervalMax; e.g. 0x00A2 means current 15 FF 08 00 Set connection device accepts maximum...
  • Page 204 Telink TLSR8232 BLE SDK Developer Handbook Corresponding CmdFunction cmdID ParaLen Parameters Format event can be connected with this module. ‘0x00’: disable MAC binding function MacAddr MAC address to be added into e.g. Add device’s MAC binding table. MAC address Command...
  • Page 205 Telink TLSR8232 BLE SDK Developer Handbook Event name Type Token ParaLen EventID Parameters Format e,g, 0x0701 (cmdID=0xFF01, corresponding to the “Set Advertising Interval” command) data (indicates Variable: received data, n e.g. Data received bytes) 0xFF 0x07A0 FF 08 A0 07 Asynchronous Eg.If...
  • Page 206: Function Description

    Telink TLSR8232 BLE SDK Developer Handbook Event name Type Token ParaLen EventID Parameters Format Connected: 0x0800 12.2 Function Description To illustrate function of the module, conection between the module and a phone is taken an example. The app in the phone is LightBlue, the software in PC is a serial port assistant.
  • Page 207: Module Sends Commands And Data

    Telink TLSR8232 BLE SDK Developer Handbook Figure 12-2 Scan Module Device Figure 12-3 Connect Module Device After Telink module establishes BLE connection with the phone, in the phone App, users can see two “Telink SPP”, one is “Module->Phone” used for sending data to the phone from the module, another “Phone->Module”...
  • Page 208: Module Receives Data

    Telink TLSR8232 BLE SDK Developer Handbook Figure 12-4 Module Sending Data Figure 12-5 Phone Receiving Data 12.2.2 Module Receives Data The phone can send data to the module, the module will report to the PC after it receives the data, as...
  • Page 209 Telink TLSR8232 BLE SDK Developer Handbook Figure 12-6 is the data sent by the phone; the part highlighted by the red rectangle in Figure 12-7 is the data received by the module. Figure 12-6 Phone Sending Data Figure 12-7 Module Receiving Data AN-19112700-E1 Ver.1.0.0...
  • Page 210: Power Management Of Module

    Telink TLSR8232 BLE SDK Developer Handbook 12.3 Power Management of Module The 5316 module project enables low power by default, as the sleep mode of Telink MCU can only be woken up by GPIO, to implement the low power and the normal interconnection of data and commands between the module and the Host, the module project uses two GPIOs as wakeup sources which can be selected according to users’...
  • Page 211: Appendix

    Telink TLSR8232 BLE SDK Developer Handbook Appendix Appendix 1: crc16 Algorithm unsigned shortcrc16 (unsigned char *pD, len) static unsigned short poly[2]={0, 0xa001}; unsigned short crc = 0xffff; unsigned char i,j; for(j=len; j>0; j--) unsigned char ds = *pD++; for(i=0; i<8; i++) crc = (crc >>...

This manual is also suitable for:

Tlsr8232f512Tlsr8232f128

Table of Contents