当前位置:网站首页>W801 / w800 / w806 unique ID / CPUID / flashid
W801 / w800 / w806 unique ID / CPUID / flashid
2022-04-23 01:39:00 【Mr. Zhao】
This is the catalogue
This article uses the environment :
master control :W800-KIT ( Development board )
compatible :W800 W801 AIR101
development environment :CDK
SDK:W801/W800 Of SDK(tls library ),HAL The library does not implement uniqueid The adaptation of
My lianshengde Q & a community homepage
One 、 Description of project
^^^^ Program function : Read a ID For identification or other purposes .
^^^^ This tutorial is mainly a summary , Relatively simple . This paper mainly obtains from three angles ID:CPUID、FLASHID、uniqueid.
CPUID:32 position this ID Not in our traditional sense ID, I asked the authorities , This is the kernel ID, As long as it's the kernel ,ID Just the same , It's not the only one .
flashID:8 byte Different flash Corresponding ID Dissimilarity , However, it is unclear whether a batch is one ID.
uniqueID:18 byte This is not an independent ID, Yes, it will flash After the fusion of parameters ID, It is said to be the only one ID.
Two 、 Engineering
^^^^ This section will read three different ID, You can use it according to your actual situation .
^^^^ Three ID Shared structure :
typedef struct ID_DATA
{
uint32 CPUID;
u8 flash_id[8];
u8 unique_id[18];
}ID_DATA;
In the above code ID_DATA The structure contains three different ID,cpu、flash and unique. This paper the following three ID All use structures for storage .
2.1、CPUID
^^^^ This ID Can read from register bytes , Same kernel ID should It's all the same .ID The reading program is a reference in lianshengde Q & a community ZYQ bosses The answer to :

The procedure is as follows :
uint32 GetCpuIdr(void)
{
uint32 id = 0;
asm volatile(
"mfcr %[id], cr<13, 0>\n\t"
:[id]"+&r"(id)
:
:
);
return id;
}
^^^^ meanwhile ZYQ This is also given ID For a certain purpose , as follows :

^^^^ This is what the boss said to me , What the boss said is really reasonable , It's really my thoughtlessness . You can refer to .
2.2、flashID
^^^^ Similarly, the following procedures still use the official code , I just summarized the code , Put all the macro definitions together , If it is W800 and W801 The official SDK, Namely tls Library demo You can paste and copy the following code directly , Call the function directly . If it is HAL library , Macro definitions can be deleted .
//add by zxx start
//flashID
#define CMD_START_Pos 8U /*!< CMD start position */
#define CMD_START_Msk (1UL << CMD_START_Pos) /*!< CMD start Mask */
#define RSA_BASE 0x40000000
/** * @brief This function is used to read the flash_id id of the internal flash. * * @param[out] flash_id Specified the address to save the flash_id, the length must be greater than or equals to 8 bytes. * * @retval TLS_FLS_STATUS_OK if read sucsess * @retval TLS_FLS_STATUS_EIO if read fail * * @note The flash_id's length must be greater than or equals to 8 bytes. */
int readFlashUniqueId(u8 *id,u8 fls_len)
{
if (!id || fls_len <= 8) {
printf("id equal NULL or fls_led not equal 8\r\n");
return -1;
}
M32(HR_FLASH_CMD_ADDR) = 0xBC04B;
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
u32 *id32 = id;
for (u8 i = 0; i < 2; i++) {
id32[i] = M32(RSA_BASE + (i + 1) * 4);
}
return 0;
}
//add by zxx end
2.3、uniqueID
^^^^ Read unique ID The official library file provides code , This section mainly deals with function calls , That's it . Function in wm_internal_fls.c In file :
/** * @brief This function is used to read the unique id of the internal flash. * * @param[out] uuid Specified the address to save the uuid, the length must be greater than or equals to 18 bytes. * * @retval TLS_FLS_STATUS_OK if read sucsess * @retval TLS_FLS_STATUS_EIO if read fail * * @note The uuid's length must be greater than or equals to 18 bytes. */
int tls_fls_read_unique_id(unsigned char *uuid)
{
unsigned int value = 0;
unsigned int addr_read = 0;
int i = 0;
int len;
unsigned char FLASH_BUF[20];
unsigned char *addr = &FLASH_BUF[0];
int dumy_bytes = 0;
int uni_bytes = 0;
unsigned char rid;
int word;
int byte;
if (inside_fls == NULL)
{
return TLS_FLS_STATUS_EPERM;
}
tls_os_sem_acquire(inside_fls->fls_lock, 0);
memset(uuid, 0xFF, 18);
rid = readRID();
switch(rid)
{
case SPIFLASH_MID_GD:
case SPIFLASH_MID_PUYA:
case SPIFLASH_MID_TSINGTENG:
dumy_bytes = 4;
uni_bytes = 16;
break;
case SPIFLASH_MID_WINBOND:
case SPIFLASH_MID_FUDANMICRO:
case SPIFLASH_MID_BOYA:
case SPIFLASH_MID_XMC:
dumy_bytes = 4;
uni_bytes = 8;
break;
case SPIFLASH_MID_ESMT:
case SPIFLASH_MID_XTX:
default:
tls_os_sem_release(inside_fls->fls_lock);
return -1;
}
uuid[0] = rid;
uuid[1] = (unsigned char)(uni_bytes & 0xFF);
len = dumy_bytes + uni_bytes;
word = len/4;
byte = len%4;
value = 0xC04B|((len-1) << 16);
M32(HR_FLASH_CMD_ADDR) = value;
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
addr_read = RSA_BASE_ADDRESS;
for(i = 0;i < word; i ++)
{
M32(addr) = M32(addr_read);
addr += 4;
addr_read += 4;
}
if(byte > 0)
{
M32(addr) = M32(addr_read);
addr += 3; //point last byte
while(byte)
{
*addr = 0;
addr --;
byte --;
}
}
addr = &FLASH_BUF[0];
memcpy(&uuid[2], addr + dumy_bytes, uni_bytes);
tls_os_sem_release(inside_fls->fls_lock);
return 0;
}
The above functions will be a lot of ID It was combined .
Little doubt : I don't think this function is very ideal , Because the function does not judge whether the parameters passed in are legal , If I pass a small array ? Send an illegal address ? In this way, the data may be wrong . Of course, it's a digression , When you use it, you must pay attention to . Validity of parameters .
3、 ... and 、 test
3.1、 Test code
^^^^ Write a test program to test whether it reads correctly ID. Reading is relatively simple, only providing code , You can encapsulate the function yourself .
while(1)
{
ID_DATA id_data;
readFlashUniqueId(id_data.flash_id,sizeof(id_data.flash_id));
printf("flashid: ");
for(int i=0;i<8;i++)
printf("%d ",id_data.flash_id[i]);
printf("\r\n");
tls_fls_read_unique_id(id_data.dev_id);
printf("uniqueid: ");
for(int i=0;i<18;i++)
printf("%d ",id_data.dev_id[i]);
printf("\r\n");
id_data.cpuid = GetCpuIdr();
printf("cpuid: %d\r\n",id_data.cpuid);
while(1);
}
3.2、W800 test result

