Skip to content

nrf5x: Enable asserts -> mbed_error #6022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,10 @@ static void btle_handler(ble_evt_t *p_ble_evt)
gattServer.hwCallback(p_ble_evt);
}

/*! @brief Callback when an error occurs inside the SoftDevice */
/*! @brief Callback when an error occurs inside the SoftDevice or ASSERT in debug*/
void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name)
{
ASSERT_TRUE(false, (void) 0);
error("nrf failure at %s:%d", p_file_name, line_num);
}

/*!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ static void btle_handler(ble_evt_t *p_ble_evt)
gattServer.hwCallback(p_ble_evt);
}

/*! @brief Callback when an error occurs inside the SoftDevice */
/*! @brief Callback when an error occurs inside the SoftDevice or ASSERT in debug*/
void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name)
{
ASSERT_TRUE(false, (void) 0);
error("nrf failure at %s:%d", p_file_name, line_num);
}

#if NRF_SD_BLE_API_VERSION >= 5
Expand Down
12 changes: 11 additions & 1 deletion targets/TARGET_NORDIC/TARGET_NRF5x/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Nordic NRF52
# Nordic NRF5x

## Adding New Targets Based On Nordic NRF52832 And NRF52840 MCUs

Expand Down Expand Up @@ -144,6 +144,16 @@ Because each DMA buffer must be at least 5 bytes deep, each buffer is automatica

The RTC2 ISR is set at the lowest interrupt priority to ensure that UARTE interrupts take precedence. The last 2 of the 4 RTC channels are used for decoupling UARTE ISR context from Mbed IRQ events. This ensures that any user code will only delay other user callbacks and idle flushing and puts an upper bound on the interrupt handling time for the UARTE ISR.


#### Asserts

The nordic asserts have been redirected to mbed error handling when building in debug mode.
The SDK file `mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/util/nrf_assert.h` was modified to enable the asserts when NDEBUG is not defined.

The assert handler is defined in mbed-os/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5x/source/btle/btle.cpp : assert_nrf_callback() which forwards assert failures to thye mbed error() handler.



#### Limitations

* The UARTE hardware only supports 8-bit, None/Even parity, and 1 stop bit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ void nrf_drv_adc_uninit(void)

void nrf_drv_adc_channel_enable(nrf_drv_adc_channel_t * const p_channel)
{
ASSERT(mp_state == NRF_DRV_STATE_INITIALIZED);
ASSERT(!is_address_from_stack(p_channel));
ASSERT(m_cb.state == NRF_DRV_STATE_INITIALIZED);
// This assert has been removed as it requires non-existent symbols from linker
//ASSERT(!is_address_from_stack(p_channel));

p_channel->p_next = NULL;
if (m_cb.p_head == NULL)
Expand All @@ -114,7 +115,7 @@ void nrf_drv_adc_channel_enable(nrf_drv_adc_channel_t * const p_channel)

void nrf_drv_adc_channel_disable(nrf_drv_adc_channel_t * const p_channel)
{
ASSERT(mp_state == NRF_DRV_STATE_INITIALIZED);
ASSERT(m_cb.state == NRF_DRV_STATE_INITIALIZED);
ASSERT(m_cb.p_head);

nrf_drv_adc_channel_t * p_curr_channel = m_cb.p_head;
Expand All @@ -137,15 +138,15 @@ void nrf_drv_adc_channel_disable(nrf_drv_adc_channel_t * const p_channel)

void nrf_drv_adc_sample(void)
{
ASSERT(mp_state != NRF_DRV_STATE_UNINITIALIZED);
ASSERT(m_cb.state != NRF_DRV_STATE_UNINITIALIZED);
ASSERT(!nrf_adc_is_busy());
nrf_adc_start();
}

ret_code_t nrf_drv_adc_sample_convert(nrf_drv_adc_channel_t const * const p_channel,
nrf_adc_value_t * p_value)
{
ASSERT(mp_state != NRF_DRV_STATE_UNINITIALIZED);
ASSERT(m_cb.state != NRF_DRV_STATE_UNINITIALIZED);
if(m_cb.state == NRF_DRV_STATE_POWERED_ON)
{
return NRF_ERROR_BUSY;
Expand Down Expand Up @@ -212,7 +213,7 @@ static bool adc_sample_process()

ret_code_t nrf_drv_adc_buffer_convert(nrf_adc_value_t * buffer, uint16_t size)
{
ASSERT(mp_state != NRF_DRV_STATE_UNINITIALIZED);
ASSERT(m_cb.state != NRF_DRV_STATE_UNINITIALIZED);
if(m_cb.state == NRF_DRV_STATE_POWERED_ON)
{
return NRF_ERROR_BUSY;
Expand Down Expand Up @@ -250,7 +251,7 @@ ret_code_t nrf_drv_adc_buffer_convert(nrf_adc_value_t * buffer, uint16_t size)

bool nrf_drv_adc_is_busy(void)
{
ASSERT(mp_state != NRF_DRV_STATE_UNINITIALIZED);
ASSERT(m_cb.state != NRF_DRV_STATE_UNINITIALIZED);
return (m_cb.state == NRF_DRV_STATE_POWERED_ON) ? true : false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
#endif
// <h> Board Support

// Enable NRF Asserts when Mbed NDEBUG is not set
#if !defined(NDEBUG) && !defined(DEBUG_NRF_USER)
#define DEBUG_NRF_USER
#endif

//==========================================================
// <q> BSP_BTN_BLE_ENABLED - bsp_btn_ble - Button Control for BLE

Expand Down Expand Up @@ -4287,6 +4292,7 @@
//==========================================================
// <e> NRF_LOG_ENABLED - Logging module for nRF5 SDK
//==========================================================

#ifndef NRF_LOG_ENABLED
#define NRF_LOG_ENABLED 0
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
#endif
// <h> Board Support

// Enable NRF Asserts when Mbed NDEBUG is not set
#if !defined(NDEBUG) && !defined(DEBUG_NRF_USER)
#define DEBUG_NRF_USER
#endif

//==========================================================
// <q> BSP_BTN_BLE_ENABLED - bsp_btn_ble - Button Control for BLE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
extern "C" {
#endif

#if !defined(NDEBUG) && !defined(DEBUG_NRF_USER)
#define DEBUG_NRF_USER
#endif

#if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)

/** @brief Function for handling assertions.
Expand Down