diff --git a/firmware/application/src/app_config.h b/firmware/application/src/app_config.h new file mode 100644 index 0000000..a6cea8c --- /dev/null +++ b/firmware/application/src/app_config.h @@ -0,0 +1,9 @@ +#include "device_info.h" + + +// version code, 1byte, max = 0 -> 255 +#define APP_FW_VER_MAJOR 1 +#define APP_FW_VER_MINOR 0 + +// Merge major and minor version code to U16 value. +#define FW_VER_NUM VER_CODE_TO_NUM(APP_FW_VER_MAJOR, APP_FW_VER_MINOR) \ No newline at end of file diff --git a/firmware/application/src/app_main.c b/firmware/application/src/app_main.c index 2106b35..3537722 100644 --- a/firmware/application/src/app_main.c +++ b/firmware/application/src/app_main.c @@ -359,36 +359,10 @@ static void button_press_process(void) { } } -/** - * @brief Function for chameleon lite power controll - */ -void board_nrf52840_high_voltage_set(void) { -#ifdef SOFTDEVICE_PRESENT - sd_power_dcdc_mode_set(NRF_POWER_DCDC_DISABLE); - sd_power_dcdc0_mode_set(NRF_POWER_DCDC_DISABLE); -#else - NRF_POWER->DCDCEN = 0; - NRF_POWER->DCDCEN0 = 0; -#endif - // if the nrf52840_pca10059 board is powered from USB (high voltage mode), GPIO output voltage is set to 1.8 volts by - // default and that is not enough to turn the green and blue LEDs on. Increase GPIO voltage to 3.0 volts. - if (((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) == (UICR_REGOUT0_VOUT_DEFAULT << UICR_REGOUT0_VOUT_Pos))) { - NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; - while (NRF_NVMC->READY == NVMC_READY_READY_Busy); - NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~((uint32_t)UICR_REGOUT0_VOUT_Msk)) | (UICR_REGOUT0_VOUT_3V3 << UICR_REGOUT0_VOUT_Pos); - NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos; - while (NRF_NVMC->READY == NVMC_READY_READY_Busy); - // a reset is required for changes to take effect - NVIC_SystemReset(); - } -} /**@brief Application main function. */ int main(void) { -#if defined(PROJECT_CHAMELEON_LITE) - board_nrf52840_high_voltage_set(); // lite需要关闭dcdc并且抬高内核电压 -#endif hw_connect_init(); // 记得先把引脚初始化一下 log_init(); // 日志初始化 diff --git a/firmware/application/src/sdk_config.h b/firmware/application/src/sdk_config.h index 6761c5b..4fc1783 100644 --- a/firmware/application/src/sdk_config.h +++ b/firmware/application/src/sdk_config.h @@ -43,6 +43,7 @@ #ifndef SDK_CONFIG_H #define SDK_CONFIG_H // <<< Use Configuration Wizard in Context Menu >>>\n +#define USE_APP_CONFIG #ifdef USE_APP_CONFIG #include "app_config.h" #endif @@ -6543,7 +6544,7 @@ #ifndef APP_USBD_STRINGS_PRODUCT_EXTERN -#define APP_USBD_STRINGS_PRODUCT_EXTERN 0 +#define APP_USBD_STRINGS_PRODUCT_EXTERN 1 #endif // APP_USBD_STRINGS_PRODUCT - String descriptor for the product name. @@ -6551,7 +6552,7 @@ // Note: This value is not editable in Configuration Wizard. // List of product names that is defined the same way like in @ref APP_USBD_STRINGS_MANUFACTURER. #ifndef APP_USBD_STRINGS_PRODUCT -#define APP_USBD_STRINGS_PRODUCT APP_USBD_STRING_DESC("Chameleon nRF52") +#define APP_USBD_STRINGS_PRODUCT g_extern_product_str #endif // diff --git a/firmware/bootloader/src/app_config.h b/firmware/bootloader/src/app_config.h new file mode 100644 index 0000000..7ab4f64 --- /dev/null +++ b/firmware/bootloader/src/app_config.h @@ -0,0 +1,9 @@ +#include "device_info.h" + + +// version code, 1byte, max = 0 -> 255 +#define BOOT_FW_VER_MAJOR 1 +#define BOOT_FW_VER_MINOR 0 + +// Merge major and minor version code to U16 value. +#define FW_VER_NUM VER_CODE_TO_NUM(BOOT_FW_VER_MAJOR, BOOT_FW_VER_MINOR) \ No newline at end of file diff --git a/firmware/bootloader/src/main.c b/firmware/bootloader/src/main.c index b557850..106c321 100644 --- a/firmware/bootloader/src/main.c +++ b/firmware/bootloader/src/main.c @@ -47,7 +47,6 @@ */ #include -#include "boards.h" #include "nrf_mbr.h" #include "nrf_bootloader.h" #include "nrf_bootloader_app_start.h" @@ -62,6 +61,8 @@ #include "nrf_delay.h" #include "app_scheduler.h" #include "nrfx_systick.h" +#include "nrf_gpio.h" +#include "hw_connect.h" static void on_error(void) @@ -104,8 +105,9 @@ static uint8_t m_led_flash_state = 0; static bool m_led_flash_setp = 0; static nrfx_systick_state_t systick; void flash_led(void *p_event_data, uint16_t event_size) { - bsp_board_leds_off(); - bsp_set_led_color(m_led_flash_state); + nrf_gpio_pin_clear(LED_5); + nrf_gpio_pin_clear(LED_4); + set_slot_light_color(m_led_flash_state); int led_flash_speed; switch (m_led_flash_state) @@ -123,18 +125,18 @@ void flash_led(void *p_event_data, uint16_t event_size) { } if (m_led_flash_setp == 0) { - bsp_board_led_on(BSP_BOARD_LED_3); + nrf_gpio_pin_set(LED_4); if (nrfx_systick_test(&systick, led_flash_speed)) { m_led_flash_setp = 1; nrfx_systick_get(&systick); - bsp_board_led_off(BSP_BOARD_LED_3); + nrf_gpio_pin_clear(LED_5); } } else { - bsp_board_led_on(BSP_BOARD_LED_4); + nrf_gpio_pin_set(LED_5); if (nrfx_systick_test(&systick, led_flash_speed)) { m_led_flash_setp = 0; nrfx_systick_get(&systick); - bsp_board_led_off(BSP_BOARD_LED_4); + nrf_gpio_pin_clear(LED_4); } } @@ -151,7 +153,6 @@ static void dfu_observer(nrf_dfu_evt_type_t evt_type) { case NRF_DFU_EVT_DFU_INITIALIZED: nrfx_systick_init(); - bsp_board_init(BSP_INIT_LEDS); m_led_flash_state = 0; m_led_flash_setp = 0; nrfx_systick_get(&systick); @@ -184,6 +185,10 @@ int main(void) { uint32_t ret_val; + // Must to init hardware connect. + hw_connect_init(); + init_leds(); + // Must happen before flash protection is applied, since it edits a protected page. nrf_bootloader_mbr_addrs_populate(); diff --git a/firmware/bootloader/src/sdk_config.h b/firmware/bootloader/src/sdk_config.h index 6f6eb9e..5d015d3 100644 --- a/firmware/bootloader/src/sdk_config.h +++ b/firmware/bootloader/src/sdk_config.h @@ -43,6 +43,7 @@ #ifndef SDK_CONFIG_H #define SDK_CONFIG_H // <<< Use Configuration Wizard in Context Menu >>>\n +#define USE_APP_CONFIG #ifdef USE_APP_CONFIG #include "app_config.h" #endif @@ -153,7 +154,7 @@ // <47=> 47 (P1.15) #ifndef NRF_BL_DFU_ENTER_METHOD_BUTTON_PIN -#define NRF_BL_DFU_ENTER_METHOD_BUTTON_PIN 26 +#define NRF_BL_DFU_ENTER_METHOD_BUTTON_PIN BUTTON_1 #endif // @@ -1067,7 +1068,7 @@ // It is checked against the hw_version value in the init packet #ifndef NRF_DFU_HW_VERSION -#define NRF_DFU_HW_VERSION 52 +#define NRF_DFU_HW_VERSION hw_get_device_type() #endif // NRF_DFU_REQUIRE_SIGNED_APP_UPDATE - Require a valid signature to update the application or SoftDevice. @@ -1176,7 +1177,7 @@ // NRF_DFU_BLE_ADV_NAME - Default advertising name. #ifndef NRF_DFU_BLE_ADV_NAME -#define NRF_DFU_BLE_ADV_NAME "DfuTarg" +#define NRF_DFU_BLE_ADV_NAME DEVICE_NAME_STR_SHORT #endif // NRF_DFU_BLE_ADV_INTERVAL - Advertising interval (in units of 0.625 ms) @@ -1546,7 +1547,7 @@ // Setting string to NULL disables that string. // The order of manufacturer names must be the same like in @ref APP_USBD_STRINGS_LANGIDS. #ifndef APP_USBD_STRINGS_MANUFACTURER -#define APP_USBD_STRINGS_MANUFACTURER APP_USBD_STRING_DESC("Nordic Semiconductor") +#define APP_USBD_STRINGS_MANUFACTURER APP_USBD_STRING_DESC("Proxgrind") #endif // @@ -1562,7 +1563,7 @@ #ifndef APP_USBD_STRINGS_PRODUCT_EXTERN -#define APP_USBD_STRINGS_PRODUCT_EXTERN 0 +#define APP_USBD_STRINGS_PRODUCT_EXTERN 1 #endif // APP_USBD_STRINGS_PRODUCT - String descriptor for the product name. @@ -1570,7 +1571,7 @@ // Note: This value is not editable in Configuration Wizard. // List of product names that is defined the same way like in @ref APP_USBD_STRINGS_MANUFACTURER. #ifndef APP_USBD_STRINGS_PRODUCT -#define APP_USBD_STRINGS_PRODUCT APP_USBD_STRING_DESC("Secure DFU Bootloader") +#define APP_USBD_STRINGS_PRODUCT g_extern_product_str #endif // diff --git a/resource/nrf52_sdk/components/libraries/bootloader/ble_dfu/nrf_dfu_ble.c b/resource/nrf52_sdk/components/libraries/bootloader/ble_dfu/nrf_dfu_ble.c index a2fdf5e..b61c0c3 100644 --- a/resource/nrf52_sdk/components/libraries/bootloader/ble_dfu/nrf_dfu_ble.c +++ b/resource/nrf52_sdk/components/libraries/bootloader/ble_dfu/nrf_dfu_ble.c @@ -57,6 +57,7 @@ #include "nrf_delay.h" #include "nrf_dfu_settings.h" #include "nrf_dfu_ble.h" +#include "hw_connect.h" #define NRF_LOG_MODULE_NAME nrf_dfu_ble #include "nrf_log.h" @@ -167,19 +168,54 @@ static uint32_t advertising_init(uint8_t adv_flags, ble_gap_adv_params_t const * m_enc_advdata[5] = LSB_16(BLE_DFU_SERVICE_UUID); m_enc_advdata[6] = MSB_16(BLE_DFU_SERVICE_UUID); - /* Get GAP device name and length. */ + + // Get GAP device name and length. err_code = sd_ble_gap_device_name_get(&m_enc_advdata[9], &actual_device_name_length); if (err_code != NRF_SUCCESS) { return err_code; } - // Set GAP device in advertising data. m_enc_advdata[7] = actual_device_name_length + 1; // (actual_length + ADV_AD_TYPE_FIELD_SIZE(1)) m_enc_advdata[8] = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME; - m_adv_data.adv_data.len += actual_device_name_length; + + // Add device information to adv data + ble_gap_addr_t addr; + err_code = sd_ble_gap_addr_get(&addr); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + m_enc_advdata[m_adv_data.adv_data.len] = 13; // length + m_adv_data.adv_data.len += 1; + m_enc_advdata[m_adv_data.adv_data.len] = BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA; + m_adv_data.adv_data.len += 1; + m_enc_advdata[m_adv_data.adv_data.len] = 0xFF; + m_adv_data.adv_data.len += 1; + m_enc_advdata[m_adv_data.adv_data.len] = 0xFF; + m_adv_data.adv_data.len += 1; + + addr.addr[0] -= 1; + for (int i = 0, j = sizeof(addr.addr) - 1; i < sizeof(addr.addr) / 2; i++, j--) { + uint8_t tmp = addr.addr[i]; + addr.addr[i] = addr.addr[j]; + addr.addr[j] = tmp; + } + memcpy(&m_enc_advdata[m_adv_data.adv_data.len], addr.addr, sizeof(addr.addr)); + + + m_adv_data.adv_data.len += sizeof(addr.addr); + m_enc_advdata[m_adv_data.adv_data.len] = hw_get_device_type(); + m_adv_data.adv_data.len += 1; + m_enc_advdata[m_adv_data.adv_data.len] = hw_get_version_code(); + m_adv_data.adv_data.len += 1; + m_enc_advdata[m_adv_data.adv_data.len] = (FW_VER_NUM >> 8) & 0xFF; + m_adv_data.adv_data.len += 1; + m_enc_advdata[m_adv_data.adv_data.len] = FW_VER_NUM & 0xFF; + m_adv_data.adv_data.len += 1; + return sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, p_adv_params); } @@ -923,13 +959,13 @@ static uint32_t gap_params_init(void) { uint32_t err_code; ble_gap_conn_sec_mode_t sec_mode; - uint8_t const * device_name; + uint8_t* device_name; uint32_t name_len; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); #if (!NRF_DFU_BLE_REQUIRES_BONDS) - + unsigned char name_array[sizeof(NRF_DFU_BLE_ADV_NAME) + sizeof("-FFFF") + 1]; err_code = gap_address_change(); VERIFY_SUCCESS(err_code); @@ -943,8 +979,15 @@ static uint32_t gap_params_init(void) #endif { NRF_LOG_DEBUG("Using default advertising name"); - device_name = (uint8_t const *)(NRF_DFU_BLE_ADV_NAME); - name_len = strlen(NRF_DFU_BLE_ADV_NAME); + + ble_gap_addr_t addr; + err_code = sd_ble_gap_addr_get(&addr); + VERIFY_SUCCESS(err_code); + addr.addr[0] -= 1; + name_len = sprintf((char*)name_array, "%s-%02X%02X", NRF_DFU_BLE_ADV_NAME, addr.addr[1], addr.addr[0]); + device_name = (unsigned char*)name_array; + // device_name = (uint8_t const *)(NRF_DFU_BLE_ADV_NAME); + // name_len = strlen(NRF_DFU_BLE_ADV_NAME); } err_code = sd_ble_gap_device_name_set(&sec_mode, device_name, name_len); diff --git a/resource/nrf52_sdk/components/libraries/bootloader/dfu/nrf_dfu_ver_validation.c b/resource/nrf52_sdk/components/libraries/bootloader/dfu/nrf_dfu_ver_validation.c index f9e369d..a6c4a6e 100644 --- a/resource/nrf52_sdk/components/libraries/bootloader/dfu/nrf_dfu_ver_validation.c +++ b/resource/nrf52_sdk/components/libraries/bootloader/dfu/nrf_dfu_ver_validation.c @@ -46,6 +46,7 @@ #include "nrf_assert.h" #include "dfu-cc.pb.h" #include "nrf_dfu_ver_validation.h" +#include "hw_connect.h" #define NRF_LOG_MODULE_NAME nrf_dfu_ver_validation #include "nrf_log.h" diff --git a/resource/nrf52_sdk/components/libraries/bootloader/nrf_bootloader.c b/resource/nrf52_sdk/components/libraries/bootloader/nrf_bootloader.c index 09d7d55..f284aee 100644 --- a/resource/nrf52_sdk/components/libraries/bootloader/nrf_bootloader.c +++ b/resource/nrf52_sdk/components/libraries/bootloader/nrf_bootloader.c @@ -41,7 +41,6 @@ #include "compiler_abstraction.h" #include "nrf.h" -#include "boards.h" #include "sdk_config.h" #include "nrf_power.h" #include "nrfx_power.h" @@ -59,6 +58,9 @@ #include "nrf_bootloader_dfu_timers.h" #include "app_scheduler.h" #include "nrf_dfu_validation.h" +#include "nrf_gpio.h" +#include "hw_connect.h" + static nrf_dfu_observer_t m_user_observer; //