3.3、W801 test result
First block W801:

Second pieces W801:

3.4、AIR101 test result

版权声明
本文为[Mr. Zhao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230136121329.html
边栏推荐
- gin -get请求的小示例1-Handle处理GET请求
- iTextSharp 显示中文字体
- 数字藏品平台入驻 数字藏品平台开发 数字藏品SaaS平台
- Traversal of ladder race l2-6 tree
- After disk D is distributed to Disk C, what should I do if the database recovery hangs? Please answer
- Itextsharp displays Chinese fonts
- Good test data management, in the end how to do?
- Redis implements distributed locks
- [蓝桥杯][2019年第十届真题]外卖店优先级
- GBASE 8s 并发控制之封锁操作
猜你喜欢

Learning of gin framework -- golang

Redis实现分布式锁

(product resources) mingdeyang ad8488 module high performance digital X-ray FMC interface 128 analog channel high-speed ADC chip

第六章 使用 matplotlib 绘制热力图

gin--hello

彻底卸载Antidote 10 ?Antidote卸载不干净怎么办?

Chris LATTNER, father of llvm: the golden age of compilers

GBase 8s 备份介绍

NR polar code 七- SCL(succesive cancellation list decoding)

清研环境深交所上市:年营收1.8亿 市值41亿
随机推荐
JSP基础知识总结
LSF的使用方法总结
Gbase 8s Group by 功能介绍
Abused "architect"!
Jerry's CPU performance test [chapter]
iTextSharp 页面设置
轮转法分片
Tight coupling of visual wheel odometer
Chris LATTNER, father of llvm: the golden age of compilers
Introduction to granularity locking of gbase 8s concurrency control
Linux系统下以RPM方式如何安装mysql-5.7.9
Rotation slice
In the second half of the smart watch, opportunities and challenges coexist
Glide set fillet image (support custom fillet position)
gin--hello
[Blue Bridge Cup] [10th real topic in 2019] priority of takeout shop
GBase 8s 备份介绍
Unity combines itextsharp to generate PDF preparation DLL
Jisuan Hakka spectrum (DFS for direct post algebra)
角色個人屬性英文縮寫