9. Advertising Demo

9.1. Introduction

The following sections explain how the user can build, program and run a simple BLE software application called Advertising Demo ble_adv on the DEVKIT-PRO development board using the Smartbond™ DA1459x SDK.

The application is first described, then step by step instructions are given to build and run it.

9.2. Software Architecture

In order to get familiar with building and executing the ble_adv project, it is better to run it in debug mode first. This setup creates the Debug version of the binary with extra debug information.

When the application starts running the first thing that is executed is the Reset_Handler, which is located in startup > DA14592 > GCC > exception_handler.S. This is followed by setting IRQ priorities and initializing variables.

Next, code execution continues with the main subroutine in file main.c. Here, the main routine creates the task SysInit and starts the RTOS scheduler. From now on the RTOS scheduler is running and it will start the first task which is SysInit.

The SysInit first initializes the clock and the low power clock and sets the clock dividers for the AHB and APB buses. Then BLE_Adv is initialized which leads to function initialization of the BLE manager.

Last thing done before SysInit task exits is to create another task ble_adv_demo_task which is the main application task running until the program gets stopped. The function code implementing this main task is as follows:

Code 2 The main task in SysInit(): the ble_adv_demo_task()
static OS_TASK_FUNCTION(ble_adv_demo_task, pvParameters)
{
      int8_t wdog_id;

      /* Just remove compiler warnings about the unused parameter */
      ( void ) pvParameters;

      /* Register ble_adv_demo_task to be monitored by watchdog */
      wdog_id = sys_watchdog_register(false);

      /* Start BLE device as a peripheral */
      ble_peripheral_start();
#if CONFIG_USE_BLE_SERVICES
#if dg_configSUOTA_SUPPORT
      ble_gap_mtu_size_set(defaultBLE_MAX_MTU_SIZE);

      suota_init(NULL);
#endif

      dis_init(NULL, &dis_info);
#endif

      /* Set device name */
      ble_gap_device_name_set("Dialog ADV Demo", ATT_PERM_READ);

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

      /* Start advertising */
      ble_gap_adv_start(GAP_CONN_MODE_UNDIRECTED);

      for (;;) {
               ble_evt_hdr_t *hdr;

               /* Notify watchdog on each loop */
               sys_watchdog_notify(wdog_id);

               /* Suspend watchdog while blocking on ble_get_event() */
               sys_watchdog_suspend(wdog_id);

               /*
               * Wait for a BLE event - this task will block
               * indefinitely until something is received.
               */
               hdr = ble_get_event(true);

               /* Resume watchdog */
               sys_watchdog_notify_and_resume(wdog_id);

               if (!hdr) {
                        continue;
               }

#if CONFIG_USE_BLE_SERVICES
               if (!ble_service_handle_event(hdr)) {
#endif
                        switch (hdr->evt_code) {
                        case BLE_EVT_GAP_CONNECTED:
                              handle_evt_gap_connected((ble_evt_gap_connected_t *) hdr);
                              break;
                        case BLE_EVT_GAP_DISCONNECTED:
                              handle_evt_gap_disconnected((ble_evt_gap_disconnected_t *) hdr);
                              break;
                        case BLE_EVT_GAP_PAIR_REQ:
                              handle_evt_gap_pair_req((ble_evt_gap_pair_req_t *) hdr);
                              break;
                        default:
                              ble_handle_event_default(hdr);
                              break;
                        }
#if CONFIG_USE_BLE_SERVICES
               }
#endif

               /* Free event buffer (it's not needed anymore) */
               OS_FREE(hdr);
      }
}

9.3. Software Build

This section describes all the steps required to import, build and run this first project.

9.3.1. Import a project

  1. On the e²studio Welcome page, click File (1.1) and then Import (1.2). (It’s possible that the Welcome page is not shown but instead the IDE (C/C++) is shown. Also click on File on the top bar).

'Import 1'

Figure 31 Initial Welcome Screen

  1. In the pop-up window double click General (2.1) and double click on Dialog SDK Project (2.2)

'Import 2'

Figure 32 Import SDK project

  1. In the pop-up window, click Browse and select your workspace directory.

'Import 3'

Figure 33 Select SDK Folder

  1. The final step is to select the preferred project(s) to import.

  2. Select the desired projects (ble_adv and python_scripts) by clicking on the respective tick boxes. Click Next.

'Import 4'

Figure 34 Project Selection

  1. Most certainly a pop-up window will appear to select a target device.

    1. Click on the 3 dots … (6.1) and

    2. Select DA14592 as target device (6.2).

    3. Click OK and Finish in the respective windows.

'Import 5'

Figure 35 Target Selection

Now you are ready to start working with the project.

9.3.2. Build the project to run from embedded eFLASH

To build, flash and run the ble_adv project the same steps are required as the freeRTOS_retarget project: Section 8.3.2

9.4. Running the project in the Debugger

  1. Now that the binary has been loaded to memory (eFLASH) it is possible to (re-)run the debugger.

  2. Start execution of the ble_adv project by selecting the bug icon and start the debugging session by clicking on ble-adv DA14592-00-Debug_eFlash.

../_images/debug_ble_adv.png

Figure 36 ble_adv: Debugging

The loader will compare the binary file in the eFLASH with the last compiled version en re-flash if they are different. Then the debugger will start executing and Pause at main. Resume the debugging by hitting F8.

  1. The correct functionality of the ble_adv project can be checked by using the SmartBond BLE scanner, which can be installed from the Google Play website or the Apple store. In the SmartBond app. one should be able to verify that the device is advertising.

../_images/QR_codes.png

Figure 37 SmartBond App

../_images/Smartbond_1.jpg

Figure 38 ble_adv: Interacting with BLE Application

9.5. What’s Next ?

This tutorial does not cover all the topics relevant to the software development environment. It describes the first steps necessary to get started with the DEVKIT-PRO. For further reading the following links provide more information on DA1459x: