[transplantation of domestic MCU] I’ll teach you how to make BSP of domestic MCU based on tae32f5300


This article was originally published by RT thread forum user @ happycode999:https://club.rt-thread.org/as…

1、 Introduction

   I have the honor to participate in the transplantation of domestic MCU. The tae32f5300 to be transplanted this time is a 32-bit MCU with hardware accelerator (Erpu) for power products. In order to meet the requirements of the power industry, four independent IIR filters are built for industrial filtering algorithm, and an electric energy metering module ECU is built in. The reason why I chose this chip is that the development board provided by Zhuhai Tai carries many peripherals. It is a development board of domestic MCU that is very suitable for learning. I also see that other small partners have been transplanted to other domestic MCU. Everyone has their own reasons.
   at the beginning, I also felt that the task of transplantation was relatively difficult, so I searched the rtthread forum for domestic MCU transplantation and found two articles. I saw that one was transplanted from Huada and the transplantation process was relatively simple, so I transplanted it according to his method. I hope this article has a more detailed record of the process of transplanting domestic MCU, Help you to solve your doubts if you want to transplant RT thread to domestic MCU. So far, I have only completed the migration of Keil and implemented pin and UART drivers. Send a note.

2、 Preparation before BSP production: understand the BSP structure, the use of scons and the use of kconfig

2.1 BSP structure in RT thread

[transplantation of domestic MCU] I'll teach you how to make BSP of domestic MCU based on tae32f5300
Applications: mainly main C file, where the source code of the user application is placed.
Build: store the compiled target file
Drivers: store peripheral drivers, such as pin driver and UART driver
Figures: store readme Picture files used by MD
Libraries: firmware library of the chip, including CMSIS and standard peripheral library.
There are two standard projects: one is the IAR standard project and the other is the Keil standard project. There is no source file in the project, which mainly indicates the chip model and compiled configuration. When using the scons — target = mdk5 command, the source code and header will be put into the Keil project according to the requirements of the sconscript script.
Scons build script sconscript: the script in the root directory is the top-level script, which can be seen from the following code through OS path. Isfile to determine whether there is a sconscript file in the subdirectory. If there is, the build script under the subdirectory will be executed. The build script mainly indicates the path of the source code and header file.

list = os.listdir(cwd)
for d in list:
    path = os.path.join(cwd, d)
    if os.path.isfile(os.path.join(path, 'SConscript')):
        objs = objs + SConscript(os.path.join(d, 'SConscript'))

rtconfig. h: The configuration file of rtthread. After the configuration is completed by using menuconfig command, the configuration of the file will be modified to enable or disable rtthread components through macros.
Kconfig: menu used to display menuconfig.

2.2. Use of scons build tool

  referencehttps://www.jianshu.com/p/e4b…, understand the basic syntax of scons. This migration is mainly to copy a project similar to the migration chip. This time I refer to mm32f327x under BSP. Three sconscripts need to be modified for migration, one in the application folder, one in the drivers folder and one in the libraries folder. Modify the corresponding script file according to your own SDK. The following shows the source code, which can be skipped. Go directly to the use of kconfig in Section 2.3. If you need reference, you can continue to see the following contents and see more BSPs.
Application: the code that focuses on the split part is the source code that needs to be included by default and is not affected by the configuration. The split of the latter two sconscripts is the same.

import rtconfig
from building import *

cwd     = GetCurrentDir()
CPPPATH = [cwd, str(Dir('#'))]
src     = Split("""

group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)



# RT-Thread building script for component

from building import *

cwd = GetCurrentDir()

# add the general drivers.
src = Split("""

# add serial driver code
if  GetDepend('BSP_USING_UART') or GetDepend('BSP_USING_UART1'):
    src += ['drv_uart.c']

# add gpio driver code
if  GetDepend(['BSP_USING_GPIO']):
    src += ['drv_gpio.c']

CPPPATH = [cwd]

group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)



# RT-Thread building script for bridge

import rtconfig
from building import *

# get current directory
cwd = GetCurrentDir()

