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

How to add Bluetooth in an empty project?

I am using a nRF52840 with "SEGGER Embedded Studio for ARM 5.10a" and "nRF5_SDK_17.0.0_9d13099" sdk.

  • I have successfully added Bluetooth in my project .

    Here is the step by step guide if any one needs it.

    Create a folder named nRF_SoftDevices and add these files

    1. nrf_sdh.c
    2. nrf_sdh_ble.c
    3. nrf_sdh_soc.c

    Create a folder named nRF_BLE and add these files

    1. ble_advdata.c
    2. ble_advertising.c
    3. ble_conn_params.c
    4. ble_conn_state.c
    5. ble_link_ctx_manager.c
    6. ble_srv_common.c
    7. nrf_ble_gatt.c
    8. nrf_ble_qwr.c

    Add following files to nrf_Libraries

    1. nrf_pwr_mgmt.c
    2. nrf_section_iter.c
    3. nrf_atfifo.c
    4. nrf_atflags.c
    5. nrf_sortlist.c
    6. app_timer2.c
    7. drv_rtc.c

    In the end

    Create a folder named nRF_BLE_Services and add the file related to services you need. I need “nus” service so I have added files required for that

    1. ble_nus.c

     Go to Solution ‘project name’  right click, go to “options” go to “Code” go to “Preprocessor” go to “User Include Directories” and add the paths to the following folders. These are the path of the folders containing “.h” files required to clear the build errors.

    For me paths were…

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\softdevice\s140\headers

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\softdevice\s140\headers\nrf52

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\drivers_nrf\nrf_soc_nosd

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\libraries\timer

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\libraries\sortlist

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\libraries\mutex

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\libraries\atomic_fifo

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\ble\common

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\ble\ble_advertising

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\ble\nrf_ble_gatt

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\ble\nrf_ble_qwr

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\ble\ble_services\ble_nus

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\ble\ble_link_ctx_manager

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\libraries\pwr_mgmt

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\libraries\sortlist

    E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\components\softdevice\common E:\nRF5_SDK_17.0.0_9d13099\nRF5_SDK_17.0.0_9d13099\examples\peripheral\Lynkgrid_base_ble\nRF_SoftDevice

     

     

    Go to Project‘project name’, right click, go to “options” select “Common” go to “Code” go to “Preprocessor” go to “Preprocessor Definitions” and add the following defines

    BOARD_PCA10056

    BSP_DEFINES_ONLY

    CONFIG_GPIO_AS_PINRESET

    FLOAT_ABI_HARD

    INITIALIZE_USER_SECTIONS

    NRF52840_XXAA

    NO_VTOR_CONFIG

    NRF_SD_BLE_API_VERSION=7

    S140

    SOFTDEVICE_PRESENT

    APP_TIMER_V2

    APP_TIMER_V2_RTC1_ENABLED

    Go to Project‘project name’, right click, go to “options” select “Common” go to “Code” go to “Linker” go to “Section Placement Macros” and set the flash and ram values as given

    FLASH_PH_START=0x0

    FLASH_PH_SIZE=0x100000

    RAM_PH_START=0x20000000

    RAM_PH_SIZE=0x40000

    FLASH_START=0x27000

    FLASH_SIZE=0xd9000

    RAM_START=0x20002ae8

    RAM_SIZE=0x3d518

    Go to Project‘project name’, right click, go to “options” select “Common” go to “Debug” go to “Loader” go to “Additional Load File[0]” and add the path to softdevice.hex

    For me it was…

    E:/nRF5_SDK_17.0.0_9d13099/nRF5_SDK_17.0.0_9d13099/components/softdevice/s140/hex/s140_nrf52_7.0.1_softdevice.hex

    If you face an error while building the code that look like this Error : undefined reference to `__start_sdh_req_observers'

    Replace the “flash_placement.xml” file of your project with the flash_placement.xml file of the ble_app_template project.

    Merger the sdk_config.h file of your project with the sdk_config.h of  ble_app_template project. You may need to do some changes in your sdk_config.h file according to requirement. I have made changes related to the “nus” service I need in my project.

     

     

    Here are the links that were very helpful to me in solving this problem.

    Nordic Semiconductor Infocenter

    Nordic Semiconductor Infocenter

    (+) Enable the use of RTC0, RTC1 or RTC2 in app_timer2 - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)

    Error Output/spis_pca10056 Debug/Obj/nrf_sdh.o:(.rodata.sdh_req_observers+0x0): undefined reference to `__start_sdh_req_observers' - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)

    NordicPlayground/nRF5x-custom-ble-service-tutorial (github.com)

     

     

Related