本文主要是介绍国民技术获取UID和UCID,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
根据手册可知 UID和UCID 的地址
代码如下
#define UID_Addr (0x1FFFF7F0)
#define UCID_Addr (0x1FFFF7C0)uint8_t UID[12] = {0};
uint8_t UCID[16] = {0};void Read_Flash_Data(u8* pBuffer, u32 NumToRead, u32 ReadAddr)
{u32 i;for (i = 0; i < NumToRead; i++){*((u8*)pBuffer + i) = *((u8*)ReadAddr + i);}
}void USART2_Configuration(void)
{USART_InitType USART_InitStructure;GPIO_InitType GPIO_InitStructure;GPIO_InitStruct(&GPIO_InitStructure);RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_USART2, ENABLE);GPIO_InitStructure.Pin = GPIO_PIN_4;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_InitStructure.GPIO_Alternate = GPIO_AF4_USART2;GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);GPIO_InitStructure.Pin = GPIO_PIN_5;GPIO_InitStructure.GPIO_Pull = GPIO_Pull_Up;GPIO_InitStructure.GPIO_Alternate = GPIO_AF4_USART2;GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);USART_StructInit(&USART_InitStructure);USART_InitStructure.BaudRate = 115200;USART_InitStructure.WordLength = USART_WL_8B;USART_InitStructure.StopBits = USART_STPB_1;USART_InitStructure.Parity = USART_PE_NO;USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX;USART_Init(USART2, &USART_InitStructure);USART_Enable(USART2, ENABLE);
}int fputc(int ch, FILE* f)
{USART_SendData(USART2, (uint8_t)ch);while (USART_GetFlagStatus(USART2, USART_FLAG_TXDE) == RESET);return (ch);
}int main(void)
{int i = 0;USART2_Configuration();Read_Flash_Data(UID, 12, UID_Addr);Read_Flash_Data(UCID, 16, UCID_Addr);printf("UID:0x");for(i = 0; i < 12; i++){printf("%02x", UID[i]);}printf("\r\n\r\n\r\n");printf("UCID:0x");for(i = 0; i < 16; i++){printf("%02x", UCID[i]);}printf("\r\n\r\n\r\n");
}
串口打印如下
UID:0x360213503447373031058929
UCID:0x360213160e5034473730313030058929
这篇关于国民技术获取UID和UCID的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!