-     wiced_result = wiced_bt_stack_init(app_bt_management_callback,
 
-                                  &wiced_bt_cfg_settings);
 
 
-     /* Check if stack initialization was successful */
 
-     if (WICED_BT_SUCCESS == wiced_result) {
 
-         printf("Bluetooth Stack Initialization Successful \n");
 
-     } else {
 
-         printf("Bluetooth Stack Initialization failed!!\n");
 
-     }
注册GATT事件回调函数:
- wiced_bt_gatt_status_t
 
- app_bt_gatt_event_callback(wiced_bt_gatt_evt_t event,
 
-                            wiced_bt_gatt_event_data_t *p_event_data)
 
- {
 
 
-     wiced_bt_gatt_status_t gatt_status = WICED_BT_GATT_ERROR;
 
-     wiced_bt_gatt_attribute_request_t *p_attr_req = NULL;
 
 
-     uint16_t error_handle = 0;
 
 
-     switch (event)
 
-     {
 
 
-     case GATT_CONNECTION_STATUS_EVT:
 
-         gatt_status = app_gatt_connect_handler(&p_event_data->connection_status);
 
-         break;
 
 
-     case GATT_ATTRIBUTE_REQUEST_EVT:
 
-         p_attr_req = &p_event_data->attribute_request;
 
-         gatt_status = app_gatts_attr_req_handler(p_attr_req,
 
-                                                  &error_handle);
 
 
-         if(gatt_status != WICED_BT_GATT_SUCCESS)
 
-         {
 
-            wiced_bt_gatt_server_send_error_rsp(p_attr_req->conn_id,
 
-                                                p_attr_req->opcode,
 
-                                                error_handle,
 
-                                                gatt_status);
 
-         }
 
 
-         break;
 
 
-     case GATT_GET_RESPONSE_BUFFER_EVT:
 
-     {
 
-         wiced_bt_gatt_buffer_request_t *p_buf_req = &p_event_data->buffer_request;
 
-         printf("len_req %d \n", p_buf_req->len_requested);
 
-         p_buf_req->buffer.p_app_rsp_buffer = app_alloc_buffer(p_buf_req->len_requested);
 
-         p_buf_req->buffer.p_app_ctxt = (void *)app_free_buffer;
 
-         gatt_status = WICED_BT_GATT_SUCCESS;
 
-     }
 
-         break;
 
 
-     case GATT_APP_BUFFER_TRANSMITTED_EVT:
 
-     {
 
-         pfn_free_buffer_t pfn_free;
 
-         pfn_free = (pfn_free_buffer_t)p_event_data->buffer_xmitted.p_app_ctxt;
 
-         /* If the buffer is dynamic, the context will point to a function to
 
-          * free it.
 
-          */
 
-         if (pfn_free)
 
-         {
 
-             pfn_free(p_event_data->buffer_xmitted.p_app_data);
 
-         }
 
-         gatt_status = WICED_BT_GATT_SUCCESS;
 
-     }
 
-        break;
 
 
-     default:
 
-         printf("Unhandled GATT Event %d", event);
 
-         break;
 
 
-     }
 
 
-     return gatt_status;
 
- }
串口打印初始化:
-     cy_retarget_io_init(CYBSP_DEBUG_UART_TX,
 
-                         CYBSP_DEBUG_UART_RX,
 
-                         CY_RETARGET_IO_BAUDRATE);
在BLE client开启notfiy功能后,处理相应的数据发送任务:
- void ess_task(void *pvParam)
 
