From 1676f4b3ad0b43c9b91cb32ebb081aee02792ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=90=AA?= Date: Tue, 28 Jul 2026 17:19:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=AD=E6=80=A7=E5=85=89?= =?UTF-8?q?=E4=B8=8A=E7=94=B5=E7=9E=AC=E6=97=B6=E9=97=AA=E7=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/ble/ble_peripheral/app/src/fmc_spi.c | 15 ++++++++++++--- .../ble_peripheral/app/src/ota_flash_interface.c | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/project/example/ble/ble_peripheral/app/src/fmc_spi.c b/project/example/ble/ble_peripheral/app/src/fmc_spi.c index 96289dc..1fa64e4 100644 --- a/project/example/ble/ble_peripheral/app/src/fmc_spi.c +++ b/project/example/ble/ble_peripheral/app/src/fmc_spi.c @@ -79,7 +79,7 @@ unsigned char get_checksum(unsigned char *ptrdata, unsigned char length) #define FLASH_POWER_CYCLE_INDEX 29U #define FLASH_POWER_MODE_MARK 0xA7U #define POWER_POLICY_SAVE_DELAY_MS 100U -#define POWER_CYCLE_SAVE_DELAY_MS 100U +#define USER_DATA_FLASH_ADDR 0x1E000UL uint8_t power_restore_policy = POWER_RESTORE_CYCLE_STATIC; static uint8_t power_cycle_next_mode; @@ -288,6 +288,15 @@ void power_restore_apply_on_boot(void) power_cycle_next_mode = (uint8_t)((mode_index + 1U) % 3U); - /* Save the next startup mode while power is stable. */ - set_TaskComps_timer(2U, POWER_CYCLE_SAVE_DELAY_MS); + /* + * Save the next startup mode before timers, BLE and the H-bridge start. + * A deferred flash erase/write masks interrupts long enough to stretch + * one Timer3-controlled dual-color pulse and causes a visible flash. + */ + wright_user_data(); + GLOBAL_INT_DISABLE(); + xc_fmc_spi_flash_erase_page(USER_DATA_FLASH_ADDR); + xc_fmc_spi_flash_write_page(USER_DATA_FLASH_ADDR, + app_data, FLASH_PAGE_SIZE); + GLOBAL_INT_RESTORE(); } diff --git a/project/example/ble/ble_peripheral/app/src/ota_flash_interface.c b/project/example/ble/ble_peripheral/app/src/ota_flash_interface.c index d309ed3..84eeeff 100644 --- a/project/example/ble/ble_peripheral/app/src/ota_flash_interface.c +++ b/project/example/ble/ble_peripheral/app/src/ota_flash_interface.c @@ -92,7 +92,7 @@ void ble_flash_handle(void) } } -uint8_t app_data[128] = {0}; +uint8_t app_data[FLASH_PAGE_SIZE] = {0}; //uint16_t app_op_flash_start = 10000; void app_op_flash(void)