Filter results by

Using gcc or IAR with ARTIK 020

The latest Simplicity Bluetooth stacks offer the option of using the GNU compiler (gcc) in addition to the IAR compiler. The advantage is price – gcc is free – but the downside is that the output image size is typically ~20% larger than that of IAR.

Here we demonstrate using the gcc compiler for a small project without size issues. You can use this procedure with the IAR compiler as well for large projects – you just need to choose between compilers when you create the project.

Physical Web

Google has an interesting initiative called the Physical Web. It is an approach to quickly enable local, web-based interaction with physical objects. For example, a parking meter might broadcast a URL to direct the driver to a Web site to pay the parking fee.

The Physical Web lets Bluetooth® Low Energy (BLE) devices broadcast beacons, typically a short Web address, so that people within range of the device can pick up the beacons with their phones. BLE beacons broadcast using the Eddystone protocol, specifically Eddystone-URL for URL broadcasting.

In this article, we demonstrate how to use Simplicity Studio to set up a Physical Web beacon, running from the ARTIK 020.

Prerequisites

This tutorial makes use of the Bluetooth software stack that is part of the Simplicity Studio® 4.0 development installation. The Simplicity tool generates custom source code according to the features you select.

You need to start out with at least one cross-compile toolchain installed prior to loading Simplicity Studio. You can also install both and switch between them.

Once you have a toolchain installed, download and install the Simplicity Studio environment. Follow the Silicon Labs instructions.

You'll additionally need some hardware:

  • ARTIK 030 development kit
  • Android phone

