This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52 nordic uart services

Hello,

I've got some trouble using Nordic Uart Services,

I correctly add the library to my project.

I can receive data from different devices. But when I want to send data over ble, the soft device Assert and make a hard fault interrupt.

After some investigationn the error comes from this function

ble_nus_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)

in the file ble_nus.c @line 262.

I understood that p_context is the ble_nus_t instance that sent my message over ble.

But when I reach this line after a transmission. The data_handler value is 0 and not the address of my callback.

Could you help me to solve this issue ?

I work on nrf52832 with SDK14.1.0 and SES. I started from free RTOS hrs exemple

Thank You. Geoffrey

Ps : This is my ble_nus_initialization

static void mdw_nus_data_handler(ble_nus_evt_t * p_evt);

void mdw_console_ble_init(void)
{
    mdwConsBleFlagsHandle = xEventGroupCreate();
    ASSERT(NULL != mdwConsBleFlagsHandle);
    mdwConsBleWriteMutexHandle = xSemaphoreCreateMutex();
    ASSERT(NULL != mdwConsBleWriteMutexHandle);
    mdwConsBleReadMutexHandle = xSemaphoreCreateBinary();
    ASSERT(NULL != mdwConsBleReadMutexHandle);
    xSemaphoreGive(mdwConsBleReadMutexHandle);
    xSemaphoreTake(mdwConsBleWriteMutexHandle, portMAX_DELAY);

    ble_nus_init_t nus_init;
    memset(&nus_init, 0, sizeof(nus_init));

    nus_init.data_handler = mdw_nus_data_handler;

    mdwRxEnable = false;
    mdwTxEnable = false;

    uint32_t errCode = ble_nus_init(&m_nus, &nus_init);
    APP_ERROR_CHECK(errCode);

    xSemaphoreGive(mdwConsBleWriteMutexHandle);
}
  • No I did not. In Reality I received the event. this is the work flow I have done.

    - Init Nus                      : OK
    - Wait a msg                 : OK
    - Get event RX              : OK
    - Execute Callback        : OK
    - Reply                         : OK
    - send data onver ble    : OK
    - get the Event BLE_NUS_EVT_TX_RDY : OK
    - execute line p_nus->data_handler(&evt); : NOK as data_handler is NULL 
    

    When I try to send something I have got this problem.

    On solution is to replace this line directly by a global function pointer, it is enough for my application, but it is dirty and I really want to understand why when I send something over ble it does not work.

  • Have you tried to test with the stock example ?

    It's pretty strange that data_handler is NULL. The way it works is that when you call BLE_NUS_DEF( m_nus) , m_nus will be declared as static variable and will be send to the softdevice using NRF_SDH_BLE_OBSERVER() and the softdevice will return the pointer when there is an event , in this case BLE_GATTS_EVT_WRITE event.

    If you can provide a simple example that can reproduce the issue, it would be very nice.

  • Hi Hung,

    Sorry for my late response. I did not try with the stock exemple. But I solved my problem by editing my own uart service to be more compliant with our project.

    However I'll try to send to you an example of code that cause this issue.

    Thank you very much for your help.

Related