3. Initial Project
The initial step involves downloading the latest version of SDK6, available at SDK6 latest version. For an optimal starting point in this tutorial or any other project you wish to undertake, we highly recommend commencing from within the SDK6 environment. Specifically, our projects initiate from the empty_peripheral_template located in
.\projects\target_apps\template\empty_peripheral_template
3.1. Application Callbacks
There are a number of system callbacks that we need to re-route to user space, to do this modify
the user_app_main_loop_callbacks
structure in user_callback_config.h as follows:
+ .app_on_init = user_on_init,
- .app_on_init = default_app_on_init,
We also need to add some Bluetooth stack callbacks, to do this modify the user_app_callbacks
structure in user_callback_config.h as follows:
+ .app_on_set_dev_config_complete = user_on_set_dev_config_complete,
- .app_on_set_dev_config_complete = default_app_on_set_dev_config_complete,
We then need to add function prototypes for the new callback functions to user_empty_peripheral_template.h as follows:
void user_on_init(void);
void user_on_set_dev_config_complete(void);
Finally we need to add the actual user space callback functions to user_empty_peripheral_template.c as follows:
void user_on_init(void)
{
arch_printf("\n\r%s", __FUNCTION__);
default_app_on_init();
}
void user_on_set_dev_config_complete(void)
{
arch_printf("\n\r%s", __FUNCTION__);
default_app_on_set_dev_config_complete();
}
Note
In UART section we provide the explanation for arch_printf
.
3.2. Sleep Mode
By default the project does not use sleep mode and so we need to perform the following modification to ensure the device enters sleep mode whenever possible. We can do this by modifying app_default_sleep_mode
in user_config.h as follows:
+ static const sleep_state_t app_default_sleep_mode = ARCH_EXT_SLEEP_ON;
- static const sleep_state_t app_default_sleep_mode = ARCH_SLEEP_OFF;
3.3. SPI Flash
A number of the following chapters use the SPI interface to access the flash memory found on the development kits. On both the PRO and USB kits the flash memory is connected to the following DA1453x pins:
SPI Flash MISO:
P0_3
SPI Flash MOSI:
P0_0
SPI Flash CLK:
P0_4
SPI Flash CS:
P0_1
First add definitions for these pin mappings to the file user_periph_setup.h as follows:
/****************************************************************************************/
/* SPI configuration */
/****************************************************************************************/
#define SPI_EN_PORT GPIO_PORT_0
#define SPI_EN_PIN GPIO_PIN_1
#define SPI_CLK_PORT GPIO_PORT_0
#define SPI_CLK_PIN GPIO_PIN_4
#define SPI_DO_PORT GPIO_PORT_0
#define SPI_DO_PIN GPIO_PIN_0
#define SPI_DI_PORT GPIO_PORT_0
#define SPI_DI_PIN GPIO_PIN_3
Next we need to reserve these pins so that the SDK can check for duplicate assignments. To do this add the following code to the GPIO_reservations
function that can be found in the user_periph_setup.c file:
RESERVE_GPIO(SPI_FLASH_CS, SPI_EN_PORT, SPI_EN_PIN, PID_SPI_EN);
RESERVE_GPIO(SPI_FLASH_CLK, SPI_CLK_PORT, SPI_CLK_PIN, PID_SPI_CLK);
RESERVE_GPIO(SPI_FLASH_DO, SPI_DO_PORT, SPI_DO_PIN, PID_SPI_DO);
RESERVE_GPIO(SPI_FLASH_DI, SPI_DI_PORT, SPI_DI_PIN, PID_SPI_DI);
Now configure the pins to have the relevant SPI function by adding the following to the set_pad_functions
function:
GPIO_ConfigurePin(SPI_EN_PORT, SPI_EN_PIN, OUTPUT, PID_SPI_EN, true);
GPIO_ConfigurePin(SPI_CLK_PORT, SPI_CLK_PIN, OUTPUT, PID_SPI_CLK, false);
GPIO_ConfigurePin(SPI_DO_PORT, SPI_DO_PIN, OUTPUT, PID_SPI_DO, false);
GPIO_ConfigurePin(SPI_DI_PORT, SPI_DI_PIN, INPUT, PID_SPI_DI, false);