Dear Dialog Team!
I would like to use a random address, that should be generated at first startup and never change in lifetime. I use DA14583 with SKD5. What's the best way to achieve that?
Thank you!
Best regards,
Oliver
Device:
Hi ibbokoeln,
You can use a static random address that is generated when the device boots and it can not be changed while the device is powered. To generate this kind of address you can use the GAPM_GEN_RAND_ADDR_CMD with GAP_STATIC_ADDR as address type. For more info on this please check the RW-BLE-GAP-IS document.
Thanks MT_dialog
Hi,
thanks for your hints. Your solution was not exactly what I wanted but it shows me the right way. For the records, here is my solution. Maybe someone might find it useful:
The following is valid for DA15483 with SDK5.0.3:
1. In user_config.h .address_src is set to GAPM_PROVIDED_RND_ADDR:
static const struct advertise_configuration user_undirected_advertise_conf ={
/// Advertise operation type.
.advertise_operation=ADV_UNDIRECT,
/// Own BD address source of the device:
.address_src=GAPM_PROVIDED_RND_ADDR,
/// Advertise interval
.intv = 874,
///Advertising channel map
.channel_map = 0x7,
};
2. On startup the following function flash_config_init is executed my_app_init:
typedef struct {
uint32_t header;
struct bd_addr bd_addr;
} Config;
#define CONFIG_HEADER 0xE347FD78 // some random uint32
static Config config;
void flash_config_init(void) {
SPI_Pad_t spi_FLASH_CS_Pad;
spi_FLASH_CS_Pad.pin = SPI_CS_PIN;
spi_FLASH_CS_Pad.port = SPI_GPIO_PORT;
// Enable SPI & SPI FLASH
spi_init(&spi_FLASH_CS_Pad, SPI_MODE_8BIT, SPI_ROLE_MASTER, SPI_CLK_IDLE_POL_LOW, SPI_PHA_MODE_0, SPI_MINT_DISABLE, SPI_XTAL_DIV_8);
spi_flash_init(SPI_FLASH_SIZE, SPI_FLASH_PAGE);
// Power up flash
spi_flash_release_from_power_down();
spi_flash_read_data((uint8_t*)(&config), 0x1D000, sizeof(config));
if(config.header!=CONFIG_HEADER) {
uint8_t rand[16];
trng_acquire(rand);
config.header=CONFIG_HEADER;
memcpy(&config.bd_addr, rand, 6);
spi_flash_block_erase (0 x1d000 SECTOR_ERASE);
spi_flash_write_data((uint8_t*)(&config), 0x1D000, sizeof(config));
}
// Power down flash
spi_flash_power_down();
// Release SPI controller
spi_release();
3. The following code is executed in user_app_adv_start(void):
void user_app_adv_start(void) {
struct bd_addr addr=config.bd_addr
arch_printf("Using BD_ADDR: %02X-%02X-%02X-%02X-%02X-%02X\n", addr.addr[0], addr.addr[1], addr.addr[2], addr.addr[3], addr.addr[4], addr.addr[5]);
struct gapm_start_advertise_cmd* cmd;
cmd = app_easy_gap_undirected_advertise_get_active();
cmd->op.addr=addr;
app_easy_gap_undirected_advertise_start();
}
This method leads to a One-Time-Random-Address, that will only be renewed if the flash is being erased or on the very first startup.
Regards,
Oliver
I'm afraid this is not complied by Bluetooth Specification, due to spec, static address should be renewed during power cycle,
the gapm_gen_rand_addr_cmd way should be the correct way
Hi ibbkoeln,
Thanks for sharing you solution.
Best Regards MT_dialog