当前位置:网站首页>Some experience of gd32 using Hal Library of ST and Gd official library
Some experience of gd32 using Hal Library of ST and Gd official library
2022-07-28 07:54:00 【Tianwaifeixian CUG】

GD32 As a domestic MCU The best in the world , The product line is also relatively rich , Is an alternative STM32 A good choice for . Some time ago, a project used GD32 The single chip computer of , Today, let's talk about some experience of using .
1. Hardware
The model of single chip microcomputer I use is GD32F405RGT6, Corresponding STM32F405RGT6. First , Basically compatible in hardware , One difference is that GD32 Of 31 and 47 Feet are NC,STM32 For the VCAP.STM32 These two pins need to be connected with a capacitor to GND, and GD32 You don't need to . Of course , It doesn't matter to have these two capacitors , therefore , On the hardware GD32 It can be replaced directly STM32.

The simulator can be used Jlink, You can also use STLink, But when downloading the program, a pop-up prompt will appear , Not ST chip .
2. Software
Software , In the early stage, in order to quickly realize the function , Use it directly ST Of HAL Library Development ( Version is V1.27.0). The peripherals used are : External high-speed clock 、Systick Timer 、GPIO、 A serial port 1(DMA、 interrupt )、SPI1、SPI2、I2C1、 External interrupt . use STM32CubeMx The generated code , No changes , Directly as ST Chip use , The above peripheral functions are normal . It shows that the compatibility between the two is good . Other peripherals are basically compatible ( Not tested ), but USB Part of it seems that it can only be used GD Official USB library .
however , Use others' library files , Always feel unreliable , Finally, it was changed to GD The official library , Version is GD32F4xx_Firmware_Library_V3.0.0. Summarize some experience in the modification process :
First ,GD Library heel of ST The previous standard library is very similar , Many functions are inferior to ST Of HAL The library is convenient . such as , A serial port DMA send data , use HAL library , Just call a function :
HAL_UART_Transmit_DMA(&huart1,tx_buffer,64);and GD There are no ready-made functions in the Library , Need to realize :
void usart_dma_transmit(uint8_t *pData,uint32_t num)
{
usart_flag_clear(USART0, USART_FLAG_TC);
dma_channel_disable(DMA1, DMA_CH7);
dma_flag_clear(DMA1, DMA_CH7, DMA_FLAG_FTF);
dma_memory_address_config(DMA1, DMA_CH7, DMA_MEMORY_0, (uint32_t)pData);
dma_transfer_number_config(DMA1, DMA_CH7, num);
dma_channel_enable(DMA1, DMA_CH7);
}There are many more of them , such as I2C Reading and writing 24Cxx series EEPROM Function of ,HAL Functions are also encapsulated in the library :
HAL_I2C_Mem_Write(&hi2c1, AT24Cxx_ADDR_WRITE, addr, I2C_MEMADD_SIZE_16BIT, dat, size, 0xFFFFFFFF);
HAL_I2C_Mem_Read(&hi2c1, AT24Cxx_ADDR_READ, addr, I2C_MEMADD_SIZE_16BIT, recv_buf, size, 0xFFFFFFFF);GD Our library also needs to be implemented by ourselves , Although the official also provides relevant routines , But only support 24C02 etc. 8 Bit address devices ,24C64 etc. 16 The device of bit address needs to be modified by itself .
Of course ,HAL Although the library is easy to use , But it's inefficient . Remember to make a low-power thing before , use STM32L151, The main frequency is set low , Use HAL Library callback function to write serial port interrupt program , There was a mistake . Later, the interrupt part was changed to register operation , It can be seen that its efficiency is low .
secondly , The two are named differently .HAL The clock in the library calls RCC_xxxx, and GD The clock in the library is called RCU_xxxx. also ,HAL The peripheral label in the library is from 1 At the beginning , such as USART1、USART2…, and GD The peripheral label of the library is from 0 At the beginning ,USART0、USART1…. Used to ST Ku's friends , This should be paid special attention to when using .
Last , Programs that achieve the same function , There are also differences in the compiled size between the two .GD The compiled size of the library is as follows :

