Complete the adaptation of LITE version of hardware.

This commit is contained in:
dxl
2023-02-22 11:55:26 +08:00
parent 7311be46a5
commit 9c44ab00b0
11 changed files with 110 additions and 55 deletions
+9
View File
@@ -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)
-26
View File
@@ -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(); // 日志初始化
+3 -2
View File
@@ -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
// <s> APP_USBD_STRINGS_PRODUCT - String descriptor for the product name.
@@ -6551,7 +6552,7 @@
// <i> Note: This value is not editable in Configuration Wizard.
// <i> 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
// </e>
+9
View File
@@ -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)
+13 -8
View File
@@ -47,7 +47,6 @@
*/
#include <stdint.h>
#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();
+7 -6
View File
@@ -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
// </e>
@@ -1067,7 +1068,7 @@
// <i> 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
// <q> NRF_DFU_REQUIRE_SIGNED_APP_UPDATE - Require a valid signature to update the application or SoftDevice.
@@ -1176,7 +1177,7 @@
// <s> 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
// <o> NRF_DFU_BLE_ADV_INTERVAL - Advertising interval (in units of 0.625 ms)
@@ -1546,7 +1547,7 @@
// <i> Setting string to NULL disables that string.
// <i> 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
// </e>
@@ -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
// <s> APP_USBD_STRINGS_PRODUCT - String descriptor for the product name.
@@ -1570,7 +1571,7 @@
// <i> Note: This value is not editable in Configuration Wizard.
// <i> 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
// </e>
@@ -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);
@@ -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"
@@ -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; //<! Observer callback set by the user.
static volatile bool m_flash_write_done;
@@ -89,6 +89,12 @@ NRF_LOG_MODULE_REGISTER();
/** @brief Make USB power value */
#define APP_USBD_POWER_MAKE(ma) (((ma) + 1) / 2)
#ifdef USE_APP_CONFIG
#define BCD_DEVICE_VALUE FW_VER_NUM
#else
#define BCD_DEVICE_VALUE APP_USBD_BCD_VER_MAKE(APP_USBD_DEVICE_VER_MAJOR, APP_USBD_DEVICE_VER_MINOR, APP_USBD_DEVICE_VER_SUB)
#endif
/**
@brief Default device descriptor initializer @ref app_usbd_descriptor_device_t
* */
@@ -102,10 +108,7 @@ NRF_LOG_MODULE_REGISTER();
.bMaxPacketSize0 = NRF_DRV_USBD_EPSIZE, /* endpoint size: fixed to: NRF_DRV_USBD_EPSIZE*/ \
.idVendor = APP_USBD_VID, /* Vendor ID*/ \
.idProduct = APP_USBD_PID, /* Product ID*/ \
.bcdDevice = APP_USBD_BCD_VER_MAKE( /* Device version BCD */ \
APP_USBD_DEVICE_VER_MAJOR, \
APP_USBD_DEVICE_VER_MINOR, \
APP_USBD_DEVICE_VER_SUB), \
.bcdDevice = BCD_DEVICE_VALUE, /* Device version BCD */ \
.iManufacturer = APP_USBD_STRING_ID_MANUFACTURER, /* String ID: manufacturer */ \
.iProduct = APP_USBD_STRING_ID_PRODUCT, /* String ID: product */ \
.iSerialNumber = APP_USBD_STRING_ID_SERIAL, /* String ID: serial */ \
+8 -1
View File
@@ -9,12 +9,19 @@ import chameleon_cmd
import colorama
import chameleon_cli_unit
ULTRA = r"""
"""
LITE = r"""
"""
# create by http://patorjk.com/software/taag/#p=display&f=ANSI%20Shadow&t=Chameleon%20Ultra
BANNER = f"""
@@ -23,7 +30,7 @@ BANNER = f"""
{ULTRA}
"""