/** * @file flash_param.h * @brief Flash parameter storage module for TCP2UART * * Stores configuration parameters in STM32F103 internal Flash. * Uses the last page of Flash (1KB) for parameter storage. */ #ifndef __FLASH_PARAM_H__ #define __FLASH_PARAM_H__ #include #include #ifdef __cplusplus extern "C" { #endif /* Flash configuration for the current STM32F103RDT6 target (384KB Flash). */ #define FLASH_PARAM_PAGE_SIZE 1024 /* 1KB per page for STM32F103 */ #define FLASH_PARAM_START_ADDR 0x0805FC00 /* Last 1KB page of 384KB Flash */ #define FLASH_PARAM_END_ADDR 0x08060000 /* End of 384KB Flash */ /* Historical reference: STM32F103RCT6 would use 0x0803FC00 as its last page. */ /** * @brief Initialize Flash parameter storage * @return 0 on success, negative on error */ int flash_param_init(void); /** * @brief Read parameters from Flash * @param data Output buffer * @param len Length to read * @return 0 on success, negative on error */ int flash_param_read(void *data, uint32_t len); /** * @brief Write parameters to Flash * @param data Data to write * @param len Length to write * @return 0 on success, negative on error * * Note: This function will erase the Flash page before writing. */ int flash_param_write(const void *data, uint32_t len); /** * @brief Erase parameter storage area * @return 0 on success, negative on error */ int flash_param_erase(void); /** * @brief Calculate CRC32 for data * @param data Data buffer * @param len Data length * @return CRC32 value */ uint32_t flash_param_crc32(const void *data, uint32_t len); /** * @brief Verify parameter storage integrity * @return 0 if valid, negative if invalid or corrupted */ int flash_param_verify(void); #ifdef __cplusplus } #endif #endif /* __FLASH_PARAM_H__ */