build your own cross-compiler !!!

I am planning to make my own compiler. I will use the following tools:
1.Eclipse + CDT + GCC 4.5.0(It support ARM cortex M3 core)
It requires the Linux environment. If you are not used to it, you can build
the virtual machine to run linux on your local system; then you can build Samba
server to communicate betweent your local system and virtual machine.
2.Eclipse + CDT + cygwin +GCC 4.5.0
It works on windows system.
I am doing these now.I build my cross-compiler on Ubuntu 10.04.
The attached file shows the procedure.
If you have any advise, can you tell me?
Thanks!
Makefile.rar (1.58 KB)

Dear all,

I hava build arm cross compiler successfully. I hava been put it in code.google.com/p/dsonano/downloads/list
You can use it freely.It support most of the arm core architecture.
If the target is arm cortex-M3, pass -mcpu=cortex-m3 and -msoft-float to GCC.
If you find any problem,please contact me.
Thanks!

Hi,
I am a proud and happy owner of a DSO Nano 2 since a few days. As long as you are aware of its limitations, it’s an awesome tool and and a fantastic gadget.

Seeing this thread, I am looking forward to be able to compile the DSO firmware using GCC. I have experience with IAR also, they are great tools from great guys and I can recommend the IAR products for anyone who wants to quickly start development. But at some point you want to use the “real” compiler, and do without any artificial limitations (like 32k code size) without shedding out $$$, especially if this is a hobby project. And most of all, to do all development on a free software platform without the hassle of wine and win32 installers.

For some hints on developing for STM32 on Ubuntu Linux, I found fun-tech.se/stm32/index.php to be a good starting point. Anyway, I started with your toolchain and tried to compile the DSO201 code. I started on a Makefile which gets most things compiled (see attachment). However, the ASM_Funtion.s file needs to be converted to gnu assembly (gas) syntax. I have found converters from intel->gas, but none for IAR syntax. Secondly, the startup code with NVIC stuff needs to be built and linked as well. This is a bit over my head right now, so please anyone help to get this further…

Cheers and thanks to everyone who contributes to DSO Nano.

Hi,
Thanks for your work. I remember IAR using the Intel assembly language format if I am not wrong. Using GCC instead of IAR, you should rewrite link script.Sorry,I am not familiar with it. Maybe someone could help. Thanks!

Progress :slight_smile: I got everything to compile and link now. The binary is huge (80k) and I have not tested it, but being able to build with no errors just by typing “make” is already something. Instead of attaching files, I have posted it here: git.debian.org/?p=users/tormod-g … ;a=summary

The gitweb interface does not treat MSDOS line terminations so well, therefore you will see \r (CR, ctrl-M) all over.

Jerry, it would be good if you can pick these two fixes to your code:

  • Fix capitalized file name of include file
  • Make assembler labels consistent and portable

I would also suggest to split ASM_Funtion.s into two files: One with the declarations of the LIB addresses (this file should be autogenerated from the LIB map files) and one with the new functions (Add_Color, Erase_Color, Get_Pixel). Renaming it to ASM_Functions.s would be nice too.

Great work Tormod :slight_smile:
I guess GCC is not very well optimized for the arm cortex m3? Is the binary stripped? Is the Thumb-2 instruction set being used?

Btw, I live in the same town as IAR and I have some friends working there :slight_smile:

The 80k was the size of the raw binary without optimization. With -Os I get 56k. Unstripped would be 130k…

But the .lst file covers addresses only from 0x8000 to 0xd32c which is only 21k so I guess the binary just has a big hole in it. Actually, by making a srec file and running srec_info I get:
Data: 008000 - 00D9A3
0159A4 - 015ABF
Using nm I can see that some initialized data is laid out at the second segment, and there is just a gap between which the binary file includes.

So effective code is under 23k. That’s not bad at all.

PS. Tell your friends to hack on gcc in their spare time :stuck_out_tongue:

Hi tormod,

Thanks for your great work. I have tried the Makefile and iar2gas script files.But now, I encountered a bit trouble.When running iar2gas, it shows “sed: -e expression #7, char 2: unterminated `s’ command”.I use Ubuntu 10.04 and your raw file from git.I have changed the /bin/sh from dash to bash, the problem is still on. Can you help me out?
Thanks.

Jerry, I guess your iar2gas file is corrupted. It is a bit tricky to download the raw file via the git web interface, especially since there is a raw \r in so it can not be copy-pasted. “Save” in Firefox works here, and also wget -O iar2gas 'http://git.debian.org/?p=users/tormod-guest/DSO-Nano.git;a=blob_plain;f=DS0201/DS0201_APP_V2.50/source/iar2gas;hb=HEAD' can do it.

But the best is to use git clone to get an exact copy of the repository.

