2484 views|3 replies

1370

Posts

2

Resources
The OP
 

Command line compilation of SDK example projects (blinky) [Copy link]

 

  The official development environment of RSL10 is based on Ecipse, so there is no doubt that the SDK supports GCC. After downloading the pack of RSL10 (this is a compressed file, just use the tool to unzip it), you can see that there are many examples in the source\samples directory. In addition to ON IDE project files, Keil and IAR project files are also provided. I am used to using the command line to compile manually, so I have to dissect the example project. Let's start with the simplest blinky (presumably the LED blinking function):

The Blink project has little code, just one C source file and one .h header file in the include directory. However, the header files that are required for compilation and the implementation of the functions that are called are all in the SDK. In addition to the program source files, the project also has several configuration files, which are XML format files for Eclipse and can also be read.

  Try compiling app.c with arm-none-eabi-gcc -c -march=cortex-m3 -mthumb. GCC will report that it can't find the header file rsl10.h . Look for it in the include directory of the SDK (the .pack compressed file), so copy it, for example, into an inc subdirectory. Compile again, and it will report an error, and another header file can't be found. You can copy all the files in the include directory of the SDK at once, regardless of whether they are used or not; you can also copy the files that are missing, so as to see how many dependencies are needed.

  In fact, there are quite a few, but even if the file inclusion of the include directory is resolved, there are still many compilation errors and missing macro definitions. Note that the first error is:

error: #error RSL10_CID must be defined

  How to define RSL10_CID is to look for clues in the project file. Search in the .cproject file and find the following:

<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnuarmeclipse.managedbuild.cross.....

<listOptionValue builtIn="false" value=" RSL10_CID=101 "/>
<listOptionValue builtIn="false" value=" _RTE_ "/>
</option>

  It seems that these two macros need to be defined, and they can be specified using the -D parameter on the GCC command line.

  There is another compilation error that printf.h cannot be found. Search and find a printf.c file in the source/firmware/printf directory of the SDK. Copy these two files and put them in a sys subdirectory. Then, use the command line

arm-none-eabi-gcc -c -Iinc -Isys -mcpu=cortex-m3 -mthumb -O2 -DRSL10_CID=101 -D_RTE_ app.c
can compile app.c into app.o.

  Then, you cannot get app.elf by just using app.o. You also need the SDK library's function support. For example, the link will report an error saying that SystemCoreClock does not exist. The SDK provides the implementation of this function. In which C file is it? You can use tools such as find and grep to find it. It is not difficult. However, the project file already contains this information, and it is automatically used when using the IDE environment. In the blinky.rteconfig file, there are these lines:

      <file category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_romvect.c"/>
      <file category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_sys_asrc.c"/>
      <file category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_sys_audio.c"/>
      <file category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_sys_clocks.c"/>
      <file category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_sys_crc.c"/>
      <file category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_sys_dma.c"/>
      <file category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_sys_flash.c"/>
      <file category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_sys_power.c"/>
      <file category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_sys_power_modes.c"/>
      <file category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_sys_rffe.c"/>
      <file category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_sys_timers.c"/>
      <file category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_sys_uart.c"/>
      <file category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_sys_version.c"/>
      <file attr="config" category="source" deviceDependent="1" name="source/firmware/syslib/code/rsl10_protocol.c" version="3.1.573"/>

  It is easy to understand that there are several files in the source/firmware/syslib/code directory of the SDK that need to be compiled and linked together. Just use the GCC command line to process them separately. Of course, it is not necessary to compile them one by one manually. It is best to write them into a Makefile.

  The startup file, including the interrupt vector table, must also be linked. There is a startup_rsl10.S assembly file in the firmware/cmsis/sources/GCC directory of the SDK, which can be assembled using the gcc command.

  Then link these compiled target files (.o files) together, use gcc to indirectly call ld, and use the -T parameter to specify the sections.ld file (in the firmware/cmsis/source/GCC directory of the SDK. This file provides important information such as the address where the code is stored and the address where the RAM is located, which must be used for MCU program development). At this time, the error message still appears: _exit cannot be found.

  Generally, the exit function is not used in MCU programs. This function is in the C runtime library. Adding the -nostartfiles option will not link several default target modules of the C library. In this way, the error that _start cannot be found is reported again. Note that there is also

      <file category="source" condition="GCC_Condition" deviceDependent="1" name="source/firmware/cmsis/source/sbrk.c"/>
      <file category="source" condition="GCC_Condition" deviceDependent="1" name="source/firmware/cmsis/source/start.c"/>
      <file attr="config" category="source" deviceDependent="1" name="source/firmware/cmsis/source/system_rsl10.c" version="1.0.0"/>

  You also need to compile the three files sbrk.c start.c system_rsl10.c separately and then link them.

  Write a Makefile as follows:

default: app.elf

INC = -Iinc

APP_OBJ = app.o

APP_OPTS = -DRSL10_CID=101 -D_RTE_

SYSOBJ = rsl10_romvect.o \
	rsl10_sys_asrc.o \
	rsl10_sys_audio.o \
	rsl10_sys_clocks.o \
	rsl10_sys_crc.o \
	rsl10_sys_dma.o \
	rsl10_sys_flash.o \
	rsl10_sys_power.o \
	rsl10_sys_power_modes.o \
	rsl10_sys_rffe.o \
	rsl10_sys_timers.o \
	rsl10_sys_uart.o \
	rsl10_sys_version.o \
	rsl10_protocol.o \
	system_rsl10.o \
	startup_rsl10.o \
	start.o \
	sbrk.o

CFLAGS = $(INC) -mcpu=cortex-m3 -mthumb -O2 $(APP_OPTS)

LDFLAGS = -Tsections.ld -nostartfiles

%.o : %.c
	arm-none-eabi-gcc -c -Isys $(CFLAGS) $<

%.o : sys/%.c
	arm-none-eabi-gcc -c $(CFLAGS) $<

%.o : sys/%.S
	arm-none-eabi-gcc -c $(CFLAGS) $<

app.elf : $(APP_OBJ) $(SYSOBJ)
	arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb $^ $(LDFLAGS) -o $@

  In this way, executing the make command can complete the compilation.

  Then use arm-none-eabi-objcopy to generate a .hex or .bin file from the elf file, and burn it to the board via Jlink. Then you can see the LED flashing.

  *In fact, the C files listed in this example project file are redundant. Among the rsl10_sys_xxxx files, only rsl10_sys_dma.c is enough, because system_rsl10.c calls a DMA function. If you modify it yourself, you can remove it.

Latest reply

Thanks for sharing  Details Published on 2021-5-14 18:42
 
 

1662

Posts

0

Resources
2
 

This method of writing Makefile is very good.

The host is very experienced and the introduction is also detailed.

 
 
 

7422

Posts

2

Resources
3
 

make the law perfect

Personal signature

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

 
 
 

824

Posts

190

Resources
4
 
Thanks for sharing
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
 
 
 

Guess Your Favourite
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