Files
STM8_Mesh_Control/STM8_Bootloader/include/bootloader_config.h
T
十七 ebef6a8694 feat: complete assembly mesh relay control path
- synchronize STM8 application and external flash layout updates\n- add assembly bootloader and assembly application test projects\n- add UART1 interrupt receive ring buffer\n- parse JDY-28M Mesh outer frames and source addresses\n- add CRC-16/MODBUS validation\n- implement relay control command 0x01 and response 0x81\n- support unicast and broadcast relay control frames\n- update host protocol, OTA documents, and serial tools
2026-11-05 16:12:51 +08:00

60 lines
2.6 KiB
C

/**
* @file bootloader_config.h
* @brief Bootloader 的固定地址和安全策略配置。
*/
#ifndef STM8_BOOTLOADER_CONFIG_H
#define STM8_BOOTLOADER_CONFIG_H
#include <stdint.h>
/** Bootloader 在 STM8 程序 Flash 中的起始地址。 */
#define BOOTLOADER_START_ADDRESS 0x8000u
/** Bootloader 预留空间,当前规划为 1KB。 */
#define BOOTLOADER_SIZE_BYTES 0x0500u
/** 应用程序固定入口地址,必须与应用工程链接地址一致。 */
#define APPLICATION_START_ADDRESS 0x8500u
/** STM8S003F3P6 程序 Flash 的最后一个地址。 */
#define APPLICATION_END_ADDRESS 0x9FFFu
/** 应用程序允许使用的最大空间。 */
#define APPLICATION_MAX_SIZE_BYTES \
(APPLICATION_END_ADDRESS - APPLICATION_START_ADDRESS + 1u)
/** W25Q80BV中保存出厂固件镜像的固定地址,预留8KiB。 */
#define FACTORY_IMAGE_ADDRESS 0x000000ul
/** W25Q80BV中保存出厂固件元数据的固定地址,独占4KiB扇区。 */
#define FACTORY_METADATA_ADDRESS 0x002000ul
/** W25Q80BV中保存OTA升级固件的固定地址,预留8KiB。 */
#define OTA_IMAGE_ADDRESS 0x003000ul
/** W25Q80BV中保存OTA元数据的固定地址,独占4KiB扇区。 */
#define OTA_METADATA_ADDRESS 0x005000ul
/** 升级元数据魔数,用于避免误把普通数据当成升级请求。 */
#define OTA_METADATA_MAGIC 0x4F544131ul
/** 出厂恢复镜像元数据魔数。 */
#define FACTORY_METADATA_MAGIC 0x46414331ul
/* 元数据字段相对于各自元数据扇区起始地址的固定偏移。 */
#define METADATA_MAGIC_OFFSET 0x00u
#define METADATA_IMAGE_SIZE_OFFSET 0x04u
#define METADATA_VERSION_OFFSET 0x08u
#define METADATA_CRC16_OFFSET 0x0Au
#define METADATA_IMAGE_VALID_OFFSET 0x0Eu
#define METADATA_UPGRADE_REQUEST_OFFSET 0x0Fu
#define METADATA_UPGRADE_RESULT_OFFSET 0x10u
/** 镜像已经完整写入并通过校验时使用的有效标志。 */
#define METADATA_IMAGE_VALID_VALUE 0xA5u
/** 应用程序有效标记,避免把空白 Flash 当作可执行程序。 */
#define APPLICATION_FIRST_BYTE_INVALID 0x00u
#define APPLICATION_FIRST_BYTE_ERASED 0xFFu
/** Bootloader 看门狗刷新周期,必须小于硬件看门狗超时时间。 */
#define BOOTLOADER_WATCHDOG_REFRESH_LOOP 20000u
/** 上电恢复按键判定时间,单位为毫秒。 */
#define FACTORY_BUTTON_HOLD_TIME_MS 5000u
/** Bootloader忙等待1ms的循环次数,需结合实际系统时钟校准。 */
#define BOOTLOADER_DELAY_1MS_LOOPS 1200u
/** 内部Flash单次擦写等待的最大循环次数,超时即判定操作失败。 */
#define BOOTLOADER_FLASH_WAIT_TIMEOUT 60000ul
#endif