10503 views|4 replies

124

Posts

1

Resources
The OP
 

[GD32F350 Learning Notes] Unique ID Acquisition and Printf Function Remapping [Copy link]

This post was last edited by justd0 on 2018-9-20 00:08 The Colibri-F350RX development board obtained by registering for the forum event, free up the task at hand to explore this domestic MCU equipped with M4 core. The development board has been designed with programming and debugging modules. The information is in the information download column of the https://www.eeworld.com.cn/huodong/Gigadevice_GD32F350Contest_201808/. After downloading, install the driver and IDE library dependencies, and directly plug in the USB to have fun.

A beautiful photo of power on

##The 350demo test program is provided in the information. The official library functions have been encapsulated, and the notes are brief and clear. For those who have been exposed to MCU programming before, it should be stress-free to read. After opening the project, you can see that the demo program provides test programs for LED, KEY and UART. You can select different test programs by adjusting the EVB_EXAMPLE macro definition in the exmaple.h header file. To test the UART, I selected it as follows: c #include "colibri_bsp.h" #define CH13_BOARD_UART_EXAMPLE (132) #define CH13_BOARD_LED_EXAMPLE (133) #define CH13_BOARD_KEY_EXAMPLE (134) #define EVB_EXAMPLE CH13_BOARD_UART_EXAMPLE You can see that the program in the board_uart_example.c file is as follows: c #include "example.h" #if (EVB_EXAMPLE == CH13_BOARD_UART_EXAMPLE) int main(void) { EvbUart1Config(); while(1) { for (int i =0; i<0xfffff; i++); EvbUart1WriteStr("HelloWorldn"); } return 0; } Simply compile and download it to the development board, and you will be able to receive the data through the serial port debugging assistant~ Although the demo program has EvbUart1WriteStr(const char* str) and void EvbUart1Printf(char* fmt, ...), the first function can only send string type data, and the second function has the same function as the Printf function, but it needs to define a buffer space by itself and the implementation efficiency seems to be not high. The main reason is that printf() is concise and familiar. ## Remapping of Printf function Friends who have used MCU must have used Printf function. It is not complicated to enable this function on GD32F350~ 1. Reference the standard input and output library in the project #include "stdio.h" 2. Remap the fputc function anywhere in your projectc int fputc(int ch, FILE *f) { usart_data_transmit(USART1, ch); while (RESET == usart_flag_get(USART1,USART_FLAG_TC)); return ch; } Then you can use the familiar and simple printf function~ ## Globally unique ID The electronic signature of the device contains storage capacity information and a 96-bit unique device ID. It is stored in the information module of the on-chip flash memory. The 96-bit unique device ID is unique for each chip, so it can be used as a serial number, or part of a security key, etc. The GD32F3X0 chip storage capacity information base address is 0x1FFFF7E0, and the device unique ID base address is 0x1FFFF7AC (31:0 bits), 0x1FFFF7B0 (63:32 bits) and 0x1FFFF7B4 (95:64 bits). The address is set by the manufacturer and cannot be changed by the user. In addition, the register can only be accessed by word (32 bits). c #include "example.h" #if (EVB_EXAMPLE == CH13_BOARD_UART_EXAMPLE) int main(void) { uint32_t Flash_Size = *(uint32_t *)(0x1FFFF7E0); //Get the MCU unique ID uint32_t Unique_ID1 = *(uint32_t *)(0x1FFFF7AC); //UNIQUE_ID [31: 0] uint32_t Unique_ID2 = *(uint32_t *)(0x1FFFF7B0); //UNIQUE_ID[63:32] uint32_t Unique_ID3 = *(uint32_t *)(0x1FFFF7B4); //UNIQUE_ID[95:63] EvbUart1Config(); while(1) { for (int i =0; i <0xfffff; i++); printf("This is Colibri-F350RB ID:%x %x %x (hex) Flash_Size:%dn",Unique_ID3,Unique_ID2,Unique_ID1,Flash_Size); } return 0; } By accessing the register pointer, the MCU unique ID is obtained, which can be used for software encryption, serial number, etc.

This post is from GD32 MCU

Latest reply

Thank you, OP. If I want to remap two serial ports, how can this fputc function support remapping of two serial ports?   Details Published on 2022-12-3 11:54
 

1368

Posts

6

Resources
2
 
Very good, thank you for sharing, keep up the good work, looking forward to your masterpiece
This post is from GD32 MCU
 
Personal signature专注智能产品的研究与开发,专注于电子电路的生产与制造……QQ:2912615383,电子爱好者群: void
 
 

32

Posts

0

Resources
3
 
//========================================================== //Read stm32 id void READ_Unique_ID(volatile u32 *p) { volatile u32 Addr; Addr=0x20000006; //Let the reverse engineer mistakenly think it is a ram variable Addr-=0x800; Addr-=0x1e; //addr is equal to the base address of id 0x1ffff7e8 p[0] = *(vu32*)(Addr); p[1] = *(vu32*)(Addr+4); p[2] = *(vu32*)(Addr+8); } //============================================================
This post is from GD32 MCU
 
 
 

32

Posts

0

Resources
4
 

3. Using ID to encrypt software


1. If there is an external memory on the board, you can first write a program, use the algorithm to calculate the ID to get some values and store them in the external memory, and then burn the real program. The real program can verify whether the data in the external memory is legal.



2. Use the key combination on the board, or press and hold certain keys when powered on. The program uses the algorithm to calculate the ID and store some values in the program area (stm8 is the EE area). When the program is running, verify whether the data in the program area is correct.



3. Xuanwei programmer has the function of software encryption. The programmer will read the chip ID and directly rewrite the buffer according to the algorithm to achieve the function of software encryption.



4. The read ID is processed by a certain algorithm, such as XOR plus a number, and the obtained data is stored in the flash (only run once, and the flag bit is also stored in the flash after running). The next time this flag bit is read, the program will not be run. //Q9272078



4. Pay attention when encrypting software


1. Do not directly use the ID address in the program, for example, STM32: 1FFFF7E8 1FFFF7EC 1FFFF7F0 STM8: 0x4865~0x4870


2. Use checksum or CRC to check the program area to prevent program modification


This post is from GD32 MCU
 
 
 

4

Posts

0

Resources
5
 

Thank you, OP. If I want to remap two serial ports, how can this fputc function support remapping of two serial ports?

This post is from GD32 MCU
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list