diff --git a/basic/sn.c b/basic/sn.c new file mode 100644 index 0000000..f35ce36 --- /dev/null +++ b/basic/sn.c @@ -0,0 +1,40 @@ +#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", info->year, info->weak, info->index); + return sn_str; +} diff --git a/basic/sn.h b/basic/sn.h new file mode 100644 index 0000000..c6c4b86 --- /dev/null +++ b/basic/sn.h @@ -0,0 +1,41 @@ +#pragma once +#include +#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 // + +#pragma pack(1) +typedef struct { + uint8_t year; + uint8_t weak; + uint16_t index; +} sn_t; +#pragma pack() + +sn_t* sn_get(); +const char* sn_get_str(); diff --git a/basic/zgpio.c b/basic/zgpio.c index e4ba924..cb2e8a1 100644 --- a/basic/zgpio.c +++ b/basic/zgpio.c @@ -2,6 +2,7 @@ #include "zdelay.h" #include "zlog.h" +#include "project_configs.h" static bool gpio_enable_clock(GPIO_TypeDef *m_gpio) { #ifdef GPIOA diff --git a/basic/zlog.c b/basic/zlog.c index 3ae27dc..3f0499e 100644 --- a/basic/zlog.c +++ b/basic/zlog.c @@ -1,5 +1,6 @@ #include "zlog.h" #include "zbase.h" +#include "project_configs.h" bool g_xs_enable_log = true; extern UART_HandleTypeDef DEBUG_UART; diff --git a/zbasic.h b/zbasic.h index 1582583..2207b12 100644 --- a/zbasic.h +++ b/zbasic.h @@ -9,6 +9,7 @@ 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"