当前位置:网站首页>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
边栏推荐
- Jerry's AI server [chapter]
- 轮转法分片
- In the context of Internet plus, how can enterprises innovate customer service?
- Android sqliteopenhelper data table structure upgrade
- Introduction to granularity locking of gbase 8s concurrency control
- ai2022新功能,illustrator 2022 新功能介绍
- Unity combines itextsharp to generate PDF preparation DLL
- LSF的常用使用命令总结
- Linux系统下以RPM方式如何安装mysql-5.7.9
- d盘分给C盘后,数据库恢复挂起怎么办,求各位解答
猜你喜欢
Let's talk about passive safety again. I'll teach you to understand the rating report of China Insurance Research Institute collision test

Text justify, orientation, combine text attributes

无关联进程间通信 —— 命名管道的创建和使用

Abused "architect"!

计蒜客:方程的解数

清研环境深交所上市:年营收1.8亿 市值41亿

engine.POST()处理POST请求

数字藏品平台入驻 数字藏品平台开发 数字藏品SaaS平台

“自虐神器”一夜爆火:用手柄控制自己的脸,代码自取,后果自负

Redis实现分布式锁
随机推荐
彻底卸载Antidote 10 ?Antidote卸载不干净怎么办?
. net (c) MySQL conn.open() reports an error: solution to SSL connection error
Blocking type of gbase 8s concurrency control
Soatest preliminary understanding
.NET(C#) MySQL conn.Open()报错:SSL Connection error的解决方法
VSCODE + PHP Debug + 名字空间指引
Abused "architect"!
(product resources) mingdeyang ad8488 module high performance digital X-ray FMC interface 128 analog channel high-speed ADC chip
Introduction to PCIe xdma IP core (with list) - mingdeyang science and Education (mdy edu. Com)
"Self abuse artifact" exploded overnight: control your face with a handle, take your own code, and bear the consequences
Instructions for Jerry's reset IO maintenance level [chapter]
Small example of gin - get request 2-handle handles post requests
UVC camera encapsulation class
Learning of gin framework -- golang
Gbase 8s shared memory segment deletion
Counting garlic customers: Sudoku (DFS)
DFS parity pruning
计蒜客:方程的解数
Technology cloud report: cloud computing has entered the "second half". Where is the way out for domestic cloud?
领导/老师让填写电子excel表格文档可手机上如何编辑word/excel文件填写excel/word电子文档?