Compare commits
2 Commits
1f82b8bc3a
...
39cf6068f7
| Author | SHA1 | Date | |
|---|---|---|---|
| 39cf6068f7 | |||
| 0d719751c4 |
@@ -64,6 +64,7 @@ static volatile bool m_flash_write_done;
|
||||
|
||||
#define SCHED_QUEUE_SIZE 32 /**< Maximum number of events in the scheduler queue. */
|
||||
#define SCHED_EVENT_DATA_SIZE NRF_DFU_SCHED_EVENT_DATA_SIZE /**< Maximum app_scheduler event size. */
|
||||
#define POST_DFU_APP_BOOT_GPREGRET2_MASK 0x02U
|
||||
|
||||
#if !(defined(NRF_BL_DFU_ENTER_METHOD_BUTTON) && \
|
||||
defined(NRF_BL_DFU_ENTER_METHOD_PINRESET) && \
|
||||
@@ -470,6 +471,7 @@ ret_code_t nrf_bootloader_init(nrf_dfu_observer_t observer)
|
||||
break;
|
||||
|
||||
case ACTIVATION_SUCCESS:
|
||||
nrf_power_gpregret2_set(nrf_power_gpregret2_get() | POST_DFU_APP_BOOT_GPREGRET2_MASK);
|
||||
bootloader_reset(true);
|
||||
NRF_LOG_ERROR("Unreachable");
|
||||
return NRF_ERROR_INTERNAL; // Should not reach this.
|
||||
|
||||
@@ -181,6 +181,7 @@
|
||||
#define POWER_OFF_DELAY 3000 /* Power-off delay: 3s after LED indication */
|
||||
#define POWER_RESET_DELAY 2000 /* Reset delay: 2s */
|
||||
#define LED_NUM 24 /* LED pin number */
|
||||
#define POST_DFU_APP_BOOT_GPREGRET2_MASK 0x02U /* Bootloader marker after DFU activation */
|
||||
|
||||
/*==============================================================================
|
||||
* BLE Instances (statically allocated via SoftDevice macros)
|
||||
@@ -230,7 +231,7 @@ static char * roles_str[] = {"INVALID_ROLE", "CENTRAL", "PERIPHERAL"};
|
||||
|
||||
/*==============================================================================
|
||||
* Global Variables
|
||||
* IEC 62304 §5.5.3: all global buffers zero-initialized for deterministic startup
|
||||
* IEC 62304 5.5.3: all global buffers zero-initialized for deterministic startup
|
||||
*============================================================================*/
|
||||
volatile uint8_t Sj_type; /* Command type identifier */
|
||||
bool power_off_duble_prohibit = false; /* Power-off double prevention flag */
|
||||
@@ -1545,7 +1546,7 @@ static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
|
||||
DBG_PRINTF("[BLE] Connected\r\n");
|
||||
|
||||
#if BLE_DEV_MODE
|
||||
/* Dev: no passkey/SEC — allow NUS TX/RX as soon as GAP is up (prod uses PM_EVT_CONN_SEC_SUCCEEDED). */
|
||||
/* Dev: no passkey/SEC - allow NUS TX/RX as soon as GAP is up (prod uses PM_EVT_CONN_SEC_SUCCEEDED). */
|
||||
ble_connection_st = BLE_CONNECTED_ST;
|
||||
battery_timer_start();
|
||||
#endif
|
||||
@@ -2076,6 +2077,7 @@ static void main_s(void * p_context)
|
||||
|
||||
bool button_released = nrf_gpio_pin_read(POWER_BUTTON);
|
||||
|
||||
|
||||
/* ---- Running phase: post-boot button polling ---- */
|
||||
if (booted)
|
||||
{
|
||||
@@ -2120,7 +2122,7 @@ static void main_s(void * p_context)
|
||||
go_device_power_off = true;
|
||||
main_timer_start();
|
||||
}
|
||||
else if (cnt_s > 250 || (m_reset_status == 2)) /* 250 x 5ms = 1.25s + α */
|
||||
else if (cnt_s > 250 || (m_reset_status == 2)) /* 250 x 5ms = 1.25s + ¥á */
|
||||
{
|
||||
DBG_PRINTF("[BTN] Boot (cnt=%d)\r\n", cnt_s);
|
||||
device_reset = false;
|
||||
@@ -2149,7 +2151,7 @@ static void main_s(void * p_context)
|
||||
cnt_s++;
|
||||
device_reset = false;
|
||||
|
||||
if (cnt_s == 250) /* 250 x 5ms = 1.25s + α */
|
||||
if (cnt_s == 250) /* 250 x 5ms = 1.25s + ¥á */
|
||||
{
|
||||
led_set_state(LED_STATE_POWER_ON);
|
||||
DBG_PRINTF("[BTN] 2.0s\r\n");
|
||||
@@ -2170,7 +2172,7 @@ int main(void)
|
||||
{
|
||||
bool erase_bonds_local = false;
|
||||
|
||||
/*──────────────────────────────────────────────────────────────
|
||||
/*--------------------------------------------------------------------------
|
||||
* Phase 1: Basic hardware init (BLE-independent)
|
||||
*
|
||||
* - Power self-latch (P0.8 HIGH)
|
||||
@@ -2179,9 +2181,20 @@ int main(void)
|
||||
* - App timers (power polling, battery, main loop)
|
||||
* - Default config (serial number, passkey)
|
||||
* - Buttons/LEDs
|
||||
*────────────────────────────────────────────────────────────*/
|
||||
*--------------------------------------------------------------------------*/
|
||||
power_hold_init();
|
||||
|
||||
if ((NRF_POWER->GPREGRET2 & POST_DFU_APP_BOOT_GPREGRET2_MASK) != 0)
|
||||
{
|
||||
NRF_POWER->GPREGRET2 &= ~POST_DFU_APP_BOOT_GPREGRET2_MASK;
|
||||
NRF_P0->OUTCLR = (1UL << 8);
|
||||
NRF_P0->DIRSET = (1UL << 8);
|
||||
while (true)
|
||||
{
|
||||
__WFE();
|
||||
}
|
||||
}
|
||||
|
||||
if (power_off_duble_prohibit)
|
||||
{
|
||||
return 0;
|
||||
@@ -2191,7 +2204,7 @@ int main(void)
|
||||
log_init();
|
||||
|
||||
DBG_PRINTF("\r\n========================================\r\n");
|
||||
DBG_PRINTF(" Medithings v1.17\r\n");
|
||||
DBG_PRINTF(" Medithings VesiScan-Basic\r\n");
|
||||
DBG_PRINTF("========================================\r\n");
|
||||
|
||||
DBG_PRINTF("[1] HW Init\r\n");
|
||||
@@ -2205,33 +2218,33 @@ int main(void)
|
||||
#endif
|
||||
DBG_PRINTF(" gpio/timer/config/btn OK\r\n");
|
||||
|
||||
/*──────────────────────────────────────────────────────────────
|
||||
/*--------------------------------------------------------------------------
|
||||
* Phase 2: BLE stack init
|
||||
*
|
||||
* - Power management module (WFE/sleep when idle)
|
||||
* - SoftDevice S140 (BLE 5.0 protocol stack)
|
||||
* - DC-DC converter enable (required after SoftDevice)
|
||||
*────────────────────────────────────────────────────────────*/
|
||||
*--------------------------------------------------------------------------*/
|
||||
DBG_PRINTF("[2] BLE Stack\r\n");
|
||||
power_management_init();
|
||||
ble_stack_init();
|
||||
APP_ERROR_CHECK(sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE));
|
||||
DBG_PRINTF(" pwr/stack/dcdc OK\r\n");
|
||||
|
||||
/*──────────────────────────────────────────────────────────────
|
||||
/*--------------------------------------------------------------------------
|
||||
* Phase 3: Internal flash config (must init after BLE stack)
|
||||
*
|
||||
* - FDS (Flash Data Storage) init
|
||||
* - Read stored config from flash (serial, passkey, piezo, etc.)
|
||||
* - Overwrite defaults with flash values
|
||||
*────────────────────────────────────────────────────────────*/
|
||||
*--------------------------------------------------------------------------*/
|
||||
DBG_PRINTF("[3] FDS\r\n");
|
||||
fs_storage_init();
|
||||
config_load();
|
||||
load_flash_config();
|
||||
DBG_PRINTF(" fds OK\r\n");
|
||||
|
||||
/*──────────────────────────────────────────────────────────────
|
||||
/*--------------------------------------------------------------------------
|
||||
* Phase 4: BLE protocol setup
|
||||
*
|
||||
* - GAP: device name (serial number), connection params, passkey
|
||||
@@ -2240,7 +2253,7 @@ int main(void)
|
||||
* - Advertising: advertising data (name, UUID)
|
||||
* - Connection parameter negotiation module
|
||||
* - Security: Peer Manager (bonding/passkey)
|
||||
*────────────────────────────────────────────────────────────*/
|
||||
*--------------------------------------------------------------------------*/
|
||||
DBG_PRINTF("[4] BLE Protocol\r\n");
|
||||
gap_params_init();
|
||||
gatt_init();
|
||||
@@ -2275,14 +2288,14 @@ int main(void)
|
||||
DBG_PRINTF(" fds defaults saved\r\n");
|
||||
}
|
||||
|
||||
/*──────────────────────────────────────────────────────────────
|
||||
/*--------------------------------------------------------------------------
|
||||
* Phase 5: Application init
|
||||
*
|
||||
* - Command parser: process BLE received commands (log, BLE TX, CRC)
|
||||
* - Piezo driver: GPIO/Timer/PPI setup for ultrasound measurement
|
||||
* - IMU (ICM42670P) is NOT initialized here
|
||||
* -> imu_read_direct() self-configures/reads/sleeps on each msp? command
|
||||
*────────────────────────────────────────────────────────────*/
|
||||
*--------------------------------------------------------------------------*/
|
||||
DBG_PRINTF("[5] App\r\n");
|
||||
g_plat.log = log_printf;
|
||||
g_plat.tx_bin = dr_binary_tx_safe;
|
||||
@@ -2292,9 +2305,9 @@ int main(void)
|
||||
dr_piezo_init();
|
||||
DBG_PRINTF(" parser/piezo OK\r\n");
|
||||
|
||||
/*──────────────────────────────────────────────────────────────
|
||||
/*--------------------------------------------------------------------------
|
||||
* Boot complete -> start power button state machine
|
||||
*────────────────────────────────────────────────────────────*/
|
||||
*--------------------------------------------------------------------------*/
|
||||
DBG_PRINTF("\r\n========================================\r\n");
|
||||
DBG_PRINTF(" READY [%s]\r\n", SERIAL_NO);
|
||||
DBG_PRINTF("========================================\r\n\r\n");
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
* : Unify both IMU direct-read and FIFO outputs as raw data in datasheet axis convention.
|
||||
* - VBTFW0120 260615 jhChun : Add EMC mitigation logic for BLE link stability: extended supervision timeout and dynamic TX power control based on RSSI, RSSI silence, HVN latency, and TX queue congestion.
|
||||
------------------------------------------------------------------------- */
|
||||
#define FIRMWARE_VERSION "VBTFW0129"
|
||||
#define FIRMWARE_VERSION "VBTFW0120"
|
||||
|
||||
/*==============================================================================
|
||||
* Data Length Constants
|
||||
|
||||
+11
@@ -32,6 +32,8 @@ NOTICE: This file has been modified by Nordic Semiconductor ASA.
|
||||
#include "system_nrf52_approtect.h"
|
||||
|
||||
#define __SYSTEM_CLOCK_64M (64000000UL)
|
||||
#define POWER_HOLD_PIN 8UL
|
||||
#define POWER_HOLD_PIN_MASK (1UL << POWER_HOLD_PIN)
|
||||
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
@@ -89,6 +91,15 @@ void SystemCoreClockUpdate(void)
|
||||
|
||||
void SystemInit(void)
|
||||
{
|
||||
/* Keep the external power latch asserted immediately after reset. */
|
||||
NRF_P0->OUTSET = POWER_HOLD_PIN_MASK;
|
||||
NRF_P0->DIRSET = POWER_HOLD_PIN_MASK;
|
||||
NRF_P0->PIN_CNF[POWER_HOLD_PIN] =
|
||||
(GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos) |
|
||||
(GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) |
|
||||
(GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) |
|
||||
(GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) |
|
||||
(GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
/* Enable SWO trace functionality. If ENABLE_SWO is not defined, SWO pin will be used as GPIO (see Product
|
||||
Specification to see which one). */
|
||||
#if defined (ENABLE_SWO) && defined(CLOCK_TRACECONFIG_TRACEMUX_Pos)
|
||||
|
||||
@@ -76,6 +76,8 @@ static void dfu_observer(nrf_dfu_evt_type_t evt_type)
|
||||
break;
|
||||
case NRF_DFU_EVT_DFU_STARTED:
|
||||
break;
|
||||
case NRF_DFU_EVT_DFU_COMPLETED:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
+11
@@ -32,6 +32,8 @@ NOTICE: This file has been modified by Nordic Semiconductor ASA.
|
||||
#include "system_nrf52_approtect.h"
|
||||
|
||||
#define __SYSTEM_CLOCK_64M (64000000UL)
|
||||
#define POWER_HOLD_PIN 8UL
|
||||
#define POWER_HOLD_PIN_MASK (1UL << POWER_HOLD_PIN)
|
||||
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
@@ -89,6 +91,15 @@ void SystemCoreClockUpdate(void)
|
||||
|
||||
void SystemInit(void)
|
||||
{
|
||||
/* Keep the external power latch asserted immediately after reset. */
|
||||
NRF_P0->OUTSET = POWER_HOLD_PIN_MASK;
|
||||
NRF_P0->DIRSET = POWER_HOLD_PIN_MASK;
|
||||
NRF_P0->PIN_CNF[POWER_HOLD_PIN] =
|
||||
(GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos) |
|
||||
(GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) |
|
||||
(GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) |
|
||||
(GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) |
|
||||
(GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
|
||||
/* Enable SWO trace functionality. If ENABLE_SWO is not defined, SWO pin will be used as GPIO (see Product
|
||||
Specification to see which one). */
|
||||
#if defined (ENABLE_SWO) && defined(CLOCK_TRACECONFIG_TRACEMUX_Pos)
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@
|
||||
<LExpSel>0</LExpSel>
|
||||
</OPTXL>
|
||||
<OPTFL>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
|
||||
Reference in New Issue
Block a user