/**@brief Function for bootloader main entry. */ int main(void) { uint32_t err_code; bool dfu_start = false; bool app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START); // This check ensures that the defined fields in the bootloader corresponds with actual // setting in the nRF51 chip. APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE); // Initialize. timers_init(); gpiote_init(); buttons_init(); bootloader_init(); // Check if we reset in the middle of a firmware update if (bootloader_dfu_sd_in_progress()) { err_code = bootloader_dfu_sd_update_continue(); APP_ERROR_CHECK(err_code); softdevice_init(!app_reset); scheduler_init(); err_code = bootloader_dfu_sd_update_finalize(); APP_ERROR_CHECK(err_code); } else { // If stack is present then continue initialization of bootloader. softdevice_init(!app_reset); scheduler_init(); } // Check if the Bootloader Control pin is low. If so, enter the bootloader // mode. dfu_start = (nrf_gpio_pin_read(BOOTLOADER_CTRL_PIN) == 0); // If the Bootloader Control pin is low or the application in the flash // is not valid, enter the bootloader mode. if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) { err_code = sd_power_gpregret_clr(POWER_GPREGRET_GPREGRET_Msk); APP_ERROR_CHECK(err_code); // Initiate an update of the firmware. err_code = bootloader_dfu_start(); APP_ERROR_CHECK(err_code); } // If the application was or now is valid, run it if (bootloader_app_is_valid(DFU_BANK_0_REGION_START)) { // Select a bank region to use as application region. // @note: Only applications running from DFU_BANK_0_REGION_START is supported. bootloader_app_start(DFU_BANK_0_REGION_START); } NVIC_SystemReset(); }
int main(void){ softdevice_init(); gap_params_init(); advertising_init(); // start fast advertisement ble_advertising_start(BLE_ADV_MODE_FAST); // setup led gpio in output mode NRF_GPIO->PIN_CNF[GREEN_LED_PIN] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); do{ // set to 1 led gpio (bit 12 corresponding to pin 12) NRF_GPIO->OUTSET = (1UL << GREEN_LED_PIN); // wait 300ms nrf_delay_ms(300); // set to 0 led gpio (bit 12 corresponding to pin 12) NRF_GPIO->OUTCLR = (1UL << GREEN_LED_PIN); // wait 300ms nrf_delay_ms(300); }while(1); //infinite loop return 0; }
int main(void){ softdevice_init(); gap_params_init(); _led.set_led_value = led_set_cb; ble_led_init(&_led); led_init(); advertising_init(); // start fast advertisement ble_advertising_start(BLE_ADV_MODE_FAST); do{ // set to 1 led gpio (bit 12 corresponding to pin 12) // NRF_GPIO->OUTSET = (1UL << GREEN_LED_PIN); // wait 300ms nrf_delay_ms(300); // set to 0 led gpio (bit 12 corresponding to pin 12) // NRF_GPIO->OUTCLR = (1UL << GREEN_LED_PIN); // wait 300ms nrf_delay_ms(300); }while(1); //infinite loop return 0; }
int main(void) { #if defined(NSEC_HARDCODED_BLE_DEVICE_ID) sprintf(g_device_id, "%.8s", NSEC_STRINGIFY(NSEC_HARDCODED_BLE_DEVICE_ID)); #else sprintf(g_device_id, "NSEC%04X", (uint16_t)(NRF_FICR->DEVICEID[1] % 0xFFFF)); #endif g_device_id[9] = '\0'; #ifdef NSEC_CTF_ADD_FLAGS static volatile char flag1[] = "FLAG-60309301fa5b4a4e990392ead6ac7b5f"; printf("%s", flag1); // Don't optimize out flag1 rot13(); #endif /* * Initialize base hardware */ log_init(); power_init(); softdevice_init(); timer_init(); init_WS2812FX(); ssd1306_init(); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); nsec_buttons_init(); /* * Initialize bluetooth stack */ create_ble_device(g_device_id); configure_advertising(); nsec_led_ble_init(); init_identity_service(); start_advertising(); nsec_battery_manager_init(); nsec_status_bar_init(); nsec_status_set_name(g_device_id); nsec_status_set_badge_class(NSEC_STRINGIFY(NSEC_HARDCODED_BADGE_CLASS)); nsec_status_set_ble_status(STATUS_BLUETOOTH_ON); load_stored_led_settings(); nsec_intro(); show_main_menu(); /* * Main loop */ while(true) { service_WS2812FX(); nsec_storage_update(); power_manage(); } return 0; }