# The set of source files associated with this SConscript file.
src = Split("""

#src += Glob('TAE32F53xx_StdPeriph_Driver/src/*.c')

if GetDepend(['RT_USING_SERIAL']):
    src += ['TAE32F53xx_StdPeriph_Driver/src/tae32f53xx_ll_uart.c']
    src += ['TAE32F53xx_StdPeriph_Driver/src/tae32f53xx_ll_tmr.c']

if GetDepend(['RT_USING_I2C']):
    src += ['TAE32F53xx_StdPeriph_Driver/src/tae32f53xx_ll_i2c.c']

#if GetDepend(['RT_USING_SPI']):
#    src += ['TAE32F53xx_StdPeriph_Driver/src/hc32f4a0_spi.c']
#    src += ['TAE32F53xx_StdPeriph_Driver/src/hc32f4a0_qspi.c']

if GetDepend(['RT_USING_CAN']):
    src += ['TAE32F53xx_StdPeriph_Driver/src/tae32f53xx_ll_can.c']

if GetDepend(['RT_USING_ADC']):
    src += ['TAE32F53xx_StdPeriph_Driver/src/tae32f53xx_ll_adc.c']

#if GetDepend(['RT_USING_RTC']):
#    src += ['HC32F4A0_StdPeriph_Driver/src/hc32f4a0_rtc.c']

if GetDepend(['RT_USING_WDT']):
    src += ['TAE32F53xx_StdPeriph_Driver/src/tae32f53xx_ll_wwdg.c']
    src += ['TAE32F53xx_StdPeriph_Driver/src/tae32f53xx_ll_iwdg.c']

if GetDepend(['RT_USING_HWTIMER']) or GetDepend(['RT_USING_PWM'] or GetDepend(['RT_USING_PULSE_ENCODER'])):
    src += ['TAE32F53xx_StdPeriph_Driver/src/tae32f53xx_ll_tmr.c']

#add for startup script 
if rtconfig.CROSS_TOOL == 'gcc':
    src = src + ['CMSIS/Device/Tai_action/TAE32F53xx/Source/GCC/startup_ARMCM3.S']
elif rtconfig.CROSS_TOOL == 'keil':
    #src = src + ['CMSIS/Device/Tai_action/TAE32F53xx/Source/ARM/startup_ARMCM3.s']
    src = src + ['CMSIS/Device/Tai_action/TAE32F53xx/Source/startup_tae32f53xx.c']
elif rtconfig.CROSS_TOOL == 'iar':
    src = src + ['CMSIS/Device/Tai_action/TAE32F53xx/Source/IAR/startup_ARMCM3.s']

#add headfile script 
path = [cwd + '/CMSIS/Include', 
    cwd + '/CMSIS/Device/Tai_action/TAE32F53xx/Include',
    cwd + '/TAE32F53xx_StdPeriph_Driver/inc']


group = DefineGroup('TAE32_StdPeriph', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)


2.3 kconfig file syntax

Kconfig is mainly used for the menu display content of menuconfig. It refers to the writing methods of others to add or delete the configuration options of menuconfig.

3、 Production example based on tae32f5300

3.1 preparation (GIT clone RTT source code, Download env tool)

The source code and env tools can be downloaded here:https://cn.bing.com/search?q=…

3.2 copy BSP of similar domestic MCU

I copied mm32f327x because they are all Cortex-M3 kernels. I renamed BSP to tae32f5300

3.3 modification of standard works

Open the standard project and modify the chip model and various options of Keil according to the original standard project: for example, whether to enable microlib, link script, default debugger and flash download algorithm.

3.4 modify the sconscript script in the applications, drivers and libraries folders

The script in the libraries folder is troublesome. It mainly indicates the path of the source code and header file. It was abandoned here at the beginning. Later, after seeing the article of the big man in the forum, he patiently changed the script file.

3.5 modify kconfig in the top level and drivers folder

This is easy to change. If the referenced BSP is too simple and does not cover all the syntax of kconfig, it is recommended to find a more complete one, so it is easy to change.

3.6 add pin driver and UART driver

3.6.1 pin drive

Open three DRVs_ gpio. C you can see how to change it. I refer to bluetrum of Zhongke Lanxun, w60x of lianshengde and mm32f327x of smart. Who calls me to cook? If I don’t cook, I’ll write it myself.

3.6.2 UART drive

Same as pin drive.


This migration activity is the first time I have used the scons script. At present, only the Keil part has been completed. The compilation error of GCC has not been solved yet. I hope to use this article to make it easier to transplant RT thread to domestic MCU. Transplanting nano can not give full play to the advantages of rtthread. Making BSP can use all resources of rtthread. Finally, I hope the little partner’s transplantation journey will be smooth.

[transplantation of domestic MCU] I'll teach you how to make BSP of domestic MCU based on tae32f5300

Recently, the shortage of chips has opened, setting off a new wave of domestic substitution. RT thread launched a domestic MCU transplantation contribution activity and invited developers to participate!
Event details:The rise of national tide! RT thread domestic MCU transplantation contribution activity started!