From 1ab3add8621513063a767e0446dbaca66e737617 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Mon, 26 Aug 2024 15:40:12 +0800 Subject: [PATCH] remove sn --- basic/sn.c | 40 ---------------------------------------- basic/sn.h | 38 -------------------------------------- basic/zbase.h | 2 -- basic/zflash.c | 28 +++++++++++++++++----------- basic/zflash.h | 26 +++++++++++++------------- zbasic.h | 1 - 6 files changed, 30 insertions(+), 105 deletions(-) delete mode 100644 basic/sn.c delete mode 100644 basic/sn.h diff --git a/basic/sn.c b/basic/sn.c deleted file mode 100644 index ca9f209..0000000 --- a/basic/sn.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "sn.h" - -#include -#include -#include -#include - -/******************************************************************************* - * EXTERN * - *******************************************************************************/ - -static sn_t m_sn; - -sn_t* xs_device_info_get() { // - sn_t* info = (sn_t*)DEVICE_INFO_START_ADD; - m_sn = *info; - - if (m_sn.year < 0) { - m_sn.year = 0; - } - - if (m_sn.weak < 0) { - m_sn.weak = 0; - } - - if (m_sn.index < 0) { - m_sn.index = 0; - } - - return &m_sn; -} - -const char* sn_get_str() { - sn_t* info = xs_device_info_get(); - static char sn_str[32]; - - - sprintf(sn_str, "%s%02ld%02ld%04ld", SN_HEADER, info->year, info->weak, info->index); - return sn_str; -} diff --git a/basic/sn.h b/basic/sn.h deleted file mode 100644 index 2082c7a..0000000 --- a/basic/sn.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once -#include - -#include "main.h" -#include "project_configs.h" - -/** - * @brief - * STM32F407VETx 1024k - * - * index startAdd size - * 0 0x08000000 16k - * 1 0x08004000 16k - * 2 0x08008000 16k - * 3 0x0800C000 16k - * 4 0x08010000 64k - * 5 0x08020000 128k - * 6 0x08040000 128k - * 7 0x08060000 128k - * 8 0x08080000 128k - * 9 0x080A0000 128k - * 10 0x080C0000 128k - * 11 0x080E0000 128k - * - * - * @WARNING: - */ - -#define DEVICE_INFO_START_ADD SDK_CFG__SN_FLASH_ADDR // - -typedef struct { - int32_t year; - int32_t weak; - int32_t index; -} sn_t; - -sn_t* sn_get(); -const char* sn_get_str(); diff --git a/basic/zbase.h b/basic/zbase.h index fbfc1a3..1caf984 100644 --- a/basic/zbase.h +++ b/basic/zbase.h @@ -2,8 +2,6 @@ #include "main.h" // -#include "project_configs.h" -// #include "cmsis_os.h" // #include diff --git a/basic/zflash.c b/basic/zflash.c index 576618c..a67fe44 100644 --- a/basic/zflash.c +++ b/basic/zflash.c @@ -13,6 +13,9 @@ static uint32_t* _defaultdata; static uint32_t _rawsize; static bool _is_first_run = false; +static uint32_t* _flashadd; +static uint32_t _flashSector; + static bool _xs_check_raw_data() { uint32_t checksum = 0; if (_rawstartadd[0] != FLASH_MASK_VAL) { @@ -33,34 +36,37 @@ static HAL_StatusTypeDef _flash_erase(void) { FLASH_EraseInitTypeDef flash_erase_structer = { // .TypeErase = FLASH_TYPEERASE_SECTORS, // - .Sector = FLASH_EARSE_SECTOR, // + .Sector = _flashSector, // .NbSectors = 1, // .VoltageRange = FLASH_VOLTAGE_RANGE_3 // }; - HAL_FLASH_Unlock(); // 解锁 - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR); // 清除一些错误标志 + HAL_FLASH_Unlock(); // 瑙i攣 + __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR); // 娓呴櫎涓浜涢敊璇爣蹇 status = HAL_FLASHEx_Erase(&flash_erase_structer, §or_error_point); if (status != HAL_OK) { ZLOGE("flash", "erase error"); } - HAL_FLASH_Lock(); // 上锁 + HAL_FLASH_Lock(); // return status; } /******************************************************************************* * EXTERN * *******************************************************************************/ -void zflash_init(uint32_t* rawstartadd, uint32_t rawsize) { +void zflash_init(uint32_t* flashadd, uint32_t flashSector, uint32_t* rawstartadd, uint32_t rawsize) { + _flashadd = flashadd; + _flashSector = flashSector; + _rawstartadd = rawstartadd; _defaultdata = NULL; _rawsize = rawsize; - // 读取flash数据 - memcpy(_rawstartadd, (uint32_t*)(FLASH_START_ADD), _rawsize * 4); + // 璇诲彇flash鏁版嵁 + memcpy(_rawstartadd, (uint32_t*)(_flashadd), _rawsize * 4); #if 0 - // 校验数据 + // 鏍¢獙鏁版嵁 if (_xs_check_raw_data()) { return; } @@ -97,14 +103,14 @@ bool zflash_flush(void) { _rawstartadd[_rawsize - 1] = zcompute_checksum(_rawstartadd, _rawsize - 1); _flash_erase(); - HAL_FLASH_Unlock(); // 解锁 + HAL_FLASH_Unlock(); // HAL_StatusTypeDef status; for (uint32_t i = 0; i < _rawsize; i++) { - status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, FLASH_START_ADD + i * 4, _rawstartadd[i]); + status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, _flashadd + i * 4, _rawstartadd[i]); if (status != HAL_OK) { ZLOGE("flash", "write error"); } } - HAL_FLASH_Lock(); // 上锁 + HAL_FLASH_Lock(); // return true; } diff --git a/basic/zflash.h b/basic/zflash.h index baa8503..aeb0706 100644 --- a/basic/zflash.h +++ b/basic/zflash.h @@ -1,8 +1,8 @@ #pragma once #include -#include "zbase.h" #include "project_configs.h" +#include "zbase.h" /** * @brief @@ -24,35 +24,35 @@ * */ -#define FLASH_MASK_VAL 0xABCD -#define FLASH_START_ADD SDK_CFG__CFG_FLASH_ADDR // -#define FLASH_EARSE_SECTOR FLASH_SECTOR_7 -#define FLASH_SOTRAGE_SIZE (128 * 1023) +#define FLASH_MASK_VAL 0xABCD +// #define FLASH_START_ADD SDK_CFG__CFG_FLASH_ADDR // +// #define FLASH_EARSE_SECTOR FLASH_SECTOR_7 +// #define FLASH_SOTRAGE_SIZE (128 * 1023) /** - * @brief 初始化flash + * @brief * - * @param rawstartadd flash内存映射的地址 - * @param defaultdata 默认数据 - * @param rawsize flash内存映射的地址大小 + * @param rawstartadd + * @param defaultdata + * @param rawsize */ -void zflash_init(uint32_t* rawstartadd, uint32_t rawsize); +void zflash_init(uint32_t* flashadd, uint32_t flashSector, uint32_t* rawstartadd, uint32_t rawsize); /** - * @brief 判断是否是第一次初始化flash + * @brief * * @return true * @return false */ bool zflash_is_first_run(void); /** - * @brief 刷新内存输出到flash中 + * @brief * * @return true * @return false */ bool zflash_flush(void); /** - * @brief 恢复出厂设置 + * @brief * * @return true * @return false diff --git a/zbasic.h b/zbasic.h index 2207b12..1582583 100644 --- a/zbasic.h +++ b/zbasic.h @@ -9,7 +9,6 @@ extern "C" { #include "basic/zflash.h" #include "basic/zgpio.h" #include "basic/zlog.h" -#include "basic/sn.h" #include "cmsis_version.h" #include "cmsis_os.h"