- {
 
-     while(true)
 
-     {
 
-         ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
 
-         /* Varying temperature by 1 degree on every timeout for simulation */
 
-         if (0 == alternating_flag)
 
-         {
 
-             temperature += DELTA_TEMPERATURE;
 
-             if (MAX_TEMPERATURE_LIMIT <= temperature)
 
-             {
 
-                 alternating_flag = 1;
 
-             }
 
-         }
 
-         else if ((1 == alternating_flag))
 
-         {
 
-             temperature -= DELTA_TEMPERATURE;
 
-             if (MIN_TEMPERATURE_LIMIT >= temperature)
 
-             {
 
-                 alternating_flag = 0;
 
-             }
 
-         }
 
 
-         printf("\nTemperature (in degree Celsius) \t\t%d.%02d\n",
 
-                 (temperature / 100), ABS(temperature % 100));
 
 
-         /*
 
-         * app_ess_temperature value is set both for read operation and
 
-         * notify operation.
 
-         */
 
-         app_ess_temperature[0] = (uint8_t)(temperature & 0xff);
 
-         app_ess_temperature[1] = (uint8_t)((temperature >> 8) & 0xff);
 
 
-         /* To check that connection is up and
 
-         * client is registered to receive notifications
 
-         * to send temperature data in Little Endian Format
 
-         * as per BT SIG's ESS Specification
 
-         */
 
 
-         if (IS_NOTIFIABLE (app_bt_conn_id, app_ess_temperature_client_char_config[0]) == 0)
 
-         {
 
-             if(!app_bt_conn_id)
 
-             {
 
-                 printf("This device is not connected to a central device\n");
 
-             }else{
 
-                 printf("This device is connected to a central device but\n"
 
-                         "GATT client notifications are not enabled\n");
 
-             }
 
-         }
 
-         else
 
-         {
 
-             wiced_bt_gatt_status_t gatt_status;
 
 
-             /*
 
-             * Sending notification, set the pv_app_context to NULL, since the
 
-             * data 'app_ess_temperature' is not to be freed
 
-             */
 
-             gatt_status = wiced_bt_gatt_server_send_notification(app_bt_conn_id,
 
-                                                                     HDLC_ESS_TEMPERATURE_VALUE,
 
-                                                                     app_ess_temperature_len,
 
-                                                                     app_ess_temperature,
 
-                                                                     NULL);
 
 
-             printf("Sent notification status 0x%x\n", gatt_status);
 
 
-         }
 
-     }
 
- }
开启BLE广播:
-     app_start_advertisement();
编译,进入调试:
- Started by GNU MCU Eclipse
 
- Open On-Chip Debugger 0.12.0+dev-5.7.0.3672 (2025-03-04-03:08)
 
- Licensed under GNU GPL v2
 
- For bug reports, read
 
-         http://openocd.org/doc/doxygen/bugs.html
 
- adapter speed: 2000 kHz
 
- adapter srst delay: 25
 
- adapter srst pulse_width: 25
 
- ** Auto-acquire enabled, use "set ENABLE_ACQUIRE 0" to disable
 
- Info : Using CMSIS-flash algorithms 'CY8C6xxA_SMIF' for bank 'psoc6_smif0_cm0' (footprint 17632 bytes)
 
- Info : CMSIS-flash: ELF path: ../flm/cypress/cat1a/CY8C6xxA_SMIF.FLM
 
- Info : CMSIS-flash: Address range:     0x18000000-0x1FFFFFFF
 
- Info : CMSIS-flash: Program page size: 0x00001000 bytes
 
- Info : CMSIS-flash: Erase sector size: 0x00040000 bytes, unified
 
- Warn : SFlash programming allowed for regions: USER, TOC, KEY
 
- Info : Using CMSIS-DAPv2 interface with VID:PID=0x04b4:0xf155, serial=16160E5A012D2400
 
- Info : CMSIS-DAP: SWD supported
 
- Info : CMSIS-DAP: Atomic commands supported
 
- Info : CMSIS-DAP: FW Version = 2.0.0
 
- Info : CMSIS-DAP: Interface Initialised (SWD)
 
- Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
 
- Info : CMSIS-DAP: Interface ready
 
- Info : KitProg3: FW version: 2.80.1506
 
- Info : KitProg3: Pipelined transfers enabled
 
- Info : KitProg3: Asynchronous USB transfers enabled
 
- Info : VTarget = 3.311 V
 
- Info : kitprog3: acquiring device in Test Mode using 'PSOC 6' target and 'xres' reset...
 
- Info : clock speed 2000 kHz
 
- Info : SWD DPIDR 0x6ba02477
 
- Info : [psoc6.cpu.cm0] Cortex-M0+ r0p1 processor detected
 
- Info : [psoc6.cpu.cm0] target has 4 breakpoints, 2 watchpoints
 
- ***************************************
 
- ** Silicon: 0xE453, Family: 0x102, Rev.: 0x12 (A1)
 
- ** Detected Device: CY8C624ABZI-S2D44
 
- ** Detected Main Flash size, kb: 2048
 
- ** Flash Boot version: 3.1.0.378
 
- ** SFlash version: 0x47530
 
- ** Chip Protection: NORMAL
 
- ***************************************
 
- Info : [psoc6.cpu.cm0] Examination succeed
 
- Info : [psoc6.cpu.cm4] Cortex-M4 r0p1 processor detected
 
- Info : [psoc6.cpu.cm4] target has 6 breakpoints, 4 watchpoints
 
- Info : [psoc6.cpu.cm4] Examination succeed
 
- Info : starting gdb server for psoc6.cpu.cm0 on 3332
 
