Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SDK15: Serialization example crashes

I started today with the following examples to make a start with serialization:

- ..\examples\connectivity\ble_connectivity\pca10040\ser_s132_hci

- ..\examples\ble_peripheral\ble_app_hrs\pca10040\ser_s132_hci

Both projects are installed on a PCA10040 and i followed the following guide:

infocenter.nordicsemi.com/.../nrf51_setups_serialization.html

I see the following behavior with RTT logging enabled:

Both applications crash after 3 minutes, advertising timeout.

After some searching i found that the following ble_event was missing from the encode and decode blocks: BLE_GAP_EVT_ADV_SET_TERMINATED.

Another feature that was missing was the sleep functionality in the connectivity example. This also causes the connectivity application to crash.

Has somebody any idea if more features/changes are overlooked in the latest SDK version of the serialization/ble_connectivity examples?

Thanks in advance,

Erwin

  • Hi Erwin,

    Unfortunately, event handling for BLE_GAP_EVT_ADV_SET_TERMINATED is not implemented in the connectivity FW as you've noticed.  This leads to a code assertion once the timeout occurs instead of entering system OFF mode. I have reported this as a bug internally, will keep you posted.

    Update 5/7 - 2018

    Looks like found the missing pieces, see reply here: https://devzone.nordicsemi.com/f/nordic-q-a/33106/bug-ble_gap_evt_adv_set_terminated-is-never-raised 

    Quickly tried it here, and it seems to fix the issue with not going to sleep. Here are the changes: 

    diff --git a/components/serialization/application/codecs/ble/serializers/ble_event.c b/components/serialization/application/codecs/ble/serializers/ble_event.c
    index e32a905..e046072 100644
    --- a/components/serialization/application/codecs/ble/serializers/ble_event.c
    +++ b/components/serialization/application/codecs/ble/serializers/ble_event.c
    @@ -295,6 +295,9 @@ uint32_t ble_event_dec(uint8_t const * const p_buf,
             case BLE_GAP_EVT_SCAN_REQ_REPORT:
                 fp_event_decoder = ble_gap_evt_scan_req_report_dec;
                 break;
    +				
    +				case BLE_GAP_EVT_ADV_SET_TERMINATED:
    +						fp_event_decoder = ble_gap_evt_adv_set_terminated_dec;
             default:
                 break;
         }
    diff --git a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.h b/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.h
    index b36e70b..053b0ed 100644
    --- a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.h
    +++ b/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.h
    @@ -536,6 +536,30 @@ uint32_t ble_gap_evt_data_length_update_dec(uint8_t const * const p_buf,
                                      uint32_t              packet_len,
                                      ble_evt_t * const     p_event,
                                      uint32_t * const      p_event_len);
    +																 
    +/**
    + * @brief Decodes ble_gap_evt_data_length_update event.
    + *
    + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
    + *
    + * @param[in] p_buf            Pointer to the beginning of an event packet.
    + * @param[in] packet_len       Length (in bytes) of the event packet.
    + * @param[in,out] p_event      Pointer to a \ref ble_evt_t buffer where the decoded event will be
    + *                             stored. If NULL, required length will be returned in \p p_event_len.
    + * @param[in,out] p_event_len  \c in: Size (in bytes) of \p p_event buffer.
    + *                             \c out: Length of decoded contents of \p p_event.
    + *
    + * @retval NRF_SUCCESS               Decoding success.
    + * @retval NRF_ERROR_NULL            Decoding failure. NULL pointer supplied.
    + * @retval NRF_ERROR_INVALID_LENGTH  Decoding failure. Incorrect buffer length.
    + * @retval NRF_ERROR_DATA_SIZE       Decoding failure. Length of \p p_event is too small to
    + *                                   hold decoded event.
    + */
    +																 
    +uint32_t ble_gap_evt_adv_set_terminated_dec(uint8_t const * const p_buf,
    +                                 uint32_t              packet_len,
    +                                 ble_evt_t * const     p_event,
    +                                 uint32_t * const      p_event_len);
     #endif
     /** @} */
     
    diff --git a/components/serialization/connectivity/codecs/ble/serializers/ble_event_enc.c b/components/serialization/connectivity/codecs/ble/serializers/ble_event_enc.c
    index ff075f1..5111e8b 100644
    --- a/components/serialization/connectivity/codecs/ble/serializers/ble_event_enc.c
    +++ b/components/serialization/connectivity/codecs/ble/serializers/ble_event_enc.c
    @@ -284,6 +284,10 @@ uint32_t ble_event_enc(ble_evt_t const * const p_event,
             case BLE_GAP_EVT_SCAN_REQ_REPORT:
                 ret_val = ble_gap_evt_scan_req_report_enc(p_event, event_len, p_buf, p_buf_len);
                 break;
    +				
    +				case BLE_GAP_EVT_ADV_SET_TERMINATED:
    +						ret_val = ble_gap_evt_adv_set_terminated_enc(p_event, event_len, p_buf, p_buf_len);
    +						break;
     
             default:
                 ret_val    = NRF_ERROR_NOT_SUPPORTED;
    diff --git a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_evt_conn.h b/components/serialization/connectivity/codecs/ble/serializers/ble_gap_evt_conn.h
    index 889d0b6..c7bc2f0 100644
    --- a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_evt_conn.h
    +++ b/components/serialization/connectivity/codecs/ble/serializers/ble_gap_evt_conn.h
    @@ -433,6 +433,26 @@ uint32_t ble_gap_evt_data_length_update_enc(ble_evt_t const * const p_event,
                                      uint32_t                event_len,
                                      uint8_t * const         p_buf,
                                      uint32_t * const        p_buf_len);
    +																 
    +
    +
    +/**
    + * @brief Encodes ble_gap_evt_adv_set_terminated event.
    + *
    + * @param[in] p_event          Pointer to the \ref ble_evt_t buffer that shall be encoded.
    + * @param[in] event_len        Size (in bytes) of \p p_event buffer.
    + * @param[out] p_buf           Pointer to the beginning of a buffer for encoded event packet.
    + * @param[in,out] p_buf_len    \c in: Size (in bytes) of \p p_buf buffer.
    + *                             \c out: Length of encoded contents in \p p_buf.
    + *
    + * @retval NRF_SUCCESS               Encoding success.
    + * @retval NRF_ERROR_NULL            Encoding failure. NULL pointer supplied.
    + * @retval NRF_ERROR_INVALID_LENGTH  Encoding failure. Incorrect buffer length.
    + */																 
    +uint32_t ble_gap_evt_adv_set_terminated_enc(ble_evt_t const * const p_event,
    +                                 uint32_t                event_len,
    +                                 uint8_t * const         p_buf,
    +                                 uint32_t * const        p_buf_len);
     #endif
     /** @} */
     
    diff --git a/components/serialization/connectivity/codecs/common/conn_mw_nrf_soc.c b/components/serialization/connectivity/codecs/common/conn_mw_nrf_soc.c
    index 62d034e..a03e536 100644
    --- a/components/serialization/connectivity/codecs/common/conn_mw_nrf_soc.c
    +++ b/components/serialization/connectivity/codecs/common/conn_mw_nrf_soc.c
    @@ -57,6 +57,7 @@ uint32_t conn_mw_power_system_off(uint8_t const * const p_rx_buf,
     
         err_code = sd_power_system_off();
         /* There should be no return from sd_power_system_off() */
    +		while(1);
     
         return err_code;
     }
    

    Note that the program will return from sd_power_system_off() if the chip is in debug interface mode which leads to a code assert, see "emulated system off": http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/power.html?cp=2_1_0_17_1_0#unique_1199040052 

Related