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

Secure DFU with NUS and UART using SDK 15

Hi,

Using the Secure DFU from SDK 14.2 I managed to integrate the NUS peripheral example to have access to an UART pipe in parallel to the DFU when running the boot loader. Now I would like to port this to SDK 15.3 and I run into trouble when adding the UART code. For debugging purposes I based my project on the pca10040_ble_debug example, using the pca10040 dev board.

I managed to make the NUS service work without any problem with same principle as before, basically extending ble_dfu_transport_init() inside nrf_dfu_ble.c with yet another service. naturally I had to add some additional libraries, defines, and include path as well:

#include "ble_nus.h"
BLE_NUS_DEF(m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT);

static void nus_data_handler(ble_nus_evt_t * p_evt)
{
    switch( p_evt->type){
        case BLE_NUS_EVT_RX_DATA:
            NRF_LOG_DEBUG("Received some NUS data");
            break;
        default:
            break;
    }
}

uint32_t ble_dfu_transport_init(nrf_dfu_observer_t observer)
{
    uint32_t err_code = NRF_SUCCESS;
    ble_nus_init_t nus_init;
...
    // Initialize NUS Service.
    memset(&nus_init, 0, sizeof(nus_init));
    nus_init.data_handler = nus_data_handler;
    err_code = ble_nus_init(&m_nus, &nus_init);
    APP_ERROR_CHECK(err_code);
---
}

Now, I continue by integrating the UART and this is when I run into trouble. This is what I reused from NUS peripheral example

#include "boards.h"
#include "app_uart.h"

#if defined (UART_PRESENT)
    #include "nrf_uart.h"
#endif
  
#if defined (UARTE_PRESENT)
    #include "nrf_uarte.h"
#endif

#define UART_TX_BUF_SIZE    (256)
#define UART_RX_BUF_SIZE    (256)

...

void app_uart_event_handle(app_uart_evt_t * p_event)
{
    uint32_t  err_code;

    switch (p_event->evt_type)
    {
        case APP_UART_DATA_READY:
            NRF_LOG_DEBUG("Received some UART Data");
            break;

        case APP_UART_COMMUNICATION_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_communication);
            break;

        case APP_UART_FIFO_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_code);
            break;

        default:
            break;
    }
}

...

uint32_t ble_dfu_transport_init(nrf_dfu_observer_t observer)
{
    uint32_t              err_code;
    app_uart_comm_params_t const comm_params =
    {
        .rx_pin_no    = RX_PIN_NUMBER,
        .tx_pin_no    = TX_PIN_NUMBER,
        .rts_pin_no   = RTS_PIN_NUMBER,
        .cts_pin_no   = CTS_PIN_NUMBER,
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
        .use_parity   = false,
#if defined (UART_PRESENT)
        .baud_rate    = NRF_UART_BAUDRATE_115200
#else
        .baud_rate    = NRF_UARTE_BAUDRATE_115200
#endif
    };

...

    APP_UART_FIFO_INIT(&comm_params,
                       UART_RX_BUF_SIZE,
                       UART_TX_BUF_SIZE,
                       app_uart_event_handle,
                       APP_IRQ_PRIORITY_LOWEST,
                       err_code);

...

}

When I Build and Debug I get the following debug output with errors:

<info> app: Inside main
<debug> app: In nrf_bootloader_init
<debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
<debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
<debug> nrf_dfu_settings: Using settings page.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<info> nrf_dfu_settings: Backing up settings page to address 0x7E000.
<debug> nrf_dfu_settings: Writing settings...
<debug> nrf_dfu_settings: Erasing old settings at: 0x0007E000
<debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007E000, len=1 pages), queue usage: 0
<debug> nrf_dfu_flash: Flash erase success: addr=0x0007E000, pending 0
<debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007E000, src=0x20009E2C, len=896 bytes), queue usage: 1
<debug> nrf_dfu_flash: Flash write success: addr=0x0007E000, pending 0
<debug> app: Enter nrf_bootloader_fw_activate
<info> app: No firmware to activate.
<info> app: Boot validation failed. No valid app to boot.
<debug> app: DFU mode because app is not valid.
<info> nrf_bootloader_wdt: WDT is not enabled
<debug> app: in weak nrf_dfu_init_user
<debug> app: timer_stop (0x20005808)
<debug> app: timer_activate (0x20005808)
<info> app: Entering DFU mode.
<debug> app: Initializing transports (found: 1)
<debug> nrf_dfu_ble: Initializing BLE DFU transport
<debug> nrf_dfu_ble: Setting up vector table: 0x00072000
<debug> nrf_dfu_ble: Enabling SoftDevice.
<debug> app: Failed to initialize transport 0, error 4096
<error> app: Could not initalize DFU transport: 0x00001000
<error> app: Received an error: 0x00000003!

I am not sure from where the error origins. However, the ble_dfu_transport_init() function inside nrf_dfu_ble.c exits after evaluating the err_code from nrf_sdh_enable_request();

    NRF_LOG_DEBUG("Enabling SoftDevice.");
    err_code = nrf_sdh_enable_request();
    VERIFY_SUCCESS(err_code);

Now, if I comment out APP_UART_FIFO_INIT(.) this error disappear and main loop is entered.

...
<debug> nrf_dfu_ble: Using default advertising name
<debug> nrf_dfu_ble: Advertising...
<debug> nrf_dfu_ble: BLE DFU transport initialized.
<debug> nrf_dfu_flash: Initializing nrf_fstorage_sd backend.
<debug> app: Enter main loop

Parents
  • Hi all,

    Sorry to bother you all about this. It looks like this is related to FLASH_START, and FLASH_SIZE.

    When I compile using SES and check the memory usage there is 0.0kB Flash free. Ones I saw this I decrease FLASH_START, and increase FLASH_SIZE a few kB and all of a sudden I got some free flash after compile.

    When I run the code the errors above are gone and the code enters main loop as expected.

Reply
  • Hi all,

    Sorry to bother you all about this. It looks like this is related to FLASH_START, and FLASH_SIZE.

    When I compile using SES and check the memory usage there is 0.0kB Flash free. Ones I saw this I decrease FLASH_START, and increase FLASH_SIZE a few kB and all of a sudden I got some free flash after compile.

    When I run the code the errors above are gone and the code enters main loop as expected.

Children
No Data
Related