@@ -553,21 +553,14 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
553553 } else {
554554 m_adv_params .type = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND ;
555555 }
556+
556557 m_adv_params .p_peer_addr = NULL ; // undirected advertisement
557558 m_adv_params .fp = BLE_GAP_ADV_FP_ANY ;
558559 m_adv_params .interval = MSEC_TO_UNITS (100 , UNIT_0_625_MS ); // approx 8 ms
559560 m_adv_params .timeout = 0 ; // infinite advertisment
560561
561- #if (BLUETOOTH_SD == 132 )
562- if (m_adv_in_progress == true) {
563- if (sd_ble_gap_adv_stop () != 0 ) {
564- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError ,
565- "Can not stop advertisment." ));
566- }
567- }
568- #endif
562+ ble_drv_advertise_stop ();
569563
570- m_adv_in_progress = false;
571564 err_code = sd_ble_gap_adv_start (& m_adv_params );
572565 if (err_code != 0 ) {
573566 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError ,
@@ -579,6 +572,17 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
579572 return true;
580573}
581574
575+ void ble_drv_advertise_stop (void ) {
576+ if (m_adv_in_progress == true) {
577+ uint32_t err_code ;
578+ if ((err_code = sd_ble_gap_adv_stop ()) != 0 ) {
579+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError ,
580+ "Can not stop advertisment. status: 0x" HEX2_FMT , (uint16_t )err_code ));
581+ }
582+ }
583+ m_adv_in_progress = false;
584+ }
585+
582586void ble_drv_attr_s_read (uint16_t conn_handle , uint16_t handle , uint16_t len , uint8_t * p_data ) {
583587 ble_gatts_value_t gatts_value ;
584588 memset (& gatts_value , 0 , sizeof (gatts_value ));
0 commit comments