Browse Source

remove sn

transmit_disinfection
zhaohe 11 months ago
parent
commit
1ab3add862
  1. 40
      basic/sn.c
  2. 38
      basic/sn.h
  3. 2
      basic/zbase.h
  4. 28
      basic/zflash.c
  5. 24
      basic/zflash.h
  6. 1
      zbasic.h

40
basic/sn.c

@ -1,40 +0,0 @@
#include "sn.h"
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/*******************************************************************************
* 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;
}

38
basic/sn.h

@ -1,38 +0,0 @@
#pragma once
#include <stdbool.h>
#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();

2
basic/zbase.h

@ -2,8 +2,6 @@
#include "main.h"
//
#include "project_configs.h"
//
#include "cmsis_os.h"
//
#include <stdint.h>

28
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(); //
__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, &sector_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;
}

24
basic/zflash.h

@ -1,8 +1,8 @@
#pragma once
#include <stdbool.h>
#include "zbase.h"
#include "project_configs.h"
#include "zbase.h"
/**
* @brief
@ -25,34 +25,34 @@
*/
#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_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

1
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"

Loading…
Cancel
Save