Wireless Embedded
Published

How to create AT cmd for Dev Name on DA1453x BLE devices!

Learn to create a custom AT command to view and change the Device Name using the CodeLess SDK on Renesas DA1453x BLE devices.

IntermediateFull instructions provided2 hours26
How to create AT cmd for Dev Name on DA1453x BLE devices!

Things used in this project

Hardware components

Renesas [DA14531MOD-00DEVKT-P] Development Kit Pro DA1453x
DA1453x Development Kit Pro to evaluate the DA1453x BLE Series of devices from Renesas Electronics.
×1
Renesas [DA14531MOD-00F1DB-P] DA14531MOD Daughterboard
DA14531MOD Daughterboard to be used with Dev Kit Pro. User can use any DA1453x Daughterboard to test this Tutorial.
×1

Software apps and online services

Renesas SmartConsole
SmartConsole is a mobile application by Renesas. It is designed to work with CodeLess SDK and SPS SDK for the DA1453x device family.
Renesas CodeLess SDK v6.380.20.66
Latest CodeLess SDK v6.380.20.66 (June 2025) for the DA1453x Family of devices. User Manual: https://lpccs-docs.renesas.com/UM-140-DA145x-CodeLess/introduction.html
Arm Keil μVision IDE (MDK)
Keil IDE is designed for developing embedded projects on Cortex and Arm devices. It requires a valid license.
Renesas e2 Studio IDE
e2 Studio IDE is an Eclipse based IDE from Renesas Electonics. The latest CodeLess SDK, that we will work on, is also supported on e2 Studio IDE. No license is required. Tutorial on Getting Started with e2 Studio IDE for DA1453x devices: https://lpccs-docs.renesas.com/e2_studio_sdk6_getting_started/index.html

Story

Read more

Schematics

DA14531MOD + Development Kit Pro Connections

Correct Jumper configuration on the Dev Kit Pro + DA14531MOD to use CodeLess SDK

Code

user_at_commands.h file

C Header File
All the required changes on user_at_commands.h file in order to add the AT+SHOWNAME and AT+DEVNAME commands
#define USE_AT_DEVNAME //custom command to get device name
#define USE_AT_SHOWNAME	//custom command to show the device name

/**
 * \brief AT command set.
 *
 * Set of supported codeless at command set.
 */
typedef enum {
    AT=0, /**< Returns OK */
    ATI, /**< Lists SW release and HW information */
    ATE, /**< Turns echo on or off */
    ATZ, /**< Set gpio configuration to default */
    ATR, /**< Platform reset */
    ATF, /**< Turn error report on or off */
#ifdef USE_AT_CURSOR
    AT_CURSOR, /**< Places a time stamp cursor in SmartSnippets power profiler */
#endif
#ifdef USE_AT_BDADDR
    AT_BDADDR, /**< Displays the Bluetooth device address */
#endif
.....
......
.........
...........
#ifdef USE_AT_HRTBT
    AT_HRTBT,
#endif
#ifdef USE_AT_DEVNAME
		AT_DEVNAME,
#endif
#ifdef USE_AT_SHOWNAME
		AT_SHOWNAME,
#endif
#ifdef USE_AT_BAUD
    AT_BAUD,
#endif
    AT_INVALID, /**< Command to execute in case of an invalid command. */
    AT_LAST_VALUE /**< Enumeration length. */
} AT_COMMAND_ID_t;


/**
 ****************************************************************************************
 * @brief Change Device Name
 ****************************************************************************************
 */
void user_at_devname(struct at_cmd_params_t* arg, char* reply_string);

/**
 ****************************************************************************************
 * @brief Show Device Name
 ****************************************************************************************
 */
void user_at_showname(struct at_cmd_params_t* arg, char* reply_string);

void save_name_on_SPI(void);

user_at_commands.c file V1 (Variables + AT command declaration)

C/C++
Initially we will add the necessary variables that will be used to store the Device name and the Flags we are going to use. Then we will show how to add our custom AT commands on the at_command_characteristics_t struct.
char new_device_name[GAP_MAX_NAME_SIZE] __SECTION_ZERO("retention_mem_area0"); //@RETENTION MEMORY;//= "\0";
bool flag_devname  __SECTION_ZERO("retention_mem_area0"); //@RETENTION MEMORY;
bool changed_name  __SECTION_ZERO("retention_mem_area0"); //@RETENTION MEMORY;

/// at commands jumptable.
const struct at_command_characteristics_t at_commands_chars[] = {
    AT_CMD_ENTRY( AT              ,  0,  0, ""             , user_at              ),
    AT_CMD_ENTRY( ATI             ,  0,  0, "I"            , user_ati             ),
    AT_CMD_ENTRY( ATE             ,  0,  1, "E"            , user_ate             ),
    AT_CMD_ENTRY( ATZ             ,  0,  0, "Z"            , user_atz             ),
    AT_CMD_ENTRY( ATR             ,  0,  0, "R"            , user_atr             ),
    AT_CMD_ENTRY( ATF             ,  1,  1, "F"            , user_atf             ),
#ifdef USE_AT_CURSOR
    AT_CMD_ENTRY( AT_CURSOR       ,  0,  0, "CURSOR"       , user_at_cursor       ),
#endif
.....
.....
.....
#ifdef USE_AT_HRTBT
    AT_CMD_ENTRY( AT_HRTBT        ,  0,  1, "HRTBT"        , user_at_hrtbt        ),
#endif
#ifdef USE_AT_DEVNAME
		AT_CMD_ENTRY( AT_DEVNAME       ,  0,  1, "DEVNAME"         , user_at_devname         ), //custom AT command to change dev name
#endif
#ifdef USE_AT_SHOWNAME
		AT_CMD_ENTRY( AT_SHOWNAME			, 0, 		0, "SHOWNAME"				, user_at_showname			), //custom AT command to show the dev name 
#endif
#ifdef USE_AT_BAUD
    AT_CMD_ENTRY( AT_BAUD         ,  0,  1, "BAUD"         , user_at_baud         ),
#endif
    AT_CMD_ENTRY( AT_INVALID      ,  0,  1, "XXX"          , user_at_invalid      )
};

user_at_commands.c file V2 (AT+SHOWNAME implementation)

C/C++
We are going to show the implementation of the AT+SHOWNAME command.
#ifdef USE_AT_SHOWNAME
void user_at_showname(struct at_cmd_params_t* arg, char* reply_string)
{
	
					if( arg->arg_count ==0)
				{

					//Print the existing Device Name
					arch_sprintf(reply_string, "%s", device_info.dev_name.name);
					arg->success_flag = true;
				}
	
}
#endif

user_at_commands.c file V3 (AT+DEVNAME implementation)

C/C++
Implementation of the AT+DEVNAME custom AT command to change the Device name. Also the implementation of the save_name_on_SPI(void) function that will get the Device name and store it in the 0xBD80 address of the SPI Flash.
// Custom AT command to change the Device Name
#ifdef USE_AT_DEVNAME
void save_name_on_SPI(void)
{

	//Re-configure P0_0 for SPI Flash
	GPIO_ConfigurePin(SPI_DO_GPIO_PORT, SPI_DO_GPIO_PIN, OUTPUT, PID_SPI_DO, false);
  int8_t ret;
	/* Wake-up SPI Flash */
	spi_flash_release_from_power_down();
	// 32 bytes- Size of Scan Response Data and Max Device Name Length
	uint32_t pc_bytes_written= 0x20;
	/* Erase data on address 0x0BD80 
		 We must always first Erase and then Write on an Address */
	ret = spi_flash_page_erase(0x0BD80);	//, SPI_FLASH_OP_BE32
#ifdef CFG_DEBUG_LOG_NAME
	if(ret == 0)	//If erase was successful
	{
		arch_printf("\n\r P25Q11U Flash sector 0x0BD80 has been erased \n\r");
	}
#endif

	/* Write data on address 0x0BD80*/
	ret = spi_flash_write_data((uint8_t *) &new_device_name, 0x0BD80, sizeof(new_device_name),  &pc_bytes_written);
#ifdef CFG_DEBUG_LOG_NAME
	arch_printf("\n\rWrite Status for 0x1FFC0: %d", ret);
	/* Print the written data if the Write Status does not return any Error */
	if(ret == 0)
	{
		arch_printf("\n\r Written Success ");
	}
#endif
	// Reduce power consumption by putting flash into sleep mode 
  spi_flash_power_down();
	
  // Re-enable HW reset input (must be disabled if/when further operation on
  // external flash are performed) - must set as input first!
  GPIO_ConfigurePin(SPI_DO_GPIO_PORT, SPI_DO_GPIO_PIN, INPUT_PULLDOWN, PID_GPIO, false);
	flag_devname = false;
}

void user_at_devname(struct at_cmd_params_t* arg, char* reply_string)
{
	//Restrict the AT command only via UART
	if (arg->cmd_source == CMD_SRC_LOCAL)
      {	
				
				char zeroed[GAP_MAX_NAME_SIZE] = "0";
				//Empty the new_device_name array
				memcpy(new_device_name, &zeroed, GAP_MAX_NAME_SIZE);
				//If AT+DEVNAME
				if( arg->arg_count ==0)
				{
					//We only printed out the name, so keep flag_devname = false;
					//flag_devname = false; 
					//Print the existing Device Name
					//arch_sprintf(reply_string, "%s", device_info.dev_name.name);
					arch_sprintf(reply_string, "%s", "Use the AT+SHOWNAME command \r\n");
					arg->success_flag = true;
				}
				else //else if AT+DEVNAME=
				{
					//We will change the Device Name (short and long) so change flag_devname= true
					flag_devname= true;
					changed_name = true;
					//Empty the device_info struct 
					memcpy(device_info.dev_name.name, &zeroed, GAP_MAX_NAME_SIZE);
					//Save the New device name into the new_device_name variable
					memcpy(&new_device_name, &arg->cmd_buffer[arg->arg_index[0]], GAP_MAX_NAME_SIZE);
					device_info.dev_name.length = (strlen(new_device_name) <= GAP_MAX_NAME_SIZE) ?strlen(new_device_name) : GAP_MAX_NAME_SIZE;
					//Save the New device name into the device_info struct
					memcpy(device_info.dev_name.name, new_device_name, device_info.dev_name.length);
					/* Set the Device Name to the codeless_env struct  */	
					 memcpy(&codeless_env.resp_data, &device_info.dev_name.name, device_info.dev_name.length);
					 codeless_env.resp_data_len = strlen(new_device_name);
					 // Instantiate the advertising update message to be sent
					struct gapm_update_advertise_data_cmd *cmd = KE_MSG_ALLOC(GAPM_UPDATE_ADVERTISE_DATA_CMD,
																																		TASK_GAPM,
																																		TASK_APP,
																																		gapm_update_advertise_data_cmd);

					cmd->operation = GAPM_UPDATE_ADVERTISE_DATA;
					//Set the Advertising Data as specifiec in user_app_init custom callback function
					#ifdef USE_AT_BINARY_MODE
					const uint8_t advertisement_data[] =
					#else 
					uint8_t advertisement_data[] =
					#endif 
					{ // Complete list of 128bit service UUIDs
					#ifdef USE_AT_BINARY_MODE 
							17, GAP_AD_TYPE_COMPLETE_LIST_128_BIT_UUID, SPS_SERV_ADV_UUID_REV_BYTES, 
					#else
							17, GAP_AD_TYPE_COMPLETE_LIST_128_BIT_UUID, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
							 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
					#endif
							 3, GAP_AD_TYPE_MORE_16_BIT_UUID, 0xF5, 0xFE, //SUOTA Service
						// Bluetooth Device Name
							 5, GAP_AD_TYPE_SHORTENED_NAME, 
							 new_device_name[0],
							 new_device_name[1],
							 new_device_name[2],
							 new_device_name[3]
					};
					#ifndef USE_AT_BINARY_MODE
					for (uint8_t i = 0; i < 16; i++) {
									advertisement_data[2 + i] = codeless_const_env.adv_service_uuid[i]; 
					}    
					#endif   
					 //Save the advertisemnt_data into the codeless_env struct
					memcpy(&codeless_env.adv_data, &advertisement_data, sizeof(advertisement_data));
					 //Save the Advertisment  data length into the codeless_env struct
					codeless_env.adv_data_len = sizeof(advertisement_data);
					// Update the Advertising data 
					cmd->adv_data_len = codeless_env.adv_data_len;
					memcpy(cmd->adv_data, codeless_env.adv_data, codeless_env.adv_data_len);

					/* Set the Device Name to Scan response data and show it */
					append_device_name(&cmd->scan_rsp_data_len,
														 codeless_env.resp_data_len,
														 &(cmd->scan_rsp_data[cmd->scan_rsp_data_len]),
														 codeless_env.resp_data);

					// Send the message
					ke_msg_send(cmd);
					
				//	arch_printf("Flag_devname bool : %s",flag_devname?"true":"false");


					//Print the New name
					arch_sprintf(reply_string, "%s", device_info.dev_name.name);
					arg->success_flag = true;
					//Save the New Device Name on the SPI Flash
					save_name_on_SPI();

			}
	}
}
#endif

user_codeless.c file V1 (user_app_on_init callback function changes)

C/C++
1) Declare the necessary variables
2) Implementation of the read_name_from_SPI(void) function that will read the Device Name from 0xBD80 address on SPI Flash after boot
3) Replace the user_app_on_init callback function that is executed after boot.
bool flag_for_name = true;



 //Will be stored the Device Name being read from SPI Flash
char device_name_after_reset[GAP_MAX_NAME_SIZE];
 /* Read the Flag_devname from SPI Flash address 0x1FE00 */
void read_name_from_SPI(void)
{
	//Empty array 
	char zeroed[GAP_MAX_NAME_SIZE] = "0";

	//Re-configure P0_0 for SPI Flash
	GPIO_ConfigurePin(SPI_DO_GPIO_PORT, SPI_DO_GPIO_PIN, OUTPUT, PID_SPI_DO, false);
	//Counter to see if we have stored another Device name in the SPI Flash
	int counter=0;
	//Variable to check if SPI Erase/Read was succesful
  int8_t ret;
	uint8_t devname_read[GAP_MAX_NAME_SIZE];
	char devname_stored[GAP_MAX_NAME_SIZE];
	//32 bytes, which is the GAP_MAX_NAME_SIZE and the MAX size of the Scan Response Data.
	uint32_t bytes_read=0x20;
	/* Wake-up SPI Flash */
	spi_flash_release_from_power_down();
	


	/*Read the data stored on address 0x0BD80 */
	ret = spi_flash_read_data((uint8_t *) &devname_read,0x0BD80 , sizeof(devname_read), &bytes_read);
#ifdef CFG_DEBUG_LOG_NAME
	arch_printf("\n\rRead Status for 0x0BD80: %d \n\r", ret);
#endif
	/* Print the data if the Read Status is OK 
		Uncomment the arch_printf if you want to Print the Bytes we have read from SPI Flash*/
	if(ret == 0)
	{
#ifdef CFG_DEBUG_LOG_NAME
		arch_printf("Bytes read:");
#endif
		int len = sizeof(devname_read);
		//Print all the data we read from SPI Flash
		while(len != 0)
		{
#ifdef CFG_DEBUG_LOG_NAME
			arch_printf(" %d |", devname_read[sizeof(devname_read) -len]);
#endif
			//Check if all the data is empty
			if(devname_read[sizeof(devname_read) -len] == 0xFF)
			{
				counter++;
			}
			//Store the Device name into a new array
			if(devname_read[sizeof(devname_read) -len] != 0x00)
			{
				if(devname_read[sizeof(devname_read) -len] == 0xFF)
				{
					break;
				}
				device_name_after_reset[sizeof(devname_read) -len] = devname_read[sizeof(devname_read) -len];

			}

			len--;
		}
		//If address 0x0BD80 is empty, then do not change the Device Name Struct and the Scan Response Data
		if(counter==32)
		{
			flag_for_name = true;
		}
		else// if address 0xBD80 is not empty, then use the stored Device Name
		{

			flag_for_name= false;
		}
#ifdef CFG_DEBUG_LOG_NAME
		arch_printf("\n\r");
#endif
	}
	// Reduce power consumption by putting flash into sleep mode 
  spi_flash_power_down();
	
  // Re-enable HW reset input (must be disabled if/when further operation on
  // external flash are performed) - must set as input first!
  GPIO_ConfigurePin(SPI_DO_GPIO_PORT, SPI_DO_GPIO_PIN, INPUT_PULLDOWN, PID_GPIO, false);

}


void user_app_on_init(void)
{
    // Create a static, random, Bluetooth Device Address
#if defined(CFG_USE_GENERATED_BLUETOOTH_ADDRESS)
    user_injected_bd_address = generate_random_bd_addr();
#else
    user_injected_bd_address = get_bd_addr_from_otp_or_nvds();
#endif
    default_app_on_init();
    // Set initial Bluetooth role
#ifdef CODELESS_585
    codeless_env.bt_role = GAP_ROLE_NONE;
#endif

    // Set the application state
    codeless_env.gap_activity = IDLE;
    codeless_env.adv_intv = user_adv_conf.intv_min;
    console_env.echo = true;
    console_env.error_report_flag = true;

    #ifdef USE_AT_BINARY_MODE
    codeless_env.binary_mode=false;
    codeless_env.escape_time1=MSEC_TO_ESC_TIMER1(CODELESS_DEFAULT_ESC_TIME1); //1sec
    codeless_env.escape_time2=MSEC_TO_ESC_TIMER2(CODELESS_DEFAULT_ESC_TIME2); //1sec
    codeless_env.escape_chars[0]='+';
    codeless_env.escape_chars[1]='+';
    codeless_env.escape_chars[2]='+';
    codeless_env.escape_chars_command_input=0x2B2B2B;
    #endif

    codeless_env.is_tk_entry_pending = false;

    // Specify the advertise data

    #ifdef USE_AT_FLOWCONTROL
    codeless_env.flow_control_enabled=false;
    #endif

    #ifdef USE_AT_CONPAR
    struct connection_configuration_t *p_conf=&codeless_env.conn_conf;
    p_conf->dle_en=true;
    p_conf->dle_tx_pkt_len=CFG_MAX_TX_PACKET_LENGTH;
    p_conf->dle_rx_pkt_len=CFG_MAX_RX_PACKET_LENGTH;
    p_conf->max_mtu=user_gapm_conf.max_mtu;
    #endif

    #ifdef USE_AT_HOSTSLP
    codeless_env.hst_sleep_mode=HOSTSL_DEFAULT_SLP_MODE;
    codeless_env.hst_sleep_wakeup_byte=HOSTSL_DEFAULT_WKUP_BYTE;
    codeless_env.hst_sleep_wakeup_retry_interval=HOSTSL_DEFAULT_WKUP_INTERVAL;
    codeless_env.hst_sleep_wakeup_retry_times=HOSTSL_DEFAULT_WKUP_TRIES;
    #endif

  
		//Read the address 0x0BD80 on SPI Flash to see if we have stored a different Device Name
		read_name_from_SPI();
#ifdef CFG_DEBUG_LOG_NAME
		//Print True if we have not a New device Name, Print False if we had stored a new Device Name	
		arch_printf("We did NOT store a new Device Name: %s",flag_for_name?"true":"false");
#endif	
		if(!flag_for_name)	//if we had stored a New Device name, print it
		{
			arch_printf("\r\n %s", device_name_after_reset);
		}
		if(flag_for_name)	//Default Operation, we have not stored any alternative Device Name in the SPI Flash
		{
			#ifdef USE_AT_BINARY_MODE
			const uint8_t advertisement_data[] =
			#else 
			uint8_t advertisement_data[] =
			#endif 
			{ // Complete list of 128bit service UUIDs
			#ifdef USE_AT_BINARY_MODE 
					17, GAP_AD_TYPE_COMPLETE_LIST_128_BIT_UUID, SPS_SERV_ADV_UUID_REV_BYTES, 
			#else
					17, GAP_AD_TYPE_COMPLETE_LIST_128_BIT_UUID, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
					 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
			#endif
					 3, GAP_AD_TYPE_MORE_16_BIT_UUID, 0xF5, 0xFE, //SUOTA Service
				// Bluetooth Device Name
					 5, GAP_AD_TYPE_SHORTENED_NAME, 
					 USER_DEVICE_NAME[0],
					 USER_DEVICE_NAME[1],
					 USER_DEVICE_NAME[2],
					 USER_DEVICE_NAME[3]
			};
			#ifndef USE_AT_BINARY_MODE
			for (uint8_t i = 0; i < 16; i++) {
							advertisement_data[2 + i] = codeless_const_env.adv_service_uuid[i]; 
			}    
			#endif    
			
			//Save the advertisemnt_data into the codeless_env struct
			memcpy(&codeless_env.adv_data, &advertisement_data, sizeof(advertisement_data));
			//Save the Advertisment  data length into the codeless_env struct
			codeless_env.adv_data_len = sizeof(advertisement_data);
			
			// Set scan response data where the full CodeLess name is shown
			codeless_env.resp_data[0] = USER_DEVICE_NAME_LEN + 1;
			codeless_env.resp_data[1] = GAP_AD_TYPE_COMPLETE_NAME;
			
			memcpy(&codeless_env.resp_data[2], USER_DEVICE_NAME, USER_DEVICE_NAME_LEN);
			codeless_env.resp_data_len = USER_DEVICE_NAME_LEN + 2;
	  }
		else if(!flag_for_name)	//if we have stored a different Device Name, then use this device name on the Scan Response Data
		{
						//Set the Advertising Data as specifiec in user_app_init custom callback function
					#ifdef USE_AT_BINARY_MODE
					const uint8_t advertisement_data[] =
					#else 
					uint8_t advertisement_data[] =
					#endif 
					{ // Complete list of 128bit service UUIDs
					#ifdef USE_AT_BINARY_MODE 
							17, GAP_AD_TYPE_COMPLETE_LIST_128_BIT_UUID, SPS_SERV_ADV_UUID_REV_BYTES, 
					#else
							17, GAP_AD_TYPE_COMPLETE_LIST_128_BIT_UUID, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
							 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
					#endif
							 3, GAP_AD_TYPE_MORE_16_BIT_UUID, 0xF5, 0xFE, //SUOTA Service
						// Bluetooth Device Name
							 5, GAP_AD_TYPE_SHORTENED_NAME, 
							 device_name_after_reset[0],
							 device_name_after_reset[1],
							 device_name_after_reset[2],
							 device_name_after_reset[3]
					};
					#ifndef USE_AT_BINARY_MODE
					for (uint8_t i = 0; i < 16; i++) {
									advertisement_data[2 + i] = codeless_const_env.adv_service_uuid[i]; 
					}    
					#endif   
					 //Save the advertisemnt_data into the codeless_env struct
					memcpy(&codeless_env.adv_data, &advertisement_data, sizeof(advertisement_data));
					 //Save the Advertisment  data length into the codeless_env struct
					codeless_env.adv_data_len = sizeof(advertisement_data);
					
					//Empty array 
					char zeroed[GAP_MAX_NAME_SIZE] = "0";
					//Empty the device_info struct 
					memcpy(device_info.dev_name.name, &zeroed, GAP_MAX_NAME_SIZE);
					device_info.dev_name.length = strlen(device_name_after_reset);
					//Save the New device name into the device_info struct
					memcpy(device_info.dev_name.name, device_name_after_reset, device_info.dev_name.length);
					/* Set the Device Name to the codeless_env struct  */	
				  memcpy(&codeless_env.resp_data, &device_info.dev_name.name, device_info.dev_name.length);
				  codeless_env.resp_data_len = strlen(device_name_after_reset);
				

		}

    // set codeless to connectable.
    codeless_env.is_connectable = true;
    // Initialize input command index to zero.
    console_env.input_cmd_char_index = 0;
    // Initialize parser flag
    console_env.parser_flag = CHAR_PARSER_NOT_ACTIVE;
#if defined(USE_AT_BND)
    #if (BLE_APP_SEC)
        // The bdb should be initialized once if the bonding commands are
        // included. The security should be enabled as well otherwise the
        // bond commands do not make sense.
        default_app_bdb_init();
    #else
        #warning "Bonding commands are included but security is disabled;No bonding commands will be available"
    #endif
#endif
#if defined(USE_AT_HNDL)
    // The hdb should be initialized once if the handler commands are
    // included
    app_hdb_init();
#endif

#if defined(USE_AT_CONPAR) || defined(USE_AT_MAXMTU) || defined(USE_AT_DLEEN)
    app_cpdb_init();
    app_load_cpdb_conf_from_flash(&codeless_env.conn_conf);
#endif

#if defined (USE_AT_EVENT)
    // The events database should be initialized once if the event command
    // is included
    app_evdb_init();
#endif

}

user_codeless.c file V2 (user_advertise new implementation)

C/C++
Replace the user_advertise function with the new implementation that will take into consideration the new Device name
void user_advertise(void)
{
	read_name_from_SPI();
	
	if(flag_for_name)// Default Operation, We have no Device Name stored in the SPI Flash (0x0BD80)
	{
				struct gapm_start_advertise_cmd* cmd;

				if (codeless_env.is_connectable)
				{
						cmd = app_easy_gap_undirected_advertise_get_active();
				} 
				else 
				{
						cmd = app_easy_gap_non_connectable_advertise_get_active();
				}
				// Specify the advertise data
				cmd->info.host.adv_data_len = codeless_env.adv_data_len;
				memcpy(&cmd->info.host.adv_data, &codeless_env.adv_data, codeless_env.adv_data_len);
				// Specify scan response data (if any)
				if (codeless_env.resp_data_len > 0 && codeless_env.is_connectable)
				{
						cmd->info.host.scan_rsp_data_len = codeless_env.resp_data_len;
						memcpy(&cmd->info.host.scan_rsp_data, &codeless_env.resp_data, codeless_env.resp_data_len);
				}
				else
				{
						cmd->info.host.scan_rsp_data_len = 0;
				}
				// Set advertising interval
				cmd->intv_min = codeless_env.adv_intv;
				cmd->intv_max = codeless_env.adv_intv;
				// Set the advertise mode
				if (codeless_env.is_connectable)
				{
						cmd->info.host.mode = GAP_GEN_DISCOVERABLE;
				}
				else
				{
						cmd->info.host.mode = GAP_BROADCASTER_MODE;
				}
				

			
			if (codeless_env.is_connectable)
			{
						app_easy_gap_undirected_advertise_start();			  
			}
			else 
			{
						app_easy_gap_non_connectable_advertise_start();   			  
			}

				// Retain the current activity state
				codeless_env.gap_activity = ADVERTISING;
		}
		else if(!flag_for_name) // If we have stored a new Device Name 
		{
				struct gapm_start_advertise_cmd* cmd;

				if (codeless_env.is_connectable)
				{
						cmd = app_easy_gap_undirected_advertise_get_active();
				} 
				else 
				{
						cmd = app_easy_gap_non_connectable_advertise_get_active();
				}
					

				// Update the Advertising data 
				cmd->info.host.adv_data_len = codeless_env.adv_data_len;
				memcpy(cmd->info.host.adv_data, codeless_env.adv_data, codeless_env.adv_data_len);

				/* Set the Device Name to Scan response data and show it */
				append_device_name(&cmd->info.host.scan_rsp_data_len,
													 codeless_env.resp_data_len,
													 &(cmd->info.host.scan_rsp_data[cmd->info.host.scan_rsp_data_len]),
													 codeless_env.resp_data);
					
				// Set advertising interval
				cmd->intv_min = codeless_env.adv_intv;
				cmd->intv_max = codeless_env.adv_intv;
				// Set the advertise mode
				if (codeless_env.is_connectable) {
						cmd->info.host.mode = GAP_GEN_DISCOVERABLE;
				} else {
						cmd->info.host.mode = GAP_BROADCASTER_MODE;
				}
				//Start Advertising
				if (codeless_env.is_connectable) {
						app_easy_gap_undirected_advertise_start();			  
				} else {
						app_easy_gap_non_connectable_advertise_start();   			  
				}

				// Retain the current activity state
				codeless_env.gap_activity = ADVERTISING;
			}
		
}

Changes on user_codeless.h file

C Header File
Declare the read_name_from_SPI(void) function.
void read_name_from_SPI(void);

Credits

Wireless Embedded
2 projects • 1 follower
Firmware Engineer. Enthusiast for Wireless Connectivity on Embedded Projects. BLE/ Wi-Fi

Comments