void nrf_bootloader_app_start(uint32_t start_addr)
{
    NRF_LOG_DEBUG("Running nrf_bootloader_app_start with address: 0x%08x", start_addr);
    uint32_t err_code;

    //NRF_LOG_INFO("Initializing SD in mbr");
    err_code = nrf_dfu_mbr_init_sd();
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR("Failed running nrf_dfu_mbr_init_sd");
        return;
    }

    // Disable and clear interrupts
    NRF_LOG_DEBUG("Disabling interrupts");

    NVIC->ICER[0]=0xFFFFFFFF;
    NVIC->ICPR[0]=0xFFFFFFFF;
#if defined(__NRF_NVIC_ISER_COUNT) && __NRF_NVIC_ISER_COUNT == 2
    NVIC->ICER[1]=0xFFFFFFFF;
    NVIC->ICPR[1]=0xFFFFFFFF;
#endif

    // Set the sd softdevice vector table base address
    NRF_LOG_DEBUG("Setting SD vector table base: 0x%08x", start_addr);
    err_code = sd_softdevice_vector_table_base_set(start_addr);
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR("Failed running sd_softdevice_vector_table_base_set");
        return;
    }

    // Run application
    nrf_bootloader_app_start_impl(start_addr);
}
Exemple #2
0
static uint32_t ble_stack_init(bool init_softdevice)
{
    uint32_t         err_code;
    nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;

    if (init_softdevice)
    {
        err_code = nrf_dfu_mbr_init_sd();
        VERIFY_SUCCESS(err_code);
    }

    NRF_LOG_INFO("vector table: 0x%08x\r\n", BOOTLOADER_START_ADDR);
    err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_START_ADDR);
    VERIFY_SUCCESS(err_code);

    SOFTDEVICE_HANDLER_APPSH_INIT(&clock_lf_cfg, true);

    ble_enable_params_t ble_enable_params;
    // Only one connection as a central is used when performing dfu.
    err_code = softdevice_enable_get_default_config(1, 1, &ble_enable_params);
    VERIFY_SUCCESS(err_code);

#if (NRF_SD_BLE_API_VERSION == 3)
    ble_enable_params.gatt_enable_params.att_mtu = NRF_BLE_MAX_MTU_SIZE;
#endif    
    
    // Enable BLE stack.
    err_code = softdevice_enable(&ble_enable_params);
    return err_code;
}
/**
 * @brief Function for relocation of the vector to RAM on nRF5x devices.
 * This function is intended to be called during startup.
 */
