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 initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. * * @param[in] init_softdevice true if SoftDevice should be initialized. The SoftDevice must only * be initialized if a chip reset has occured. Soft reset from * application must not reinitialize the SoftDevice. */ static void ble_stack_init(bool init_softdevice) { uint32_t err_code; sd_mbr_command_t com = {SD_MBR_COMMAND_INIT_SD, }; if (init_softdevice) { err_code = sd_mbr_command(&com); APP_ERROR_CHECK(err_code); } err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_REGION_START); APP_ERROR_CHECK(err_code); SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, true); // Enable BLE stack ble_enable_params_t ble_enable_params; memset(&ble_enable_params, 0, sizeof(ble_enable_params)); ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT; err_code = sd_ble_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. * * @param[in] init_softdevice true if SoftDevice should be initialized. The SoftDevice must only * be initialized if a chip reset has occured. Soft reset from * application must not reinitialize the SoftDevice. */ static void ble_stack_init(bool init_softdevice) { uint32_t err_code; sd_mbr_command_t com = {SD_MBR_COMMAND_INIT_SD, }; if (init_softdevice) { err_code = sd_mbr_command(&com); APP_ERROR_CHECK(err_code); } err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_REGION_START); APP_ERROR_CHECK(err_code); SOFTDEVICE_HANDLER_APPSH_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, true); // Enable BLE stack ble_enable_params_t ble_enable_params; memset(&ble_enable_params, 0, sizeof(ble_enable_params)); // Below code line is needed for s130. For s110 is inrrelevant - but executable // can run with both s130 and s110. ble_enable_params.gatts_enable_params.attr_tab_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT; ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT; err_code = sd_ble_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); }
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); }
/* * Function for initializing the BLE stack. * * Initializes the SoftDevice and the BLE event interrupt. * * param[in] init_softdevice true if SoftDevice should be initialized. * The SoftDevice must only be initialized * if a chip reset has occured. Soft reset from * application must not reinitialize the SoftDevice. */ static void ble_stack_init(bool init_softdevice) { uint32_t err_code; sd_mbr_command_t com = {SD_MBR_COMMAND_INIT_SD, }; if (init_softdevice) { err_code = sd_mbr_command(&com); APP_ERROR_CHECK(err_code); } err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_REGION_START); APP_ERROR_CHECK(err_code); /* Initialize the SoftDevice handler module. See specific board header file */ SOFTDEVICE_HANDLER_INIT(LFCLKSRC_OPTION, NULL); // Enable BLE stack ble_enable_params_t ble_enable_params; memset(&ble_enable_params, 0, sizeof(ble_enable_params)); ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT; err_code = sd_ble_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); }
/**@brief Function for preparing the reset, disabling SoftDevice, and jumping to the bootloader. * * @param[in] conn_handle Connection handle for peer requesting to enter DFU mode. */ static void bootloader_start(uint16_t conn_handle) { uint32_t err_code; uint16_t sys_serv_attr_len = sizeof(m_peer_data.sys_serv_attr); err_code = sd_ble_gatts_sys_attr_get(conn_handle, m_peer_data.sys_serv_attr, &sys_serv_attr_len, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS); if (err_code != NRF_SUCCESS) { // Any error at this stage means the system service attributes could not be fetched. // This means the service changed indication cannot be sent in DFU mode, but connection // is still possible to establish. } m_reset_prepare(); err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_disable(); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_vector_table_base_set(NRF_UICR->BOOTLOADERADDR); APP_ERROR_CHECK(err_code); dfu_app_peer_data_set(conn_handle); NVIC_ClearPendingIRQ(SWI2_IRQn); interrupts_disable(); bootloader_util_app_start(NRF_UICR->BOOTLOADERADDR); }
/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. * * @param[in] init_softdevice true if SoftDevice should be initialized. The SoftDevice must only * be initialized if a chip reset has occured. Soft reset from * application must not reinitialize the SoftDevice. */ static void ble_stack_init(bool init_softdevice) { uint32_t err_code; sd_mbr_command_t com = {SD_MBR_COMMAND_INIT_SD, }; nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; if (init_softdevice) { err_code = sd_mbr_command(&com); APP_ERROR_CHECK(err_code); } err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_REGION_START); APP_ERROR_CHECK(err_code); SOFTDEVICE_HANDLER_APPSH_INIT(&clock_lf_cfg, true); // Enable BLE stack. 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); APP_ERROR_CHECK(err_code); ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT; err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); }
void start_firmware() { void (*fw_start)(void) = *(void (**)(void))(FW_ADDRESS+4); sd_softdevice_vector_table_base_set(FW_ADDRESS); __set_MSP(*(uint32_t*)FW_ADDRESS); fw_start(); while(1); }
/** * @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 = (uint32_t*)VECTORS_FLASH_START; uint32_t i; for (i = 0; i< NVIC_NUM_VECTORS; i++) { nrf_dispatch_vector[i] = old_vectors[i]; } sd_softdevice_vector_table_base_set((uint32_t) nrf_dispatch_vector); }
void bootloader_abort(dfu_end_t end_reason) { __LOG("ABORT...\n"); bl_info_entry_t* p_segment_entry = bootloader_info_entry_get(BL_INFO_TYPE_SEGMENT_APP); switch (end_reason) { case DFU_END_SUCCESS: case DFU_END_ERROR_TIMEOUT: case DFU_END_FWID_VALID: case DFU_END_ERROR_MBR_CALL_FAILED: if (p_segment_entry && dfu_mesh_app_is_valid()) { if (fifo_is_empty(&m_flash_fifo)) { interrupts_disable(); sd_mbr_command_t com = {SD_MBR_COMMAND_INIT_SD, }; uint32_t err_code = sd_mbr_command(&com); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_vector_table_base_set(p_segment_entry->segment.start); APP_ERROR_CHECK(err_code); #ifdef DEBUG_LEDS NRF_GPIO->OUTSET = (1 << 21) | (1 << 22) | (1 << 23) | (1 << 24); #endif bootloader_util_app_start(p_segment_entry->segment.start); } else { __LOG("->Will go to app once flash is finished.\n"); m_go_to_app = true; } } else if (p_segment_entry) { __LOG("->App not valid.\n"); } else { __LOG("->No segment entry found\n"); } break; case DFU_END_ERROR_INVALID_PERSISTENT_STORAGE: APP_ERROR_CHECK_BOOL(false); default: __LOG(RTT_CTRL_TEXT_RED "SYSTEM RESET (reason 0x%x)\n", end_reason); __disable_irq(); while(1); //NVIC_SystemReset(); } }
void bootloader_app_start(uint32_t app_addr) { // If the applications CRC has been checked and passed, the magic number will be written and we // can start the application safely. uint32_t err_code = sd_softdevice_disable(); APP_ERROR_CHECK(err_code); interrupts_disable(); err_code = sd_softdevice_vector_table_base_set(CODE_REGION_1_START); APP_ERROR_CHECK(err_code); bootloader_util_app_start(CODE_REGION_1_START); }
uint32_t nrf_dfu_svci_vector_table_unset(void) { uint32_t err_code; NRF_LOG_INFO("Setting vector table to main app: 0x%08x", APP_START_ADDR); err_code = sd_softdevice_vector_table_base_set(APP_START_ADDR); if (err_code != NRF_SUCCESS) { NRF_LOG_ERROR("Failed running sd_softdevice_vector_table_base_set"); return err_code; } return NRF_SUCCESS; }
/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. * * @param[in] init_softdevice true if SoftDeviceshould be initialized. The SoftDevice must only * be initialized if a chip reset has occured. Soft reset from * application must not reinitialize the SoftDevice. */ static void ble_stack_init(bool init_softdevice) { uint32_t err_code; sd_mbr_command_t com = {SD_MBR_COMMAND_INIT_SD, }; if (init_softdevice) { err_code = sd_mbr_command(&com); APP_ERROR_CHECK(err_code); } err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_REGION_START); APP_ERROR_CHECK(err_code); // TODO: enable if we're on a device with 32kHz xtal /*nrf_clock_lf_cfg_t clock_lf_cfg = { .source = NRF_CLOCK_LF_SRC_XTAL, .rc_ctiv = 0, .rc_temp_ctiv = 0, .xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM};*/ 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}; SOFTDEVICE_HANDLER_APPSH_INIT(&clock_lf_cfg, true); // Enable BLE stack. 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); APP_ERROR_CHECK(err_code); ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT; err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); } /**@brief Function for event scheduler initialization. */ static void scheduler_init(void) { APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); }
/** * @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 }
uint32_t nrf_dfu_svci_vector_table_set(void) { uint32_t err_code; if (NRF_UICR->NRFFW[0] != 0xFFFFFFFF) { NRF_LOG_INFO("Setting vector table to bootloader: 0x%08x", NRF_UICR->NRFFW[0]); err_code = sd_softdevice_vector_table_base_set(NRF_UICR->NRFFW[0]); if (err_code != NRF_SUCCESS) { NRF_LOG_ERROR("Failed running sd_softdevice_vector_table_base_set"); return err_code; } return NRF_SUCCESS; } NRF_LOG_ERROR("No bootloader was found"); return NRF_ERROR_NO_MEM; }
void bootloader_abort(bl_end_t end_reason) { uint32_t app_length = m_bl_info_pointers.p_segment_app->length; if (m_transaction.transaction_id != 0) { app_length = m_transaction.length; } switch (end_reason) { case BL_END_SUCCESS: case BL_END_ERROR_TIMEOUT: case BL_END_FWID_VALID: if (app_is_valid((uint32_t*) m_bl_info_pointers.p_segment_app->start, app_length)) { interrupts_disable(); #ifdef DEBUG_LEDS NRF_GPIO->OUTCLR = (1 << 22); #endif sd_mbr_command_t com = {SD_MBR_COMMAND_INIT_SD, }; volatile uint32_t err_code = sd_mbr_command(&com); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_vector_table_base_set(m_bl_info_pointers.p_segment_app->start); APP_ERROR_CHECK(err_code); #ifdef DEBUG_LEDS NRF_GPIO->OUTSET = (1 << 21); NRF_GPIO->OUTSET = (1 << 22); #endif bootloader_util_app_start(m_bl_info_pointers.p_segment_app->start); } break; case BL_END_ERROR_INVALID_PERSISTENT_STORAGE: APP_ERROR_CHECK_BOOL(false); default: NVIC_SystemReset(); break; } }
/**@brief Function for preparing the reset, disabling SoftDevice and jump to the bootloader. */ static void bootloader_start(void) { m_reset_prepare(); uint32_t err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_disable(); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_vector_table_base_set(NRF_UICR->BOOTLOADERADDR); APP_ERROR_CHECK(err_code); if (m_dm_handle_valid) { dfu_app_set_peer_data(); } NVIC_ClearPendingIRQ(SWI2_IRQn); interrupts_disable(); bootloader_util_app_start(NRF_UICR->BOOTLOADERADDR); }
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); }
/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. * * @param[in] init_softdevice true if SoftDevice should be initialized. The SoftDevice must only * be initialized if a chip reset has occured. Soft reset from * application must not reinitialize the SoftDevice. */ static void ble_stack_init(bool init_softdevice) { uint32_t err_code; sd_mbr_command_t com = {SD_MBR_COMMAND_INIT_SD, }; // Initialize the SoftDevice handler module. nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; // Check if the 32 bit crystal does Exist or Not. if((DFU_DEVICE_INFO->device_type & 0x8000) == 0) { clock_lf_cfg.source = NRF_CLOCK_LF_SRC_RC; clock_lf_cfg.rc_ctiv = 16; clock_lf_cfg.rc_temp_ctiv = 2; } if (init_softdevice) { err_code = sd_mbr_command(&com); APP_ERROR_CHECK(err_code); } err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_REGION_START); APP_ERROR_CHECK(err_code); SOFTDEVICE_HANDLER_APPSH_INIT(&clock_lf_cfg, true); // Enable BLE stack. 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); APP_ERROR_CHECK(err_code); ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT; err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); }
/**@brief Function for preparing the reset, disabling SoftDevice and jump to the bootloader. */ void bootloader_start(void) { m_reset_prepare(); uint32_t err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_disable(); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_vector_table_base_set(NRF_UICR->BOOTLOADERADDR); APP_ERROR_CHECK(err_code); // Commenting out the following block because it brings in unwanted dependencies from bonding. // TODO: discuss this with Nordic. // if (m_dm_handle_valid) // { // dfu_app_set_peer_data(); // } NVIC_ClearPendingIRQ(SWI2_IRQn); interrupts_disable(); bootloader_util_app_start(NRF_UICR->BOOTLOADERADDR); }
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); }
int main() { static char address[5]; sd_mbr_command(&startSdCmd); sd_softdevice_vector_table_base_set(BOOTLOADER_ADDRESS); // If the master boot switch has detected short or no click: boot the firmware if (((NRF_POWER->GPREGRET&0x86U) != 0x82U) && ((NRF_POWER->GPREGRET&0x40U) != 0x40U) && (*(uint32_t *)FW_ADDRESS != 0xFFFFFFFFU) ) { start_firmware(); } if (NRF_POWER->GPREGRET&0x40U) { address[4] = 0xb1; memcpy(&address[0], (char*)&NRF_FICR->DEVICEADDR[0], 4); esbSetAddress(address); } NRF_POWER->GPREGRET &= ~(0x60U); // Enable the radio LNA nrf_gpio_cfg_output(RADIO_PAEN_PIN); nrf_gpio_pin_set(RADIO_PAEN_PIN); // Initialize timer module. APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false); ble_init(); /* NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSTAT_SRC_Synth; NRF_CLOCK->TASKS_LFCLKSTART = 1UL; while(!NRF_CLOCK->EVENTS_LFCLKSTARTED); */ systickInit(); buttonInit(buttonIdle); #ifndef DEBUG_TIMESLOT //sd_ppi_channel_assign(0, &(NRF_TIMER1->EVENTS_COMPARE[0]), &(NRF_GPIOTE->TASKS_OUT[0])); //sd_ppi_channel_enable_set(PPI_CHEN_CH0_Msk); //NRF_PPI->CH[0].EEP = &(NRF_TIMER1->EVENTS_COMPARE[0]); //NRF_PPI->CH[0].TEP = &(NRF_GPIOTE->TASKS_OUT[0]); //NRF_PPI->CHENSET = 1; #endif // Start (or continue) to blink the LED at 0.5Hz //NRF_TIMER1->TASKS_STOP = 1; //NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer; //NRF_TIMER1->PRESCALER = 7; //NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos; //NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Msk; // | TIMER_SHORTS_COMPARE1_CLEAR_Msk; //NRF_TIMER1->TASKS_CLEAR = 1; NRF_TIMER1->CC[0] = 1*SEC; //0x1E84 ; NRF_TIMER1->CC[1] = 2*SEC; nrf_gpio_cfg_output(LED_PIN); nrf_gpiote_task_config(0, LED_PIN, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW); NRF_TIMER1->TASKS_START = 1; // Enable 500mA USB input and enable battery charging nrf_gpio_cfg_output(PM_EN1); nrf_gpio_pin_set(PM_EN1); nrf_gpio_cfg_output(PM_EN2); nrf_gpio_pin_clear(PM_EN2); nrf_gpio_cfg_output(PM_CHG_EN); nrf_gpio_pin_clear(PM_CHG_EN); // Power STM32, hold reset nrf_gpio_cfg_output(PM_VCCEN_PIN); nrf_gpio_pin_set(PM_VCCEN_PIN); nrf_gpio_cfg_output(STM_NRST_PIN); nrf_gpio_pin_clear(STM_NRST_PIN); // Set flow control and activate pull-down on RX data pin nrf_gpio_cfg_output(UART_TX_PIN); nrf_gpio_pin_set(UART_TX_PIN); nrf_gpio_cfg_output(UART_RTS_PIN); nrf_gpio_pin_set(UART_RTS_PIN); nrf_gpio_cfg_input(UART_RX_PIN, NRF_GPIO_PIN_PULLDOWN); nrf_gpio_pin_set(STM_NRST_PIN); //systickInit(); //syslinkInit(); //buttonInit(); // nrf_gpio_cfg_input(BUTTON_PIN, NRF_GPIO_PIN_PULLUP); mainLoop(); while(1); }