[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

Time:2021-12-31

This article was originally published by RT thread forum users @ who want to be Princes:https://club.rt-thread.org/as…

Preparation before transplantation

premise

Now chip prices are rising, and many domestic manufacturers are constantly looking for alternatives. Although the company is not very sensitive to the chip price, as a new generation of migrant workers, chrysanthemum is still tight. I took the initiative to replace domestic chips. I originally wanted to use GD series, and the leaders decided to use Huada. Finally, I chose hc32f460petb.
Recently, RT thread held [domestic MCU transplantation] activity. The staff suggested that I submit PR based on the original transplanted nano version, just to practice.
Hc32f460 transplants RT thread nano based on keil MDK
https://club.rt-thread.org/as…

Hardware

  • Chip model: hc32f460petb
  • Chip core: arm cortex M4
  • Chip dominant frequency: up to 200MHz
  • On chip SRAM: 192K
  • On chip flash: 512k

target

  • Environment construction
  • Basic engineering
  • Verification Engineering

Transplantation process

1. Environmental construction

Install keil5.
Install the package of hc32f460: HDSC HC32F460. 1.0. 7. Pack, download link on the official website:http://www.hdsc.com.cn/Catego…

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

Serial assistant – mobaxterm

2. Foundation works

1. Prepare the RT thread master source package

Download address:https://gitee.com/rtthread/rt…

2. Prepare template

Find the basic template Huada series BSP package. Hc32f4a0 already exists in the RT thread code warehouse. Copy a copy and change the folder name to hc32f460

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

Make modifications in the order of directory files

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

3. Modify template

Modify main. In hc32f460 \ application directory c

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\applicationSconscript in the directory is not modified and can continue to be used

modifyhc32f460\board\linker_scriptsLink SCT, this file is a linked file and needs to be modified according to the chip data

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

modifyhc32f460\boardBoard in the directory c. This file provides chip clock configuration, system clock configuration, tick timer, stack initialization, RTT components initialization and console settings for the chip

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

modifyhc32f460\boardBoard in the directory h. Set stack position and size.

modifyhc32f460\boardBoard under directory_ config. c. Initialize serial port pin

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

Modify hc32f460 \ board \ kconfig, and modify the source code to

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

Hc32f460 \ board \ sconscript is not modified

Keep DRV in hc32f460 \ drivers directory_ gpio. c、drv_ gpio. h、drv_ irq. c、drv_ irq. h、drv_ usart. c、drv_ usart. h、SConscript

hc32f460\driversDirectory DRV_ gpio. C amend to read

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\driversDirectory DRV_ gpio. H amend to read

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

DRV in hc32f460 \ drivers directory_ irq. C amend to read

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

DRV in hc32f460 \ drivers directory_ irq. H amend to read

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\driversDirectory DRV_ usart. C amend to read

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\driversDirectory DRV_ usart. H amend to read

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\driversThe sconscript in the directory is modified to

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb
deletehc32f460\figuresfolder

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\Libraries\CMSIS\Device\HDSCThe folder under the directory is modified to hc32f460

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\Libraries\CMSIS\Device\HDSC\HC32F460\IncludeDelete DDL_ config. h、hc32_ common. h、hc32_ ddl. h、hc32f4a0. h、system_ hc32f4a0. h,

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

Replace with hc32f460 series files

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\Libraries\CMSIS\Device\HDSC\HC32F460\SourceDelete system under directory_ hc32f4a0. c

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\Libraries\CMSIS\Device\HDSC\HC32F460\Source\ARMReplace with

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\Libraries\CMSIS\Device\HDSC\HC32F460\Source\GCCReplace with

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\Libraries\CMSIS\Device\HDSC\HC32F460\SourceReplace with system_ hc32f460. c

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\LibrariesHc32f4a0 under directory_ StdPeriph_ Replace driver with hc32f460_ StdPeriph_ Driver

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\Libraries\HC32F460_StdPeriph_DriverReplace with hc32f460 standard driver under the directory

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

hc32f460\Libraries\SConscriptChange to the following

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb
Modify rtconfig. In the \ hc32f460 directory Py replace all hc32f4a0 with hc32f460

modify\hc32f460Sconstruct Replace hc32f4a0 in py with hc32f460

Test whether kconfig is modified successfully. Right click in the \ hc32f460 directory

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

Save the configuration file after entering the command menuconfig

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

If the console uses usart4, it can be modified in RT thread kernel — > kernel device object — > the device name for console
[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

Modify template project

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

Change chipOptions for Target -> Device

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

Select emulators options for target – > debug – > j-link

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

Modify chip capacityOptions for Target->Utilities->Settings

[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

New project
[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

Verification Engineering

Open the new project, compile and download
[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

Operation results
[domestic MCU transplantation] transplant RT thread to domestic chip hc32f460petb

summarize experience

It was decided to take over on August 20, opened on August 21 and completed the transplantation on September 2. During this period, it took a small detour and made a lot of profits. The following points are summarized:

  1. I’ve never considered how things come from before. RTT can only be used. It’s far from being proficient. I don’t have an in-depth understanding of the function context and calling process. This transplant has a little understanding of the structure. What I want to say is that RTT architects are really heaven and man. I sigh for the view. The program architecture design is exquisite, and Daniel’s programming skills are amazing, Use it for reference in the future programming process.
  2. I just knew that Python can be used for artificial intelligence and big data processing. I usually use py + QT to write some small programs. During this migration, I finally saw the power of Py batch processing files.
  3. There are days outside the sky and people outside the people. no end for learning.
  4. Make complaints about the HC function library, and the two series of chip functions are not universal. The function of checking the library function is too painful in the process of transplantation. During this period, it was found that there were serious bugs in one RTT master and another series, so it took time to submit a pr.