Wireless Projects - IoT
Published

Bluetooth Low Energy - DA14592 - Peripheral configurations

Enhance the DA14592 BLE peripheral with security, low power, and real-time UART debug messages.

IntermediateFull instructions provided1 hour40
Bluetooth Low Energy - DA14592 - Peripheral configurations

Things used in this project

Hardware components

Renesas DA14592-016FDEVKT-P
The DA14592-016FDEVKT-P Bluetooth® Low Energy Development Kit Pro includes a motherboard, daughterboard, and cables. This kit is specifically designed for software application development and power measurements. DA14592 is a dual-core Bluetooth 5.2 SoC with 256kB of embedded Flash that operates at ultra-low power levels providing world-class RF performance. DA14592 is available in both FCQFN and WLCSP packages.
×1

Software apps and online services

Renesas e2 studio
e² studio is an Eclipse-based integrated development environment (IDE) for Renesas MCUs. In addition to Eclipse’s own powerful code editor, e² studio offers a rich range of extended functions. e² studio covers all development processes, from the downloading of sample code to debugging.
Renesas SmartSnippets Toolbox
SmartSnippets™ Toolbox which covers all software development requirements, including: Programming and loading of firmware into SRAM, OTP, and Flash Power profiling User Manual: https://lpccs-docs.renesas.com/UM-B-083/index.html

Story

Read more

Schematics

DA14592-016FDEVKT-P

SmartBond DA14592 Bluetooth Low Energy 5.2 SoC Development Kit Pro

Code

Change Advertising Intervals on ble_adv project

C/C++
Utilize the ble_gap_adv_intv_set API and use the printf API to print out Debug messages
        /* Set device name */
        ble_gap_device_name_set("DA14592_Test", ATT_PERM_READ);

        /* Set advertising data */
        ble_gap_adv_data_set(sizeof(adv_data), adv_data, 0, NULL);

        /* Set Advertising interval Min and Max */
        uint16_t intv_min =0xF0; // 0xF0 = 240, 240 * 0.625ms = 150ms
        uint16_t intv_max = 0xF0;
        ble_gap_adv_intv_set(intv_min, intv_max);

        /* Start advertising */
        ble_gap_adv_start(GAP_CONN_MODE_UNDIRECTED);
        printf("Device Advertising with name: DA14592_Test \r\n");

Change Device Name

C/C++
Utilize the ble_gap_device_name_set API to change the device name.
Modify the advertising data in order to Advertise the device name.
        /* Set device name */
        ble_gap_device_name_set("DA14592_Test", ATT_PERM_READ);

//On top of main.c file find the adv_data variable
/*
 * BLE adv demo advertising data
 */

static const uint8_t adv_data[] = {
#if dg_configSUOTA_SUPPORT || dg_configASYM_SUOTA_SUPPORT
        0x03, GAP_DATA_TYPE_UUID16_LIST_INC, U16(dg_configBLE_UUID_SUOTA_SERVICE),
#endif
        0x0D, GAP_DATA_TYPE_LOCAL_NAME,
        'D', 'A', '1', '4', '5', '9', '2', '_', 'T', 'e', 's', 't'
};

Enable Extended Sleep mode

C/C++
Use the pm_sleep_mode_set API inside the System Initialization function
/**
 * @brief System Initialization and creation of the BLE task
 */
static OS_TASK_FUNCTION(system_init, pvParameters)
{
#if defined CONFIG_RETARGET
        extern void retarget_init(void);
#endif

        /* Use appropriate XTAL for each device */
        cm_sys_clk_init(sysclk_XTAL32M);
        cm_apb_set_clock_divider(apb_div1);
        cm_ahb_set_clock_divider(ahb_div1);
        cm_lp_clk_init();


        /* Prepare the hardware to run this demo */
        prvSetupHardware();

#if defined CONFIG_RETARGET
        retarget_init();
#endif

        /* Set the desired sleep mode */
        pm_set_wakeup_mode(true);

        pm_sleep_mode_set(pm_mode_extended_sleep);

        /* Initialize BLE Manager */
        ble_mgr_init();

        /* Start the BLE adv demo application task */
        OS_TASK_CREATE("BLE ADV Demo",                  /* The text name assigned to the task, for
                                                           debug only; not used by the kernel. */
                       ble_adv_demo_task,               /* The function that implements the task. */
                       NULL,                            /* The parameter passed to the task. */
                       1500,                             /* The number of bytes to allocate to the
                                                           stack of the task. */
                       mainBLE_ADV_DEMO_TASK_PRIORITY,  /* The priority assigned to the task. */
                       handle);                         /* The task handle. */
        OS_ASSERT(handle);

        /* the work of the SysInit task is done */
        OS_TASK_DELETE(OS_GET_CURRENT_TASK());
}

Add Debug Messages

C/C++
Make sure that CONFIG_RETARGET macro is defined in custom_config_eflash.h file.
Below code snippet can be taken as reference on how to add debug messages.
Below code snippet is the Connection callback handler which will be executed when we have established a connection
static void print_connections(void)
{
        int num = 0;

        printf("\r\n");
        printf("Active connections:\r\n");
        printf("Nr | Index | Address           | Pending unpair\r\n");
        queue_foreach(&connections, print_connection_func, &num);

        if (!num) {
                printf("(no active connections)\r\n");
        }

        printf("\r\n");
}



static void handle_evt_gap_connected(ble_evt_gap_connected_t *evt)
{
        /**
         * Manage behavior upon connection
         */
    conn_dev_t *conn_dev;

    printf("Device connected\r\n");
    printf("\tConnection index: %d\r\n", evt->conn_idx);
    printf("\tAddress: %s\r\n", ble_address_to_string(&evt->peer_address));
    printf("\r\n");

    conn_dev = OS_MALLOC(sizeof(*conn_dev));

    conn_dev->conn_idx = evt->conn_idx;
    conn_dev->unpair = false;
    memcpy(&conn_dev->addr, &evt->peer_address, sizeof(conn_dev->addr));

    queue_push_back(&connections, conn_dev);


    print_connections();
#if (dg_configSUOTA_GAP_SEC_LEVEL > 0)
        ble_gap_set_sec_level(evt->conn_idx, dg_configSUOTA_GAP_SEC_LEVEL);
#endif
}

Credits

Wireless Projects - IoT
2 projects • 0 followers
Embedded Application Engineer on Wireless Connectivity

Comments