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

BLE Peripheral NUS connected to multiple Central devices on nrf52840 S140 and SDK V16.0.0

Hello,

Is it possible to configure the board as a peripheral device that provides the Nordic UART Service and allows multiple central devices to connect and exchange data.

Sort of like the "usbd_ble_uart_freertos" example but allows more than one Central device to connect at the same time.

Thanks

Omid

Parents
  • Thanks very much

    I checked that out and it sure works as expected.  For our project we have modified the "usbd_ble_uart_freertos" and when I attempted to change the NRF_SDH_BLE_PERIPHERAL_LINK_COUNT  to allow for multi connections the build is successful but I get the following error @ runtime

    <error> app: ERROR 4 [NRF_ERROR_NO_MEM] at /home/nikola/gitlabRepo/nikola-nordic-ble/nikola_nRF5_SDK_16.0.0/nikola-ws/nikola/nikola-ble/main.c:583
    PC at: 0x0003965B
    <error> app: End of error report

    It occurs at this instruction

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&ram_start);
    APP_ERROR_CHECK(err_code);

    Thanks for your help

Reply
  • Thanks very much

    I checked that out and it sure works as expected.  For our project we have modified the "usbd_ble_uart_freertos" and when I attempted to change the NRF_SDH_BLE_PERIPHERAL_LINK_COUNT  to allow for multi connections the build is successful but I get the following error @ runtime

    <error> app: ERROR 4 [NRF_ERROR_NO_MEM] at /home/nikola/gitlabRepo/nikola-nordic-ble/nikola_nRF5_SDK_16.0.0/nikola-ws/nikola/nikola-ble/main.c:583
    PC at: 0x0003965B
    <error> app: End of error report

    It occurs at this instruction

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&ram_start);
    APP_ERROR_CHECK(err_code);

    Thanks for your help

Children
  • If you have enabled logging, the log probably says something about some recommended RAM settings right before it returns this error. You should change the RAM settings accordingly. Let me know what IDE you are using, if you are not sure how to do this in your project. The lines you should look for should look something like this:

    RAM start location can be adjusted to 0x...
    
    RAM size for application can be adjusted to 0x...

    The simple reason for this is that if you want to support more connections, the softdevice requires more RAM in order to hold the information for the multiple devices' services and characteristics.

    Best regards,

    Edvin

  • Hi Edvin,

    I am using the Segger Embedded Studio and  I have the debug logging to the Debug Terminal.  Is that what you mean?

    The only thing I see on the Terminal is the error I included on the previous message.  Which is :

    <error> app: ERROR 4 [NRF_ERROR_NO_MEM] at /home/nikola/gitlabRepo/nikola-nordic-ble/nikola_nRF5_SDK_16.0.0/nikola-ws/nikola/nikola-ble/main.c:583
    PC at: 0x0003965B
    <error> app: End of error report

    Your help is much appreciated.

  • Ok. Can you please try to step through nrf_sdh_ble_enable() and see what happens there? Are you sure you don't get any other logging?

    ret_code_t nrf_sdh_ble_enable(uint32_t * const p_app_ram_start)
    {
        // Start of RAM, obtained from linker symbol.
        uint32_t const app_ram_start_link = *p_app_ram_start;
    
        ret_code_t ret_code = sd_ble_enable(p_app_ram_start);
        if (*p_app_ram_start > app_ram_start_link)
        {
            NRF_LOG_WARNING("Insufficient RAM allocated for the SoftDevice.");
    
            NRF_LOG_WARNING("Change the RAM start location from 0x%x to 0x%x.",
                            app_ram_start_link, *p_app_ram_start);
            NRF_LOG_WARNING("Maximum RAM size for application is 0x%x.",
                            ram_end_address_get() - (*p_app_ram_start));
        }
        else
        {
            NRF_LOG_DEBUG("RAM starts at 0x%x", app_ram_start_link);
            if (*p_app_ram_start != app_ram_start_link)
            {
                NRF_LOG_DEBUG("RAM start location can be adjusted to 0x%x.", *p_app_ram_start);
    
                NRF_LOG_DEBUG("RAM size for application can be adjusted to 0x%x.",
                              ram_end_address_get() - (*p_app_ram_start));
            }
        }
    
        if (ret_code == NRF_SUCCESS)
        {
            m_stack_is_enabled = true;
        }
        else
        {
            NRF_LOG_ERROR("sd_ble_enable() returned %s.", nrf_strerror_get(ret_code));
        }
    
        return ret_code;
    }

    What is your NRF_LOG_DEFAULT_LEVEL defined to in sdk_config.h?

    If you step through this part of the code (you may need to turn off optimization for that to happen properly), does it enter any of the if-else checks?

    BR,

    Edvin

  • Hi Edvin,

    So I guess the reason I couldn't see the debug output is because I am using the "usbd_ble_uart_freertos" example and the logger task does not get the chance to output before the fault handler stops the execution.

    Any way I was able to find the ram_start location and the ram max size and changed them in the Linker "Section Placement Macros" and now I am able to build and run the app.  I also placed the code to restart advertising after a connection provided the num_peripherals is less than the MAX

    if (periph_link_cnt < NRF_SDH_BLE_PERIPHERAL_LINK_COUNT)
    {
    // Continue advertising. More connections can be established because the maximum link count has not been reached.
    advertising_start(NULL);
    }

    It appears I still have some issues because the moment I connect the board crashes in the softdevice_task when it tries to start advertising again.  I am probably missing an important piece of the puzzle.

    Would you be able to modify the "usbd_ble_uart_freertos"  SDK 16.0.0 , pca10056 example to handle multiple connections.  Our application requires the rtos version because we need to spawn other tasks for other functionality.

    I would much appreciate your help.

  • I am not that experienced with FreeRTOS. Why don't you explain kind of issues you encounter when you establish the connection? Is it the error handler that kicks in? Is it a hardfault? (NB Hardfault != Error handler). 

    It is probably a bit too late, but do you really need FreeRTOS? In my experience many users think they need it, but it creates more issues than it solves. Usually, you can use interrupts and timers to do pretty much everything that you need.

Related