Page 1 of 1

Compile Cortex-M3 code on Raspberry Pi 3

Posted: Tue Dec 27, 2016 2:08 pm
by Fulcrum Mike
Hi guys,

I can compile Chibios code for STM32F103 successfully on my main desktop (x86).

I want to compile code for STM32F103 based board on Raspberry Pi. I have installed GCC on raspberry pi, so I should be able to compile for STM32F103 since gcc on raspberry pi supports these architectures (I believe Cortex-M3 belongs to armv7-m):

https://gcc.gnu.org/onlinedocs/gcc/ARM-Options

Code: Select all

‘armv2’, ‘armv2a’, ‘armv3’, ‘armv3m’, ‘armv4’, ‘armv4t’, ‘armv5’, ‘armv5e’, ‘armv5t’, ‘armv5te’, ‘armv6’, ‘armv6-m’, ‘armv6j’, ‘armv6k’, ‘armv6kz’, ‘armv6s-m’, ‘armv6t2’, ‘armv6z’, ‘armv6zk’, ‘armv7’, ‘armv7-a’, ‘armv7-m’, ‘armv7-r’, ‘armv7e-m’, ‘armv7ve’, ‘armv8-a’, ‘armv8-a+crc’, ‘armv8.1-a’, ‘armv8.1-a+crc’, ‘armv8-m.base’, ‘armv8-m.main’, ‘armv8-m.main+dsp’, ‘iwmmxt’, ‘iwmmxt2’.


But issuing the 'make' commands says
arm-none-eabi-gcc: Command not found


So I changed TRGT variable in Makefile as:

Code: Select all

# Compiler settings
#

MCU  = cortex-m3

#TRGT = arm-elf-
##TRGT = arm-none-eabi-
TRGT =       #### Changed TRGT
CC   = $(TRGT)gcc -march=armv7-m
CPPC = $(TRGT)g++
# Enable loading with g++ only if you need C++ runtime support.
# NOTE: You can use C++ even without C++ support if you are careful. C++
#       runtime support makes code size explode.
LD   = $(TRGT)gcc
#LD   = $(TRGT)g++
CP   = $(TRGT)objcopy
AS   = $(TRGT)gcc -x assembler-with-cpp
AR   = $(TRGT)ar
OD   = $(TRGT)objdump
SZ   = $(TRGT)size
HEX  = $(CP) -O ihex
BIN  = $(CP) -O binary


With this change I can get past the arm-none-eabi-gcc not found error. But then this error appears:

../../../os/common/ext/CMSIS/include/core_cm3.h:142:6: error: #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
^~~~~
make: *** [../../../os/common/startup/ARMCMx/compilers/GCC/rules.mk:223: build/obj/crt1.o] Error 1


I tried adding '-mfloat-abi=soft' to gcc, yet it causes another error:

from ../../../os/common/startup/ARMCMx/compilers/GCC/crt1.c:27:
/usr/include/gnu/stubs.h:7:29: fatal error: gnu/stubs-soft.h: No such file or directory
# include <gnu/stubs-soft.h>
^
compilation terminated.
make: *** [../../../os/common/startup/ARMCMx/compilers/GCC/rules.mk:223: build/obj/crt1.o] Error 1


I also noticed that the Makefile already contains:

Code: Select all

# Enables the use of FPU (no, softfp, hard).
ifeq ($(USE_FPU),)
  USE_FPU = no
endif


I have used all my computer-fu skills and can't solve the issue. Any help would be appreciated.

Re: Compile Cortex-M3 code on Raspberry Pi 3

Posted: Tue Dec 27, 2016 2:13 pm
by Giovanni
Hi,

The GCC for embedded targets is not the same GCC in your average Linux distribution, you should use a specific compiler: arm-none-eabi-

Giovanni

Re: Compile Cortex-M3 code on Raspberry Pi 3

Posted: Tue Dec 27, 2016 2:25 pm
by Fulcrum Mike
Thanks for the prompt reply.

Any chance you could point me regarding how to install arm-none-eabi on raspberry pi? I can't even find arm-none-eabi source code for Raspberry pi (armv7-h), and my current repo (Arch Linux ARM) doesn't provide package for arm-none-eabi-gcc.

Re: Compile Cortex-M3 code on Raspberry Pi 3

Posted: Tue Dec 27, 2016 5:22 pm
by barthess
It is very strange decision to use RPi as build host but you can try to build (using RPi as build host) gcc from sources https://launchpad.net/gcc-arm-embedded/ ... rc.tar.bz2

Re: Compile Cortex-M3 code on Raspberry Pi 3

Posted: Sun Jan 01, 2017 7:37 pm
by Fulcrum Mike
Thanks for the info.

It was more of a proof-of-concept thing. I like to develop on Linux yet I also have to run Windows for games and stuff. I was just checking if I could use rpi for development to avoid dual booting my pc.

I tried to install arm-none-eabi from source. But a lot of dependencies for arm-none-eabi-gcc were missing in ArchLinuxARM repositories. It sounded like a lot of work to compile arm-none-eabi on ArchLinuxARM. I instead switched to Raspbian, as they provide prepackaged arm-none-eabi in official repos.

Cheers

Re: Compile Cortex-M3 code on Raspberry Pi 3

Posted: Mon Jan 02, 2017 1:20 am
by DeusExMachina
Fulcrum Mike wrote:Thanks for the info.

It was more of a proof-of-concept thing. I like to develop on Linux yet I also have to run Windows for games and stuff. I was just checking if I could use rpi for development to avoid dual booting my pc.

I tried to install arm-none-eabi from source. But a lot of dependencies for arm-none-eabi-gcc were missing in ArchLinuxARM repositories. It sounded like a lot of work to compile arm-none-eabi on ArchLinuxARM. I instead switched to Raspbian, as they provide prepackaged arm-none-eabi in official repos.

Cheers


I guess that the compilation time is quite long... Is it really a functional configuration for the actual work? I am considering a small fanless computer because sometimes I get a headache from the PC fans.

Re: Compile Cortex-M3 code on Raspberry Pi 3

Posted: Mon Jan 02, 2017 5:18 pm
by Fulcrum Mike
As a test, I compiled demos/RT-STM32F407-DISCOVERY project on rpi-3 (running headless Raspbian Lite) and my PC (AMD X4 760K @ 3.8GHz, 8GB, 2TB).

Here are the compilation times:

Rpi-3 (Running SSH only):

Code: Select all

real    0m33.638s
user    0m29.830s
sys     0m1.910s


PC (Running 3 Vim, ~25 chromium tabs, openocd, telnet, picocom, 5 xterm, i3wm):

Code: Select all

real    0m5.485s
user    0m4.323s
sys     0m0.543s


If you consider running Rpi3 as a proper desktop, you'll be using xserver, some editor, some debugger and may be a web/file browser for datasheets and stuff. Running all this stuff is going to have further toll on compilation time. For the time being, I'll stick to my PC.

Hope it helps :)

Re: Compile Cortex-M3 code on Raspberry Pi 3

Posted: Tue Jan 03, 2017 4:46 pm
by Giovanni
I found this one: https://www.kickstarter.com/projects/17 ... rmance-pl/

It looks like real ARM-based PC are not that far away.

Giovanni

Re: Compile Cortex-M3 code on Raspberry Pi 3

Posted: Tue Jan 03, 2017 5:42 pm
by barthess
Looks powerful, but video drivers shit the bed. On all such boards. They are always proprietary and always bounded to ancient kernel/xorg.