Skip to content

Commit 2d0e5f0

Browse files
authored
Merge pull request #6022 from andrewleech/nrf_asserts_error
nrf5x: Enable asserts -> mbed_error
2 parents 66e3409 + 67140a2 commit 2d0e5f0

File tree

7 files changed

+38
-12
lines changed

7 files changed

+38
-12
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/btle/btle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ void btle_handler(ble_evt_t *p_ble_evt)
254254
gattServer.hwCallback(p_ble_evt);
255255
}
256256

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

263263
/*!

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/btle/btle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,10 @@ void btle_handler(const ble_evt_t *p_ble_evt)
402402
gattServer.hwCallback(p_ble_evt);
403403
}
404404

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

411411
#if NRF_SD_BLE_API_VERSION >= 5

targets/TARGET_NORDIC/TARGET_NRF5x/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Nordic NRF52
1+
# Nordic NRF5x
22

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

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

145145
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.
146146

147+
148+
#### Asserts
149+
150+
The nordic asserts have been redirected to mbed error handling when building in debug mode.
151+
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.
152+
153+
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.
154+
155+
156+
147157
#### Limitations
148158

149159
* The UARTE hardware only supports 8-bit, None/Even parity, and 1 stop bit.

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF51/TARGET_MCU_NRF51822_UNIFIED/sdk/drivers_nrf/adc/nrf_drv_adc.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ void nrf_drv_adc_uninit(void)
9292

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

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

115116
void nrf_drv_adc_channel_disable(nrf_drv_adc_channel_t * const p_channel)
116117
{
117-
ASSERT(mp_state == NRF_DRV_STATE_INITIALIZED);
118+
ASSERT(m_cb.state == NRF_DRV_STATE_INITIALIZED);
118119
ASSERT(m_cb.p_head);
119120

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

138139
void nrf_drv_adc_sample(void)
139140
{
140-
ASSERT(mp_state != NRF_DRV_STATE_UNINITIALIZED);
141+
ASSERT(m_cb.state != NRF_DRV_STATE_UNINITIALIZED);
141142
ASSERT(!nrf_adc_is_busy());
142143
nrf_adc_start();
143144
}
144145

145146
ret_code_t nrf_drv_adc_sample_convert(nrf_drv_adc_channel_t const * const p_channel,
146147
nrf_adc_value_t * p_value)
147148
{
148-
ASSERT(mp_state != NRF_DRV_STATE_UNINITIALIZED);
149+
ASSERT(m_cb.state != NRF_DRV_STATE_UNINITIALIZED);
149150
if(m_cb.state == NRF_DRV_STATE_POWERED_ON)
150151
{
151152
return NRF_ERROR_BUSY;
@@ -212,7 +213,7 @@ static bool adc_sample_process()
212213

213214
ret_code_t nrf_drv_adc_buffer_convert(nrf_adc_value_t * buffer, uint16_t size)
214215
{
215-
ASSERT(mp_state != NRF_DRV_STATE_UNINITIALIZED);
216+
ASSERT(m_cb.state != NRF_DRV_STATE_UNINITIALIZED);
216217
if(m_cb.state == NRF_DRV_STATE_POWERED_ON)
217218
{
218219
return NRF_ERROR_BUSY;
@@ -250,7 +251,7 @@ ret_code_t nrf_drv_adc_buffer_convert(nrf_adc_value_t * buffer, uint16_t size)
250251

251252
bool nrf_drv_adc_is_busy(void)
252253
{
253-
ASSERT(mp_state != NRF_DRV_STATE_UNINITIALIZED);
254+
ASSERT(m_cb.state != NRF_DRV_STATE_UNINITIALIZED);
254255
return (m_cb.state == NRF_DRV_STATE_POWERED_ON) ? true : false;
255256
}
256257

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/config/sdk_config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
#endif
4949
// <h> Board Support
5050

51+
// Enable NRF Asserts when Mbed NDEBUG is not set
52+
#if !defined(NDEBUG) && !defined(DEBUG_NRF_USER)
53+
#define DEBUG_NRF_USER
54+
#endif
55+
5156
//==========================================================
5257
// <q> BSP_BTN_BLE_ENABLED - bsp_btn_ble - Button Control for BLE
5358

@@ -4287,6 +4292,7 @@
42874292
//==========================================================
42884293
// <e> NRF_LOG_ENABLED - Logging module for nRF5 SDK
42894294
//==========================================================
4295+
42904296
#ifndef NRF_LOG_ENABLED
42914297
#define NRF_LOG_ENABLED 0
42924298
#endif

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/config/sdk_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
#endif
4949
// <h> Board Support
5050

51+
// Enable NRF Asserts when Mbed NDEBUG is not set
52+
#if !defined(NDEBUG) && !defined(DEBUG_NRF_USER)
53+
#define DEBUG_NRF_USER
54+
#endif
55+
5156
//==========================================================
5257
// <q> BSP_BTN_BLE_ENABLED - bsp_btn_ble - Button Control for BLE
5358

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/util/nrf_assert.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
extern "C" {
5353
#endif
5454

55+
#if !defined(NDEBUG) && !defined(DEBUG_NRF_USER)
56+
#define DEBUG_NRF_USER
57+
#endif
58+
5559
#if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)
5660

5761
/** @brief Function for handling assertions.

0 commit comments

Comments
 (0)