当前位置:网站首页>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
边栏推荐
- Itextsharp infrastructure
- DFS parity pruning
- Practice and exploration of knowledge map visualization technology in meituan
- LSF的常用使用命令总结
- Use Charles to grab app package
- (product resources) mingdeyang ad8488 module high performance digital X-ray FMC interface 128 analog channel high-speed ADC chip
- In the context of Internet plus, how can enterprises innovate customer service?
- [经验教程]支付宝余额自动转入余额宝怎么设置关闭取消支付宝余额自动转入余额宝?
- [interview skills] how to face an interview without a leading group
- [course summary] Hello harmonyos series of courses, take you to zero foundation introduction
猜你喜欢
第六章 使用 matplotlib 绘制热力图
JSP基础知识总结
四级城市地区表 xlsx, sql文件,国内,中国省市县街道乡镇四级地址 (名称,联动ID,层级,是否末级(1-是))
Learning of gin framework -- golang
NR polar code 七- SCL(succesive cancellation list decoding)
彻底卸载Antidote 10 ?Antidote卸载不干净怎么办?
Chapter 9 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of exercises for users to establish their own data types
42、使用mmrotate中k3det进行旋转目标检测,并进行mnn部署和ncnn部署
gin--hello
gin框架的学习--golang
随机推荐
Qingyan environment and Shenzhen Stock Exchange listing: annual revenue of 180 million and market value of 4.1 billion
找数字(DFS)
角色个人属性英文缩写
UVC camera encapsulation class
W801/W800/W806唯一ID/CPUID/FLASHID
最新流程引擎 flowable 6.7.2 更新说明
01 knapsack problem - and deformation problem
gin -get请求的小示例1-Handle处理GET请求
engine.POST()处理POST请求
修改数组(并查集)
Blocking type of gbase 8s concurrency control
Practice and exploration of knowledge map visualization technology in meituan
gin--hello
LSF的常用使用命令总结
Introduction to gbase8s SQL Engine framework
iTextSharp 页面设置
Rotation slice
Introduction to PCIe xdma IP core (with list) - mingdeyang science and Education (mdy edu. Com)
Gbase 8s检查点简介
GBase 8t索引