Advertising doesn't change name after code update

Greetings,

I've been developing a DFU firmware that should update the device through Android. The thing is, the device works, but I changed the advertising name, and it still shows the old name when I try to update the device. I use the following function to update the name:

static void make_dev_name(void)
{
    ble_gap_addr_t device_address;
    uint8_t companyName[] = {"M"};
    uint8_t modelName[] = {"1"};
    uint8_t *macAddressName;
    uint8_t macTmp[12];

    sd_ble_gap_addr_get(&device_address);
    macAddressName = Convert_Hex_To_Ascii(&device_address.addr[0], 4);
    memcpy(&DEVICE_NAME[0], companyName, 1);
    memcpy(&DEVICE_NAME[1], modelName, 1);
    memcpy(&DEVICE_NAME[2], macAddressName, 12);

}

Any idea why this issue occurs?

I used reference from here;
https://novelbits.io/ota-device-firmware-update-part-3/

Parents
  • Hello,

    When is make_dev_name() called, is it only on startup, or are you sending a command over BLE to update the name? 

    Best regards,

    Vidar

  • Only on start-up.

    int main(void)
    {
        bool erase_bonds;
        ret_code_t err_code;
        ble_gap_addr_t device_address;
        
        // Comment this for new modules
        sd_power_dcdc_mode_set(1);
    
        // Initialize.
        uart_init();
        log_init();
    
        // Initialize the async SVCI interface to bootloader before any interrupts are enabled.
        err_code = ble_dfu_buttonless_async_svci_init();
        APP_ERROR_CHECK(err_code);
    
        timers_init();
        buttons_leds_init(&erase_bonds);
        power_management_init();
        ble_stack_init();
    
        make_dev_name();
    
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
    
        //if(nrf_gpio_pin_read(WAKEUP_IN_PIN))
        //{
        //    while(1);   // wait here 
        //}
    
        sd_ble_gap_addr_get(&device_address);
        nrf_delay_ms(5);
        while(!nrf_gpio_pin_read(WAKEUP_IN_PIN))
        {
            //nrf_gpio_pin_clear(UART_TX_NOTIFY);
            //nrf_delay_ms(250);
            //nrf_gpio_pin_set(UART_TX_NOTIFY);
            for(int i=0; i<6; i++)
            {
                do
                {
                    err_code = app_uart_put(device_address.addr[i]);
                    if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
                    {
                        NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                        APP_ERROR_CHECK(err_code);
                    }
                } while (err_code == NRF_ERROR_BUSY);
                
            }
            //nrf_delay_ms(500);
            nrf_delay_ms(50);
        }
    
        // Start execution.
        //printf("\r\nApplication started.\r\n");
        NRF_LOG_INFO("Debug logging for UART over RTT started.");
        while(app_uart_tx_done());
        app_uart_close();
        advertising_start();
    
        wdt_init();
    
        // Enter main loop.
        for (;;)
        {
            // Feed the watchdog
            feed_dog();
            // Power management 
            idle_state_handle();
    
        }
    }

  • This is the error I get in the debug output.

    <error> app: ERROR 12 [NRF_ERROR_DATA_SIZE] at C:\Proj\nRF5_SDK_17.1.0_ddde560\PROJECT\MyProj\003p\main.c:832
    PC at: 0x000272D5
    <error> app: End of error report

    So there are 2 outcomes:

    1. When I go with step during debugging, the program goes into infinite loop (HardFault_Handler()) on the log_init() part.
    2. When I go with Continue execution, the error above appears when the debugger continues to execute from line 1045 (timers_init()).

  • This error is raised by the UARTE peripheral if it received invalid data. This can happen if the UART RX input is left floating or if you have an external device sending invalid data packets. You can comment the APP_ERROR_HANDLER line if you want to ignore com. errors.

  • Ok, I did this and now I get the same error but with different address: 0x0002726D. I also tried with commented timers_init(), but now it does the same with the next line (buttons_leds_init) and debugging stops at NRF_BREAKPOINT_COND.

    I tried to build the project in the Nordic examples (the uart specifically), the advertising worked as it should.

    I assume the possible issue is with the bootloader, because in the Nordic example I only used the App and the Softdevice. There was no Bootloader there.

    It leaves me confused to see the same code in both projects at the main part, but in this one, it throws errors during the initialization parts.

  • You need to find the line number and file name of where the error was raised. This should be shown in the debug log.

  • Ok, so I finally found the culprit behind this. It's actually the UART. Because the UART needs to communicate with another controller, I assume it compares the advertising value from the flash on the other chip with the one from Nordic and overwrites it. When I disabled the UART init, the code works as it is intended.

Reply Children
No Data
Related