- Info : Listening on port 3332 for gdb connections
 
- Info : starting gdb server for psoc6.cpu.cm4 on 3333
 
- Info : Listening on port 3333 for gdb connections
 
- Info : SWD DPIDR 0x6ba02477
 
- Info : kitprog3: acquiring device in Test Mode using 'PSOC 6' target and 'xres' reset...
 
- [psoc6.cpu.cm0] halted due to debug-request, current mode: Thread 
 
- xPSR: 0x41000000 pc: 0x00000190 msp: 0x080ff800
 
- ** Device acquired successfully
 
- ** psoc6.cpu.cm4: Ran after reset and before halt...
 
- [psoc6.cpu.cm4] halted due to debug-request, current mode: Thread 
 
- xPSR: 0x01000000 pc: 0x0000012a msp: 0x080ff800
 
- Started by GNU MCU Eclipse
 
- Info : Listening on port 6666 for tcl connections
 
- Info : Listening on port 4444 for telnet connections
 
- Info : accepting 'gdb' connection on tcp/3333
 
- Info : New GDB Connection: 1, Target psoc6.cpu.cm4, state: halted
 
- Warn : Prefer GDB command "target extended-remote :3333" instead of "target remote :3333"
 
- semihosting is enabled
 
- Info : Auto-detected RTOS: FreeRTOS
 
- Info : Auto-detected RTOS: FreeRTOS
 
- Verifying region (0x10000000,      6352)... Match
 
- Verifying region (0x10002000,    165228)... Mismatch
 
- Info : Data mismatch, proceeding with flash programming
 
- Info : Flash write discontinued at 0x100018d0, next section at 0x10002000
 
