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

Cant port pca10056 application to pca10059

Hello everyone, 

Im developing a simple BLE scanner and its purpose is to receive and send beacons data by serial port.

My application worked quite well when flashing to the nRF52840-DK. But i cant figure out how to port it to nRF52840-Dongle.

I read the guide: https://devzone.nordicsemi.com/nordic/short-range-guides/b/getting-started/posts/nrf52840-dongle-programming-tutorial but it still doesnt work.

My first doubt was:

I must change the preprocessor definition from BOARD_PCA10056 to BOARD_PCA10059. But i se that we have different options panel for the Solution, the Project and even the Module. What exactly should be changed? I changed'em all... But sometimes

2. When i set BOARD_PCA10059 in the preprocessor definitions, i have to set the other parameters or they continue as default? The ones that appear as "inherit". 

3.  In the linker placement macros, can i have offset beetween the Softdevice and the application? Because when i set the start of application right after the end of the softdevice, the app layer appears black in the nRF Connect Programmer. With some offset it appears green. Attached picture of nRF Connect.

Despite these issues, i can flash it to the pca10059, but it just dont work. It works perfectly in the pca10056. Can you please provide me some tips to make it work?

My code:

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "nordic_common.h"
#include "nrf_sdm.h"
#include "ble.h"
#include "ble_hci.h"
#include "ble_db_discovery.h"
#include "ble_srv_common.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_soc.h"
#include "nrf_pwr_mgmt.h"
#include "app_util.h"
#include "app_error.h"
#include "ble_dis_c.h"
#include "ble_rscs_c.h"
#include "app_util.h"
#include "app_timer.h"
#include "bsp_btn_ble.h"
#include "peer_manager.h"
#include "peer_manager_handler.h"
#include "fds.h"
#include "nrf_fstorage.h"
#include "ble_conn_state.h"
#include "nrf_ble_gatt.h"
#include "nrf_pwr_mgmt.h"
#include "nrf_ble_scan.h"
//
////ANDRE
//#include <stdbool.h>
//#include "nrf_delay.h"
//#include "boards.h"
////

#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"


#define APP_BLE_CONN_CFG_TAG        1                                   /**< Tag that identifies the BLE configuration of the SoftDevice. */
#define APP_BLE_OBSERVER_PRIO       3                                   /**< BLE observer priority of the application. There is no need to modify this value. */
#define APP_SOC_OBSERVER_PRIO       1                                   /**< SoC observer priority of the application. There is no need to modify this value. */

#define SCAN_INTERVAL               0x0320                              /**< Determines scan interval in units of 0.625 millisecond. */
#define SCAN_WINDOW                 0x0320                              /**< Determines scan window in units of 0.625 millisecond. */
#define SCAN_DURATION           	0x0000                              /**< Duration of the scanning in units of 10 milliseconds. If set to 0x0000, scanning continues until it is explicitly disabled. */

NRF_BLE_SCAN_DEF(m_scan);                                   /**< Scanning Module instance. */

static bool                  m_memory_access_in_progress;   /**< Flag to keep track of ongoing operations on persistent memory. */

static ble_gap_scan_params_t m_scan_param =                 /**< Scan parameters requested for scanning and connection. */
{
    .active        = 0x00,
    .interval      = SCAN_INTERVAL,
    .window        = SCAN_WINDOW,
    .filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
    .timeout       = SCAN_DURATION,
//    .scan_phys     = BLE_GAP_PHY_CODED,                                 // Choose only one of the following scan_phys
    .scan_phys     = BLE_GAP_PHY_1MBPS,
//    .scan_phys     = BLE_GAP_PHY_2MBPS,
    .extended      = 1,
};

static void scan_start(void);


/**@brief Function for handling BLE events.
 *
 * @param[in]   p_ble_evt   Bluetooth stack event.
 * @param[in]   p_context   Unused.
 */




static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{

//    uint8_t  idx = 0;
//    unsigned char mac[6];
    int8_t rssi;
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_ADV_REPORT:

        {

       
//        for ( idx=0; idx < 6; idx++ ) {
//          mac[idx] = p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[idx];
//        }
        
         //NRF_LOG_RAW_INFO ("----------------------------------\r\n");
        NRF_LOG_RAW_INFO("Device: %02x:%02x:%02x:%02x:%02x:%02x  ", p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[0],
                                                                     p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[1],
                                                                     p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[2],
                                                                     p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[3],
                                                                      p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[4],                                                                      
                                                                      p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[5]);

             rssi = p_ble_evt->evt.gap_evt.params.adv_report.rssi;
             NRF_LOG_RAW_INFO("RSSI:%d \r\n", rssi);
            

            
           // NRF_LOG_RAW_HEXDUMP_INFO (m_scan.scan_buffer.p_data, m_scan.scan_buffer.len);
           
            //NRF_LOG_RAW_INFO ("----------------------------------\r\n");
        }

        default:
            break;
    }
}


/**
 * @brief SoftDevice SoC event handler.
 *
 * @param[in] evt_id    SoC event.
 * @param[in] p_context Context.
 */
static void soc_evt_handler(uint32_t evt_id, void * p_context)
{
    switch (evt_id)
    {
        case NRF_EVT_FLASH_OPERATION_SUCCESS:
        /* fall through */
        case NRF_EVT_FLASH_OPERATION_ERROR:

            if (m_memory_access_in_progress)
            {
                m_memory_access_in_progress = false;
                scan_start();
            }
            break;

        default:
            // No implementation needed.
            break;
    }
}