HAL The compiled size of the library is as follows :

You can see HAL The compiled code of the library is better than GD The library is nearly 4KB, The amount of RAM It's big too 1KB many . Mainly because HAL The library is good for the compatibility of different series of chips , Made many layers of packaging , The procedure is cumbersome .
3. summary
in general ,HAL The library is convenient to use , But less efficient .GD Some functions of the library need to be implemented by ourselves , But efficient execution . Of course , If you use GD Chip , I still suggest using GD The official library , Otherwise, if something goes wrong, it's not easy to check .
If you use ST Chip , I suggest using HAL library . Many people reject HAL library , On the one hand, I feel inefficient , On the other hand, I think it encapsulates many layers , It seems that the procedure is troublesome . I think the problem of low efficiency can be improved through local optimization .(HAL The library also provides some efficient underlying functions similar to the standard library , usually “__HAL” At the beginning ). and , Now SCM resources are relatively rich , Many times we don't have to pursue extreme efficiency . On the other hand , Officials have been promoting this , This is also a trend , We'd better keep pace with the times .
Recommended reading :
several RS485 Introduction to the scheme of isolated communication
STM32CubeMX Series of tutorials
Collection of debugging skills
Welcome to the official account " Development of Embedded Technology ", You can leave a message for me backstage . If you think the official account is helpful to you , Also welcome to recommend and share with others .
边栏推荐
- Matplotlib绘图笔记基础直线、折线、曲线
- [dry goods] 32 EMC standard circuits are shared!
- .NET 6.0中使用Identity框架实现JWT身份认证与授权
- EMC rectification method set
- C language explanation series - array explanation, one-dimensional array, two-dimensional array
- ArcGIS JS自定义Accessor,并通过watchUtils相关方法watch属性
- 【google】解决google浏览器不弹出账号密码保存框且无法保存登录信息问题
- [Google] solve the problem that Google browser does not pop up the account and password save box and cannot save login information
- On deep paging
- 辨析覆盖索引/索引覆盖/三星索引
猜你喜欢

【google】解决google浏览器不弹出账号密码保存框且无法保存登录信息问题

非关系型数据库之Redis【redis集群详细搭建】

User mode vs kernel mode, process vs thread

Matplotlib绘图笔记基础直线、折线、曲线

Google and Stanford jointly issued a document: why do we have to use large models?
![[shaders realize negative anti color effect _shader effect Chapter 11]](/img/c5/70761374330eb4fb3915c335b7efb8.png)
[shaders realize negative anti color effect _shader effect Chapter 11]

Near infrared two region agzs quantum dots wrapped deoxyribonucleic acid dna|dna agzsqds (Qiyue)
![[Google] solve the problem that Google browser does not pop up the account and password save box and cannot save login information](/img/b3/2592e941f5d8f3505fb9763e8947a6.png)
[Google] solve the problem that Google browser does not pop up the account and password save box and cannot save login information

Copper indium sulfide CuInSe2 quantum dots modified DNA (deoxyribonucleic acid) DNA cuinse2qds (Qiyue)

【花书笔记】 之 Chapter01 引言
随机推荐
使用FFmpeg来批量生成单图+单音频的一图流视频
It has been rectified seven times and took half a month. Painful EMC summary
DNA修饰金属铑Rh纳米颗粒RhNPS-DNA(DNA修饰贵金属纳米颗粒)
【青鸟学员故事】追风少年“李晓亮”
GD32使用ST的HAL库和GD官方库的一些体会
DNA modified rhodium RH nanoparticles rhnps DNA (DNA modified noble metal nanoparticles)
DNA-CuInSeQDs近红外CuInSe量子点包裹脱氧核糖核酸DNA
辨析覆盖索引/索引覆盖/三星索引
ASP. Net core technology insider and project practice after reading
【无标题】
Eventbus of guava
Analysis of collector principle
Pytorch的冻结以及解冻
CLion调试redis6源码
Clion debugging redis6 source code
Elaborate on common mode interference and differential mode interference
win系统添加打印机
Delete the nodes in the linked list - daily question
动态内存管理知识点
EMC整改思路