Thanks tormod. I have compiled successfully.There is still one problem : ld: warning: cannot find entry symbol _start; defaulting to 00008000,which means the ld could not place the code correctly.Maybe we need one link script,could someone add it? Thanks.

Yes, we will need to add a linker script (often called stm32.ld) and a startup.S which defines _main. Your toolchain comes with startup code (crt.o etc) but I have not tried to link them.

EDIT: Added linker script. Will update and add startup file with vector table tonight.

Hi,
I add one link script file and startup&vector table source file.Using GCC4.5.0,I have passed the process,both compiling and linking.I put the whole project(DS0 project using GCC.rar) on code.google.com/p/dsonano/downloads/list. But there is still one problem, using DfuSe Demonstration could not make dfu file.I don’t know why.Maybe you can help me.Thanks.

Nice, I have looked at it. Maybe we can start using git, so we can track and exchange changes more easily?

Your current code does not have any startup code. I think at least there should be code to initialize the data segments. Any variables in the code which are declared with an initial non-zero value would need this.

EDIT: I mistakenly unpacked the wrong rar file and got utterly confused in my original post… Anyway, one valid question is still:

What is the licensing on these files?

I have posted my work in progress at gitorious.org/dsonano/dsonano (instead of the old URL). The only issue is overlapping .data and .init segments. I am not sure where the .init segment comes from, and I can overcome it by linking with --no-check-sections.

For making a dfu file and transferring it to the device, it will have to wait until I have access to a Windows (virtual) machine or can make a Linux dfu-util that works with the ST DFUse protocol.

Thanks,tormod.I will try to use git.
What i did before about startup code and link script like this: after CPU reset, it will jump to main function directly.It lack of some steps,such as copy data from flash to ram,init section.I will modify it later.I have tried your code, it show the following message:
arm-none-eabi-gcc -T stm32f10x_flash_offset.ld -mcpu=cortex-m3 -mthumb -o dso.elf Calculate.o Files.o Function.o HW_V1_Config.o Lcd.o main.o stm32f10x_it.o …/…/library/src/stm32f10x_flash.o …/…/library/src/stm32f10x_nvic.o …/…/library/src/stm32f10x_rcc.o ASM_Function-gcc.o cortexm3_macro.o startup_stm32f10x_md.o
/usr/arm-cross/lib/gcc/arm-none-eabi/4.5.0/…/…/…/…/arm-none-eabi/lib/thumb/crt0.o: In function change_back': /usr/src/build-newlib/arm-none-eabi/thumb/libgloss/arm/../../../../../toolchain/newlib-1.18.0/libgloss/arm/crt0.S:335: undefined reference to bss_start
/usr/src/build-newlib/arm-none-eabi/thumb/libgloss/arm/…/…/…/…/…/toolchain/newlib-1.18.0/libgloss/arm/crt0.S:335: undefined reference to __bss_end__' /usr/arm-cross/lib/gcc/arm-none-eabi/4.5.0/../../../../arm-none-eabi/lib/thumb/libc.a(lib_a-exit.o): In function exit’:
/usr/src/build-newlib/arm-none-eabi/thumb/newlib/libc/stdlib/…/…/…/…/…/…/toolchain/newlib-1.18.0/newlib/libc/stdlib/exit.c:65: undefined reference to `_exit’
collect2: ld returned 1 exit status
Do you have the same problem?
PS, what about GPL on these files?

Yes, I had some errors like that when using your toolchain. Then I switched to the CodeSourcery toolchain release instead. I downloaded arm-2010q1-188-arm-none-eabi-i686-pc-linux-gnu.tar.bz2 from codesourcery.com/sgpp/lite/a … elease1294

Sorry,maybe my configuration of newlib misses something.I will use Sourcery G++ instead.

The section overlap errors I had earlier was because the .init and .fini sections (defined by the gcc startup code, and potentially used in the source code but not in our case) had not been defined in the linker script. I added them and the errors went away.

However, after checking the .lst file I got convinced that the added startup code did not do anything useful so I added -nostartfiles instead. Theoretically, use of standard library functions (newlib) could need specific startup initialization, but not here AFAICS.

Hi,tormod.
I have converted the final hex to dfu.After upgrade, restart the DSO, it just shows the lib hint message : DSO201 Oscilloscope LIB Ver2.22. I think it occurs section overlap. We need to modify the link script.

I also tried flashing and had the same result as you, both with or without startup code. Maybe there is a conflict with code in the LIB. I realize that it will be just a waste of time to try to make something work together with a closed-source component. So I will either go back to the free 1.1 version or wait for you (or BenF) to release some more code :slight_smile:

Meanwhile I will look at making a dfuse firmware loader for Linux so that we will not need a Windows machine or license to flash the DSO. Hopefully it will be enough to modify the dfu-util a bit. Probably someone has done this already, but I haven’t found any published code.