/**@brief Function for initializing the BLE stack.
 *
 * @details Initializes the SoftDevice and the BLE event interrupt.
  */
static void ble_stack_init(void)
{
    ret_code_t err_code;

    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
    APP_ERROR_CHECK(err_code);

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

    // Register handlers for BLE and SoC events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
    NRF_SDH_SOC_OBSERVER(m_soc_observer, APP_SOC_OBSERVER_PRIO, soc_evt_handler, NULL);
}


/**@brief Function for handling Scanning Module events.
 */
static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{
    switch(p_scan_evt->scan_evt_id)
    {
        case NRF_BLE_SCAN_EVT_SCAN_TIMEOUT:
        {
            NRF_LOG_INFO("Scan timed out.");
            scan_start();
        } break;

        default:
          break;
    }
}


/**@brief Function for initializing the scanning and setting the filters.
 */
static void scan_init(void)
{
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;

    memset(&init_scan, 0, sizeof(init_scan));

    init_scan.connect_if_match = false;
    init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;
    init_scan.p_scan_param     = &m_scan_param;

    err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
    APP_ERROR_CHECK(err_code);
}


/**@brief Function for starting scanning.
 */
static void scan_start(void)
{
    ret_code_t err_code;

    // If there is any pending write to flash, defer scanning until it completes.
    if (nrf_fstorage_is_busy(NULL))
    {
        m_memory_access_in_progress = true;
        return;
    }

    err_code = nrf_ble_scan_start(&m_scan);
    APP_ERROR_CHECK(err_code);
}


/**@brief Function for initializing logging. */
static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}


/**@brief Function for initializing the timer. */
static void timer_init(void)
{
    ret_code_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);
}


/**@brief Function for initializing power management.
 */
static void power_management_init(void)
{
    ret_code_t err_code;
    err_code = nrf_pwr_mgmt_init();
    APP_ERROR_CHECK(err_code);
}


/**@brief Function for handling the idle state (main loop).
 *
 * @details Handles any pending log operations, then sleeps until the next event occurs.
 */
static void idle_state_handle(void)
{
    if (NRF_LOG_PROCESS() == false)
    {
        nrf_pwr_mgmt_run();
    }
}



int main(void)
{

    // Initialize.
    log_init();
    timer_init();
    power_management_init();
     
      
  
    ble_stack_init();
    scan_init();
  

    // Start execution.
    NRF_LOG_RAW_INFO(    " ----------------\r\n");
    NRF_LOG_RAW_INFO(	 "| Scanning for BLE devices... |");
    NRF_LOG_RAW_INFO("\r\n ----------------\r\n");
    
    scan_start();


    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}

Preprocessor settings:

Linker Settings:

nRF Connect with the files to be written:

  • Hi Andre

    It seems you've forgotten to select the Common configuration in the upper left corner of the Options window when editing the SEGGER Embedded Studios configurations. Please try that and update me if you're still having trouble.

    Best regards,

    Simon

  • Hi Thank you for your reply.

    I edited the Common options, but i cant select it as an option to Build the project. 

  • Hi Andre

    Sorry I didn't catch this when I first looked at this case. Your setup and flashing process is correct, but there is no UART bridge on the nRF52840 Dongle, which is why it isn't working for you. There are no default UART pins in the Dongle, so you'll have to set these yourself when using the Dongle. They can be set to any GPIO, but we recommend not using the pins marked "low frequency I/O only" in the ball assignment documentation. Also, make sure that you don't choose pins that are used for other peripherals and components on the Dongle.

    If you're communicating with a PC, you can also set up the Dongle with the USB CDC ACM example to send data through a virtual USB COM port, and implement the scanner central from there.

    Best regards,

    Simon

  • Hi Simonr,

    I am struggling trying to build and example program made for the pca10056. I have the same problem trying to convert this example for the nRF52840 Dongle.

    I first tried to use the usbd_ble_uart (looking at your last reply, it may not be possible to use it with the pca10059)

    Let me recap what needs to be done, and please correct what is wrong and where I can find information to get it right.

    Using nRF Connect 3.7.0

    1. Open the usbd_cdc_acm_pca10056
    2. Right-clic Project Using Option dialog select Common configuration
    3. Select Preprocessor -> Preprocesor Definitions
      1. Change BOARD_PCA10056 to BOARD_PCA10059
    4. Select Linker -> Section Placement Macros
      1. Here, I don't know what I should do. Where can I get START and SIZE. Also, the section Andre has in his screenshot are not identical to what I have:
        1.  This was not modified form pca10056
    5. Build
    6. Open nRF Connect - Programmer
    7. Select the .hex file generated in Output folder

    Now, while building this example I get this: 

    //---- Another issue

    I did some additional tests with another SDK example: gpiote_pca10056. it build correctly (I changed Preprocessor def to BOARD_PCA10059) However, when come time to program. it complain that it does not contain the FWID for the current SoftDevice. So I flashed the SoftDevice And yet it is not happy.

    Is there a place where I configure the SoftDevice to be used?

    Also, is there a way to include the new SoftDevice in the Need user input list:

    Thanks in advance,

    Mathnitrof

Related