- Info : Padding image section 0 at 0x100018d0 with 304 bytes (bank write end alignment)
 
 
- [100%] [################################] [ Erasing     ]
 
 
- [100%] [################################] [ Programming ]
 
- Info : Padding image section 1 at 0x1002a56c with 148 bytes (bank write end alignment)
 
 
- [ 34%] [##########                      ] [ Erasing     ]
 
- [ 37%] [###########                     ] [ Erasing     ]
 
- [ 41%] [#############                   ] [ Erasing     ]
 
- [ 44%] [##############                  ] [ Erasing     ]
 
- [ 48%] [###############                 ] [ Erasing     ]
 
- [ 53%] [################                ] [ Erasing     ]
 
- [ 55%] [#################               ] [ Erasing     ]
 
- [ 60%] [###################             ] [ Erasing     ]
 
- [ 67%] [#####################           ] [ Erasing     ]
 
- [ 69%] [######################          ] [ Erasing     ]
 
- [ 74%] [#######################         ] [ Erasing     ]
 
- [ 76%] [########################        ] [ Erasing     ]
 
- [ 81%] [#########################       ] [ Erasing     ]
 
- [ 83%] [##########################      ] [ Erasing     ]
 
- [ 86%] [###########################     ] [ Erasing     ]
 
- [ 88%] [############################    ] [ Erasing     ]
 
- [ 95%] [##############################  ] [ Erasing     ]
 
- [ 97%] [############################### ] [ Erasing     ]
 
- [100%] [################################] [ Erasing     ]
 
 
- [ 17%] [#####                           ] [ Programming ]
 
- [ 19%] [######                          ] [ Programming ]
 
- [ 23%] [#######                         ] [ Programming ]
 
- [ 26%] [########                        ] [ Programming ]
 
- [ 29%] [#########                       ] [ Programming ]
 
- [ 34%] [##########                      ] [ Programming ]
 
- [ 36%] [###########                     ] [ Programming ]
 
- [ 43%] [#############                   ] [ Programming ]
 
- [ 53%] [################                ] [ Programming ]
 
- [ 54%] [#################               ] [ Programming ]
 
- [ 63%] [####################            ] [ Programming ]
 
- [ 72%] [#######################         ] [ Programming ]
 
- [ 81%] [#########################       ] [ Programming ]
 
- [ 91%] [#############################   ] [ Programming ]
 
- [100%] [################################] [ Programming ]
 
- Info : SWD DPIDR 0x6ba02477
 
- Info : kitprog3: acquiring device in Test Mode using 'PSOC 6' target and 'xres' reset...
 
- [psoc6.cpu.cm0] halted due to debug-request, current mode: Thread 
 
- xPSR: 0x41000000 pc: 0x00000190 msp: 0x080ff800
 
- ** Device acquired successfully
 
- ** psoc6.cpu.cm4: Ran after reset and before halt...
 
- [psoc6.cpu.cm4] halted due to debug-request, current mode: Thread 
 
- xPSR: 0x01000000 pc: 0x0000012a msp: 0x080ff800, semihosting
 
- Info : SWD DPIDR 0x6ba02477
 
- [psoc6.cpu.cm4] halted due to debug-request, current mode: Thread 
 
- xPSR: 0x01000000 pc: 0x100066b2 msp: 0x080ff7b0, semihosting
 
- Info : psoc6.cpu.cm4: Waiting up to 10.0 sec for valid Vector Table address...
 
- Info : psoc6.cpu.cm4: Vector Table found at 0x10002000
 
- Info : psoc6.cpu.cm4: bkpt @0x10002371, issuing SYSRESETREQ
 
- Info : SWD DPIDR 0x6ba02477
 
- Info : [psoc6.cpu.cm4] Examination succeed
 
- [psoc6.cpu.cm4] halted due to debug-request, current mode: Thread 
 
- xPSR: 0x61000000 pc: 0x10002370 msp: 0x080ff800, semihosting
 
- Info : [psoc6.cpu.cm0] external reset detected
 
- ===== arm v7m registers
 
- (0) r0 (/32): 0x08002a28
 
- (1) r1 (/32): 0x00000000
 
- (2) r2 (/32): 0x08000000
 
- (3) r3 (/32): 0x00000000
 
- (4) r4 (/32): 0x10029e14
 
- (5) r5 (/32): 0x10029e14
 
- (6) r6 (/32): 0x04c11db7
 
- (7) r7 (/32): 0x08027fff
 
- (8) r8 (/32): 0xa5a5a5a5
 
- (9) r9 (/32): 0xa5a5a5a5
 
- (10) r10 (/32): 0xa5a5a5a5
 
- (11) r11 (/32): 0xa5a5a5a5
 
- (12) r12 (/32): 0x080ff7e0
 
- (13) sp (/32): 0x080ff800
 
- (14) lr (/32): 0x100023c1
 
- (15) pc (/32): 0x10003438
 
- (16) xpsr (/32): 0x61000000
 
- (17) msp (/32): 0x080ff800
 
- (18) psp (/32): 0x080165d0
 
- (20) primask (/1): 0x01
 
- (21) basepri (/8): 0x00
 
- (22) faultmask (/1): 0x00
 
- (23) control (/3): 0x00
 
- (42) d0 (/64): 0xbe83b103bef15aea
 
- (43) d1 (/64): 0x3de2fd523c45f6d0
 
- (44) d2 (/64): 0x3bee7fa03e86da6a
 
- (45) d3 (/64): 0xbd727f443c8351f0
 
- (46) d4 (/64): 0xc012ddaac00be208
 
- (47) d5 (/64): 0x37f5000037dc0000
 
- (48) d6 (/64): 0x3db4a8c93d5b2f20
 
- (49) d7 (/64): 0x3eb67b013f000000
 
- (50) d8 (/64): 0xdfffbf6ff3dbfebf
 
- (51) d9 (/64): 0x7ea9eeefff7f74ff
 
- (52) d10 (/64): 0xbffbffbf7e7ffeed
 
- (53) d11 (/64): 0xfefafeefe7feffbf
 
- (54) d12 (/64): 0xffbffbeffffbffaf
 
- (55) d13 (/64): 0xffffff6ffffbfeaf
 
- (56) d14 (/64): 0xfffbfbff77ffbfff
 
- (57) d15 (/64): 0xeffeffdffbfcf7ff
 
- (58) fpscr (/32): 0x00000000
 
- ===== Cortex-M DWT registers
Android上安装英飞凌BLE调试工具:AIROC™ Bluetooth® Connect
进入App后,扫描BLE外设(Server):目标设备是Thermistor
点击设备名称,发起连接。点击“Enviornment Sensing service”
点击Yes:
继续点击:
点击Notify:
实时温度数据正常被推送:
串口输出结果:
- Temperature (in degree Celsius)                 21.00
 
- Notfication send complete
 
- Sent notification status 0x0
 
 
- Temperature (in degree Celsius)                 22.00
 
- Notfication send complete
 
- Sent notification status 0x0
 
 
- Temperature (in degree Celsius)                 23.00
 
- Notfication send complete
 
- Sent notification status 0x0
 
 
- Temperature (in degree Celsius)                 24.00
 
- Notfication send complete
 
- Sent notification status 0x0
 
 
- Temperature (in degree Celsius)                 25.00
 
- Notfication send complete
 
- Sent notification status 0x0