1750 views|2 replies

71

Posts

0

Resources
The OP
 

RISC-V MCU Development (IV): Compilation Configuration [Copy link]

In embedded development, after we have completed the project creation, code editing and other operations, we can start the project compilation. For projects created using built-in project templates or imported externally, MounRiver Studio (MRS) will automatically configure the target tool chain (riscv-none-embed-gcc or arm-none-eabi-gcc) according to the corresponding chip core. At the same time, the compilation configurations such as the target platform, optimization level, debugging level and file references will also be automatically set.

How to obtain the latest MRS V1.51 installation package: www.mounriver.com .

[Project Property Page] Select the project to be compiled in the Explorer window, click the project property configuration button on the toolbar, or click "Properties" in the right-click menu to enter the compilation option property page.

[Target processor] is used to specify parameters such as target instruction architecture and extended functions.

  • Architecture is the instruction set architecture, rv32i is the RISC-V basic integer instruction set
  • RVM means support for multiplication and division extensions, RVA means support for atomic extensions, RVF means single-precision floating-point extensions, RVD means double-precision floating-point extensions, and RVC means compressed instruction extensions.
  • Integer ABI is the RISC-V application integer binary interface, and Floating point ABI is the RISC-V application floating point binary interface. The RISC-V compiler supports multiple ABIs , depending on whether the F and D extensions are present. The ABIs for RV32 are named ilp32 , ilp32f , and ilp32d . ilp32 means that the C language integer ( int ), long integer ( long ), and pointer ( pointer ) are all 32 bits, and the optional suffix indicates how to pass floating point parameters. In ilp32 , floating point parameters are passed in integer registers; in ilp32f , single-precision floating point parameters are passed in floating point registers; in ilp32d , double-precision floating point parameters are also passed in floating point registers. Naturally, if you want to pass floating point parameters in floating point registers, you need to add the F or D extension to the corresponding floating point ISA . Therefore, to compile code for RV32I ( GCC option -march=rv32i ), you must use the ilp32 ABI ( GCC option -mabi=ilp32 ). In turn, the calling convention does not require floating-point instructions to use floating-point registers, so RV32IFD is compatible with ilp32 , ilp32f , and ilp32d .
  • Tuning optimizes the output of a given processor by microarchitecture, the default is rocket.
  • Code model has two main modes:

-mcmodel=medlow : The program and its statically defined symbols must be located within a single 2 GiB address range, and must be located between absolute addresses -2 GiB and +2 GiB. The program may be linked statically or dynamically. This is the default code model.

-mcmodel=medany : The program and its statically defined symbols may be located in any single 2 GiB address range. The program may be linked statically or dynamically.

  • In Align , -mstrict-align -mno-strict-align depends on whether the processor supports unaligned memory access.
  • Small data limit on some targets puts global and static variables smaller than n bytes into a special segment.

[Optimization level] mainly configures GCC's optimization options. If you want to add other optimization options, you can write them in the other optimization flags below.

  • -O0: No optimization (default)
  • -O , -O1: Use optimizations that reduce target file size and execution time without significantly increasing compile time. This can significantly increase compile-time memory usage when compiling large programs.
  • -O2: Includes the optimizations of -O1 and adds optimizations that do not require a trade-off between object file size and execution speed. The compiler does not perform loop unrolling or function inlining. This option will increase compilation time and object file execution performance.
  • -Os: Optimizes the target file size specifically, executes all -O2 optimization options that do not increase the target file size. And executes optimization options that specifically reduce the target file size.
  • -O3: Turn on all -O2 optimization options and add some parameters.

【Warning Level】is used to set the warning parameter options of GCC.

  • -fsyntax-only : Check your code for syntax errors, but don't do anything else.
  • -fmax-errors= n : Limit the maximum number of error messages to n that GCC caches instead of trying to continue processing the source code. If n is 0 (the default), an unlimited number of error messages are generated. If -Wfatal-errors is also specified, fatal errors take precedence over this option.
  • -w : Suppress all warning messages.
  • -Werror : turn all warnings into errors
  • -pedantic : Enable all warnings listed in the ANSI/ISO C standard
  • -pedantic-errors : Enable ANSI/ISO C standard errors.
  • -Wfatal-errors : Stop at the first error to reduce the time of finding errors

[Debug Level] The -g in the red box sets the GDB debugging information. Note that when generating a static library, set the -g in the red box to None, otherwise the generated library will contain debugging information, resulting in an overly large library file.

[Add assembly and header files] The positions in the red boxes are respectively for adding assembly and header file interfaces. Click the green plus sign on the right box to add the file path.

[Add link script file] The positions in the red box are the interfaces for adding link script files. Click the green plus sign on the right box to add the file path.

【Library file addition】

-L adds the path of the library file, -l adds the library name. Note that the prefix and suffix of the library name should be removed. For example, libtest.a only needs to fill in test.

[Link other files] Other objects can add .o or .lib files that you want to participate in the link.

[Output file format] In the red box on the right, you can click the drop-down box to select BIN file or HEX file to output after compilation.

[Output Type] You can choose to generate an executable file or a static library file in the icon location.

The above is the commonly used compilation configuration of MRS. The files generated after compilation will be stored in the obj file in the project directory, among which the .list and .map files can be used for program analysis.

This post is from MCU

Latest reply

Thanks for sharing! I learned a lot.   Details Published on 2021-9-27 18:04
 

7452

Posts

2

Resources
2
 

Thanks for sharing! I learned a lot.

This post is from MCU

Comments

Haha, this is a little experience in the development of RISC-V core MCU. I look forward to making progress together.  Details Published on 2021-9-28 09:43
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 

71

Posts

0

Resources
3
 
freebsder posted on 2021-9-27 18:04 Thank you for sharing! I learned a lot.

Haha, this is a little experience in the development of RISC-V core MCU. I look forward to making progress together.

This post is from MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

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