and some software:

  • Latest BLE stack from SiLabs, to build
    – “Soc-Empty” example project (we'll provide the main code) – bootloader-storage-internal-ble bootloader image
  • Android app "Beacon Scanner"

The time for completing this tutorial is under an hour, including the download and installation time for necessary software.

Creating Project

Start out with your ARTIK 020 board connected by USB. The project will not be created correctly if you don't.

For a video of the EddyStone beacon project using ARTIK 020, click here.

Step 1. Create a base project

Here we will start from an empty project and paste in a pre-written main function.

  1. Click File » New » Project and select Appbuilder Project.

  2. Select "Bluetooth SDK" as the application type.

  3. Select SoC – Empty for the application stack. Simplicity applications can run either stand-alone (SoC) or as the controller (Host) to a network co-processor (NCP).

  4. Rename it or accept the default name.

  5. Verify that the correct SoC part was found, select only the compiler you intend to use, and click Finish.

    The board is ARTIK-020 Bluetooth Module Radio Board (BRD4300C).
    Make sure you select this board if it does not appear by default.

Step 2. Generate the source files

Simplicity Studio has multiple perspectives – Launcher, Simplicity IDE, Configurator, etc. – and it is initially challenging to determine where you need to be. The large red arrow below points to the button that lets you choose.

  1. Go to the Simplicity IDE perspective. You should see a page similar to that below. If you don't see the .isc tab, double-click the .isc file (small red arrow on the left).

  2. Once you can see it, click the Generate button. Simplicity creates the source files for the project and part you have selected.

The file set you have generated is not yet a working solution; it still needs main.c code.

Step 3. Copy the Main program

  1. From the Project Explorer on the left, double-click the main.c file to open it.

  2. Delete its contents.

  3. Copy and paste in the file provided here.

main.c code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/***********************************************************************************************//**
 * \file   main.c
 * \brief  Silicon Labs Empty Example Project
 *
 * This example demonstrates the bare minimum needed for a Blue Gecko C application
 * that allows Over-the-Air Device Firmware Upgrading (OTA DFU). The application
 * starts advertising after boot and restarts advertising after a connection is closed.
 ***************************************************************************************************
 * <b> (C) Copyright 2016 Silicon Labs, http://www.silabs.com</b>
 ***************************************************************************************************
 * This file is licensed under the Silabs License Agreement. See the file
 * "Silabs_License_Agreement.txt" for details. Before using this software for
 * any purpose, you must agree to the terms of that agreement.
 **************************************************************************************************/
/* Board headers */
#include "init_mcu.h"
#include "init_board.h"
#include "init_app.h"
#include "ble-configuration.h"
#include "board_features.h"

/* Bluetooth stack headers */
#include "bg_types.h"
#include "native_gecko.h"
#include "gatt_db.h"

/* Libraries containing default Gecko configuration values */
#include "em_emu.h"
#include "em_cmu.h"

/* Device initialization header */
#include "hal-config.h"

#if defined(HAL_CONFIG)
#include "bsphalconfig.h"
#else
#include "bspconfig.h"
#endif


/***********************************************************************************************//**
 * @addtogroup Application
 * @{
 **************************************************************************************************/

/***********************************************************************************************//**
 * @addtogroup app
 * @{
 **************************************************************************************************/

#ifndef MAX_CONNECTIONS
#define MAX_CONNECTIONS 4
#endif
uint8_t bluetooth_stack_heap[DEFAULT_BLUETOOTH_HEAP(MAX_CONNECTIONS)];


// Gecko configuration parameters (see gecko_configuration.h)
static const gecko_configuration_t config = {
  .config_flags = 0,
  .sleep.flags = SLEEP_FLAGS_DEEP_SLEEP_ENABLE,
  .bluetooth.max_connections = MAX_CONNECTIONS,
  .bluetooth.heap = bluetooth_stack_heap,
  .bluetooth.heap_size = sizeof(bluetooth_stack_heap),
  .bluetooth.sleep_clock_accuracy = 100, // ppm
  .gattdb = &bg_gattdb_data,
  .ota.flags = 0,
  .ota.device_name_len = 3,
  .ota.device_name_ptr = "OTA",
#if (HAL_PA_ENABLE) && defined(FEATURE_PA_HIGH_POWER)
  .pa.config_enable = 1, // Enable high power PA
  .pa.input = GECKO_RADIO_PA_INPUT_VBAT, // Configure PA input to VBAT
#endif // (HAL_PA_ENABLE) && defined(FEATURE_PA_HIGH_POWER)
};

#define NO_SCAN_RESPONSE             0
#define EDDYSTONE_DATA_LEN           (0x16)
static uint8_t eddystone_data[EDDYSTONE_DATA_LEN] = {

0x03, 0x03, 0xaa, 0xfe, 0x0e, 0x16, 0xaa, 0xfe, 0x10, 0x00, 0x01,

// 'a'   'r'   't'   'i'   'k'   '.'   'i'   'o'
  0x61, 0x72, 0x74, 0x69, 0x6b, 0x2e, 0x69, 0x6f 

};


/**
 * @brief  Main function
 */
void main(void)
{
	// Initialize device
	  initMcu();
	  // Initialize board
	  initBoard();
	  // Initialize application
	  initApp();

  /* Initialize stack */
  gecko_init(&config);

  while (1) {
    /* Event pointer for handling events */
    struct gecko_cmd_packet* evt;

    /* Check for stack event. */
    evt = gecko_wait_event();

    /* Handle events */
    switch (BGLIB_MSG_ID(evt->header)) {

      /* This boot event is generated when the system boots up after reset.
       * Here the system is set to start advertising immediately after boot procedure. */
      case gecko_evt_system_boot_id:

        /* Set advertising parameters. 100ms advertisement interval. All channels used.
         * The first two parameters are minimum and maximum advertising interval, both in
         * units of (milliseconds * 1.6). The third parameter '7' sets advertising on all channels. */
        gecko_cmd_le_gap_set_adv_parameters(160,160,7);

        /*
         * the Eddystone beacon uses a custom advertising packet, so point to the array containing the custom data
         *
         *
         */
        gecko_cmd_le_gap_set_adv_data(NO_SCAN_RESPONSE,
        		EDDYSTONE_DATA_LEN,
				eddystone_data);

        /*
         * set transmit power to 0 dBm
         *
         * */
        gecko_cmd_system_set_tx_power(0);

        /* Start general advertising and enable connections. */
        gecko_cmd_le_gap_set_mode(le_gap_user_data, le_gap_non_connectable);
        break;

      case gecko_evt_le_connection_closed_id:
        /* Restart advertising after client has disconnected */
        gecko_cmd_le_gap_set_mode(le_gap_user_data, le_gap_non_connectable);
        break;


      /* Events related to OTA upgrading
      ----------------------------------------------------------------------------- */

      /* Check if the user-type OTA Control Characteristic was written.
       * If ota_control was written, boot the device into Device Firmware Upgrade (DFU) mode. */
      case gecko_evt_gatt_server_user_write_request_id:
        if(evt->data.evt_gatt_server_user_write_request.characteristic==gattdb_ota_control)
        {
          gecko_cmd_system_reset(1);
        }
        break;

      default:
        break;
    }
  }
}


/** @} (end addtogroup app) */
/** @} (end addtogroup Application) */

Step 4. Modify the URL to your own

The Eddystone URL frame specification describes the format of the frame. You'll see that the https://www. prefix and the suffix are already accounted for within the scheme.

Our example here works to generate a beacon of https://www.artik.io. You'll likely want to use an Eddystone string calculator to come up with the right string for your own URL, just like we did.

  1. Within main.c, search for the definition of EDDYSTONE_DATA_LEN – below it you'll see the frame format for https://www.artik.io.

  2. Use the Eddystone calculator to generate your replacement.

  3. Copy the part shown in brackets […] and paste it in your main.c code, replacing the sample.

  4. Note that the data is all in hex. Format your data, preceding each letter value with 0x and putting a comma after each but the last.

  5. Change the EDDYSTONE_DATA_LEN value to correspond with the length of your string.

Limitations. There is a maximum length for the URL; the calculator will tell you if you have exceeded it. The Google Physical Web works only with https sites, not http sites.

Step 5. Compile source files to binary image

As long as you have selected any file within the project, you'll see the Build icon. Click it to begin compilation.

Step 6. Create a bootloader

You will need to follow the same procedure to generate and build a bootloader. This is a one-time requirement; you will not need to repeat it once built. Follow the Creating Bootloader section and then return here.

Uploading Images

You will initially upload two different images to your ARTIK 020 development board.

  • Bootloader image (specific to Bluetooth)

  • Project image (specific to your project and changes each time)

All binary files we'll use here end in .s37 as the format type.

After you have uploaded the bootloader once, you won't need to do it again unless you change protocols (say, from BLE to Bluetooth Mesh). So once you succeed in uploading to and running binaries on your board, you can skip reloading the bootloader image on future application uploads.

General Procedure

  • Go to the Simplicity IDE view.

  • Connect the board to your PC using the USB cable. Make sure the board switch is set to AEM.

  • Check that connected devices appear on the left of the screen with identifier numbers. If you have more than one board connected, use these numbers to distinguish between boards/applications.

  • Find the binary file locations for both bootloader and main image files.

  • Right-click on the selected adapter, choose Upload applications…, and enter the binary file locations to start the upload.

Find the binary file location

  1. Under your open project, expand the Binaries category.
  2. Right-click on the file ending in ".s37", which is the format used for flash loading.
  3. Select Properties.

  4. Highlight and copy the Location including the full path, then [Esc] or hit Cancel.

Upload binary image using IDE

You can use this method or the next one according to your preference.

  1. Right-click on your adapter and select Upload application….

    Selection grayed out? Once you launch the console, Simplicity automatically connects to a debugger. To upload an image later, hit Disconnect to again make the Upload application… selection clickable.

  2. Under Application Image Path, do not paste your path here – instead, click the Browse button to the far right.

  3. Paste your copied binary path in the File name: box and click Open.

  4. For the initial loading of a new device, also load a bootloader.

    1. Click the "Bootloader" checkbox.
    2. For a bootloader, enter the location of either the file you created or a pre-compiled image (from the introductory article).

    3. Click Erase chip so that the chip will be cleared before upload.
    4. Click OK.
  5. Click Okay to flash-upload the binary file.

Upload binary image using Simplicity Commander

If you prefer a separate tool, try out Simplicity Commander.

From the Launcher perspective, click the Compatible Tools header and then click to highlight your adapter from the list at the left. One of the tools you'll see is Simplicity Commander.

Operation of this tool for flash-loading binaries is intuitive, so we'll just bring it to your attention here. The advantage is that you can leave it open, as it is a separate application from the integrated development environment.

Using Beacon Scanner

You may want to install a program to test your beacon.



1. Install an app like Beacon Scanner.


2. Run the app and verify your beacon.

Creating Bootloader

The procedure for creating a bootloader image is very similar to creating any other application.

Bluetooth stacks ver. 2.7 and later require a bootloader. Earlier stacks included the bootloader in the application.

  1. Click File » New » Project and select Appbuilder Project.

  2. Select "Gecko Bootloader" as the application type.

  3. Select the bootloader that has "gecko_sdk_suite" in the path.

  4. Select the application named "Bluetooth in-place OTA DFU bootloader".

  5. Accept the default name or rename.

  6. Choose the compiler and click Finish.

  7. Generate the files and build the image as usual.

The output will be the bootloader-storage-internal-ble.s37 file, which you'll specify the first time you load an application to your ARTIK 030 module. You can skip it after that.

Last updated on: