This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Device freezing after change tx power from the nrf app

Hello All,

I have nrf52810 chip. using softdevice 6.1.1

I have implemented dfu feature.

Now i have  implement tx power change feature through nrf connect mobile app using custom service .

I am saving the variable in flash after receive from app but code is freezing there while setting tx power.

Device is not advertising , its hanging there..

So i have try to use NVIC_systemReset() , but after reset my all buffer are resetting . After that am reading saved data from the flash but it is not reading new data ,

It is taking default data that set while initializing code at the start.

for this tx power change Is reset is required to set updated tx pwer value?

If yes then which reset should i use ? Is there any soft reset?

Please check my code for tx power change below and provide your input.

/********************************************************************************************************************************************/
            
            //  ----------------------------------------------changing the TX Power---------------------------------------------------------------------

            /********************************************************************************************************************************************/

             // CODE is " 0x46 " for Changing the ADVERTISING INTERVAL

                if(((temp_name_id[0] == temp_name_id[0]) && (temp_name_id[1] == 0x46))&&((temp_name_id[2] == 0x4A)||(temp_name_id[2] == 0x4B)||(temp_name_id[2] == 0x4C)||(temp_name_id[2] == 0x4D)))
                {
                    sd_ble_gap_adv_stop(m_adv_handle); //STOP ADVERTISING
                     
                    err_code = fds_test_find_and_delete3();
                    APP_ERROR_CHECK(err_code);
                    Tx_value_buff[0] = temp_name_id[2]; //copy tx flag value

                    err_code =fds_test_write3();
                    APP_ERROR_CHECK(err_code);
                    
                    select_tx_pwr();
                    
                    ret_code_t err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, TX_POWER_LEVEL);
                    APP_ERROR_CHECK(err_code);
                    ble_tps_tx_power_level_set(&m_tps, TX_POWER_LEVEL);
                    //                  tx_power_set();
                    NVIC_SystemReset();
                    //sd_nvic_systemreset();

                }
                
                
static void select_tx_pwr(void)
{
     if(Tx_value_buff[0] == 0x00)
     {
          TX_POWER_LEVEL = 80; // max tx power
     }
     else if(Tx_value_buff[0] == 0x4A)
     {
          TX_POWER_LEVEL = TX_POWER_LEVEL; // max tx power
     }
     else if (Tx_value_buff[0] == 0x4B)
     {
          TX_POWER_LEVEL = TX_POWER_LEVEL1; //mid1  tx power
     }
     else if(Tx_value_buff[0] == 0x4C)
     {
          TX_POWER_LEVEL = TX_POWER_LEVEL2; //mid2  tx power
     }
     else if(Tx_value_buff[0] == 0x4D)
     {
          TX_POWER_LEVEL = TX_POWER_LEVEL3; // min tx power
     }
}

////////////////////////////////////////////////////////////tx
static ret_code_t fds_test_write3(void)
{
                fds_record_t        record3;
		fds_record_desc_t   record_desc3;
                //tempbuff

                ////////////////////////////////
                // Set up record.
		record3.file_id              = FILE_ID_FDS_TEST3;
		record3.key                  = REC_KEY_FDS_TEST_3;

                temp_data_3 = Tx_value_buff[0];

		record3.data.p_data       = &temp_data_3;
		//record.data.length_words   = sizeof(m_deadbeef)/sizeof(uint32_t);
		record3.data.length_words   = sizeof(Tx_value_buff)/sizeof(uint8_t);
				
                                record_desc3.record_id =3;
		ret_code_t ret = fds_record_write(&record_desc3, &record3);
		if (ret != FDS_SUCCESS)
		{
				return ret;
		}
		 NRF_LOG_INFO("Writing Record ID = %d \r\n",record_desc3.record_id);
		return NRF_SUCCESS;
}
//////////// tx
static ret_code_t fds_read3(void)
{
                fds_flash_record_t  flash_record3;
		fds_record_desc_t   record_desc3;
		fds_find_token_t    ftok3 ={0};//Important, make sure you zero init the ftok token
		//uint32_t *data;
		uint8_t *data_3;
		uint32_t err_code;
                uint8_t i=0;
		
//                write_flag_fds_test = 0;

		NRF_LOG_INFO("id 2 Start searching... \r\n");
//////////////////////////////////////////////////////////////
                while (fds_record_find(FILE_ID_FDS_TEST3, REC_KEY_FDS_TEST_3, &record_desc3, &ftok3) == FDS_SUCCESS)
                //while (fds_record_find_in_file(FILE_ID_FDS_TEST, &record_desc, &ftok) == FDS_SUCCESS)
		{
				err_code = fds_record_open(&record_desc3, &flash_record3);
				if ( err_code != FDS_SUCCESS)
				{
					return err_code;		
				}
				
				NRF_LOG_INFO("Found Record ID3 = %d\r\n",record_desc3.record_id);
				NRF_LOG_INFO("Data_3 = ");
				//data = (uint32_t *) flash_record.p_data;
				data_3 = (uint8_t *) flash_record3.p_data;
				for (uint8_t i=0;i<flash_record3.p_header->length_words;i++)
				{
					NRF_LOG_INFO("%d ",(data_3[i]));
				}
				NRF_LOG_INFO("\r\n");
                                NRF_LOG_INFO("%d ",(data_3[i]));
                                Tx_value_buff[0] = *data_3;
                                select_tx_pwr();
                                counter2++;
//                                select_advt_int();
//                                if(tempbuff[0] = 0x00)
//                                {
//                                  bsp_board_init(BSP_INIT_LEDS);
//                                  bsp_board_led_off(ADVERTISING_LED);
//                                }
                                //tempbuff[0] = tempbuff[0]+1;
//                                data[2]= 45;
//                                NRF_LOG_INFO("0x%8x ",data[2]);
//                                NRF_LOG_INFO("0x%8x ",data[3]);
//                                if(record_desc.record_id == 1)
//                                {
//                                  for (uint8_t i=0;i<flash_record.p_header->length_words;i++)
//                                  {
//                                        NRF_LOG_INFO("%x",data[i]);
//                                  }
//                                  //NRF_LOG_INFO("0x%8x ",data[2]);
//                                }
                                //fds_record_find_in_file()
				// Access the record through the flash_record structure.
				// Close the record when done.
				err_code = fds_record_close(&record_desc3);
				if (err_code != FDS_SUCCESS)
				{
					return err_code;	
				}
		}
		return NRF_SUCCESS;
		
}
               ////for tx////////////////////////////////////////////////////////
static ret_code_t fds_test_find_and_delete3 (void)
{
                fds_record_desc_t   record_desc3;
		fds_find_token_t    ftok3;
                // Loop and find records with same ID and rec key and mark them as deleted. 
		while (fds_record_find(FILE_ID_FDS_TEST3, REC_KEY_FDS_TEST_3, &record_desc3, &ftok3) == FDS_SUCCESS)
		{
			fds_record_delete(&record_desc3);
			NRF_LOG_INFO("Deleted record ID: %d \r\n",record_desc3.record_id);
		}
		// call the garbage collector to empty them, don't need to do this all the time, this is just for demonstration
		ret_code_t ret = fds_gc();
		if (ret != FDS_SUCCESS)
		{
				return ret;
		}
		return NRF_SUCCESS;
}

static ret_code_t fds_test_init (void)
{
	
		ret_code_t ret = fds_register(my_fds_evt_handler);
		if (ret != FDS_SUCCESS)
		{
					return ret;
				
		}
		ret = fds_init();
		if (ret != FDS_SUCCESS)
		{
				return ret;
		}
		
		return NRF_SUCCESS;
		
}

static void my_fds_evt_handler(fds_evt_t const * const p_fds_evt)
{
    switch (p_fds_evt->id)
    {
        case FDS_EVT_INIT:
            if (p_fds_evt->result != FDS_SUCCESS)
            {
                // Initialization failed.
            }
            break;
        case FDS_EVT_WRITE:
            if (p_fds_evt->result == FDS_SUCCESS)
            {
                    write_flag_fds_test=1;
            }
            break;
        default:
            break;
    }
}

Waiting for your reply...

Regards,

Rohit

Parents Reply Children
No Data
Related