void nrf_reloc_vector_table(void)
{
    // Copy and switch to dynamic vectors
	uint32_t *old_vectors = VECTORS_FLASH_START;
	uint32_t i;
	for (i = 0; i< NVIC_NUM_VECTORS; i++) {
		nrf_dispatch_vector[i] = old_vectors[i];
	}

#if defined(SOFTDEVICE_PRESENT)

    /**
     * Before setting the new vector table address in the SoftDevice the MBR must be initialized.
     * If no bootloader is present the MBR will be initialized automatically.
     * If a bootloader is present nrf_dfu_mbr_init_sd must be called once and only once.
     * 
     * By resetting the MBR and SoftDevice VTOR address first, it becomes safe to initialize
     * the MBR again regardless of how the application was started. 
     */

    /* Reset MBR VTOR to original state before calling MBR init. */
    uint32_t *mbr_vtor_address = (uint32_t *) MBR_VTOR_ADDRESS;
    *mbr_vtor_address = (uint32_t) VECTORS_FLASH_START;

    /* Reset SoftDevive VTOR. */
    uint32_t *softdevice_vtor_address = (uint32_t *) SOFTDEVICE_VTOR_ADDRESS;
    *softdevice_vtor_address = 0xFFFFFFFF;

    /* Set SCB->VTOR to go through MBR to trap SoftDevice service calls. */
    SCB->VTOR = 0x0;

    /* Initialize MBR so SoftDevice service calls are being trapped correctly. 
     * This call sets MBR_VTOR_ADDRESS to point to the SoftDevice's VTOR at address 0x1000.
     */
    nrf_dfu_mbr_init_sd();

    /* Instruct the SoftDevice to forward interrupts to the application's vector table in RAM. */
    sd_softdevice_vector_table_base_set((uint32_t) nrf_dispatch_vector);

#else

    /* No SoftDevice is present. Set all interrupts to vector table in RAM. */
    SCB->VTOR = (uint32_t) nrf_dispatch_vector;    
#endif
}
void nrf_bootloader_app_start(uint32_t start_addr)
{
    NRF_LOG_INFO("Running nrf_bootloader_app_start with address: 0x%08x\r\n", start_addr);

#ifdef BLE_STACK_SUPPORT_REQD
    uint32_t err_code;

    //NRF_LOG_INFO("Initializing SD in mbr\r\n");
    err_code = nrf_dfu_mbr_init_sd();
    if(err_code != NRF_SUCCESS)
    {
        NRF_LOG_INFO("Failed running nrf_dfu_mbr_init_sd\r\n");
        return;
    }

#endif

    // Disable interrupts
    NRF_LOG_INFO("Disabling interrupts\r\n");

    NVIC->ICER[0]=0xFFFFFFFF;
#if defined(__NRF_NVIC_ISER_COUNT) && __NRF_NVIC_ISER_COUNT == 2
    NVIC->ICER[1]=0xFFFFFFFF;
#endif

#ifdef BLE_STACK_SUPPORT_REQD
    // Set the sd softdevice vector table base address
    NRF_LOG_INFO("Setting SD vector table base: 0x%08x\r\n", start_addr);
    err_code = sd_softdevice_vector_table_base_set(start_addr);
    if(err_code != NRF_SUCCESS)
    {
        NRF_LOG_INFO("Failed running sd_softdevice_vector_table_base_set\r\n");
        return;
    }
#endif

    // Run application
    nrf_bootloader_app_start_impl(start_addr);
}
Exemple #5
0
static uint32_t ble_stack_init(bool init_softdevice)
{
    uint32_t         err_code;
    nrf_clock_lf_cfg_t clock_lf_cfg = {
            .source        = NRF_CLOCK_LF_SRC_RC,
            .rc_ctiv       = 16, // recommended for nRF52
            .rc_temp_ctiv  = 2,  // recommended for nRF52
            .xtal_accuracy = 0};

    if (init_softdevice)
    {
        err_code = nrf_dfu_mbr_init_sd();
        VERIFY_SUCCESS(err_code);
    }

    NRF_LOG_INFO("vector table: 0x%08x\r\n", BOOTLOADER_START_ADDR);
    err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_START_ADDR);
    VERIFY_SUCCESS(err_code);

    SOFTDEVICE_HANDLER_APPSH_INIT(&clock_lf_cfg, true);

    ble_enable_params_t ble_enable_params;
    // Only one connection as a central is used when performing dfu.
    err_code = softdevice_enable_get_default_config(1, 1, &ble_enable_params);
    VERIFY_SUCCESS(err_code);

#if (NRF_SD_BLE_API_VERSION == 3)
    ble_enable_params.gatt_enable_params.att_mtu = NRF_BLE_MAX_MTU_SIZE;
#endif    
    
    // Enable BLE stack.
    err_code = softdevice_enable(&ble_enable_params);
    return err_code;
}


/**@brief       Function for adding DFU Packet characteristic to the BLE Stack.
 *
 * @param[in]   p_dfu DFU Service structure.
 *
 * @return      NRF_SUCCESS on success. Otherwise an error code.
 */
static uint32_t dfu_pkt_char_add(ble_dfu_t * const p_dfu)
{
    ble_gatts_char_md_t char_md             = {{0}};
    ble_gatts_attr_t    attr_char_value     = {0};
    ble_gatts_attr_md_t attr_md             = {{0}};
    ble_uuid_t          char_uuid;

    char_md.char_props.write_wo_resp = 1;

    char_uuid.type = p_dfu->uuid_type;
    char_uuid.uuid = BLE_DFU_PKT_CHAR_UUID;

    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);

    attr_md.vloc    = BLE_GATTS_VLOC_STACK;
    attr_md.vlen    = 1;

    attr_char_value.p_uuid    = &char_uuid;
    attr_char_value.p_attr_md = &attr_md;
    attr_char_value.max_len   = MAX_DFU_PKT_LEN;
    attr_char_value.p_value   = NULL;

    return sd_ble_gatts_characteristic_add(p_dfu->service_handle,
                                           &char_md,
                                           &attr_char_value,
                                           &p_dfu->dfu_pkt_handles);
}