Which version of arm gnu toolchain should I use to run on Rpi 4B?

Viewed 47

I want to use Raspberry Pi 4B to compile code for stm32. Therefore I download the "AArch64 Linux hosted cross toolchains" version of arm-none-eabi from this website. Then I scp to Rpi and unzip it.

But I cannot execute it. The shell told me that cannot execute binary file: Exec format error. Did I download the worng version?

The architecture of Rpi is "armv7l" and the OS I'm using is Pi OS(buster). I thought it belongs to "AArch64 Linux hosted".

Thank you ~

2 Answers

That is ARM v7 architecture. IIRC, the raspi hardware is armv8 capable machines, but RPI OS runs in aarch32 mode, which is compatibility mode for armv7. You can also check cpuinfo to be sure about it.

On an ARMv7 kernel/OS(aarch32), armv8 applications cannot be run, but on armv8(aarch64) kernel/OS armv7 applications can be run in aarch32 mode. Refer ARM's Learn the architecture: Aarch64 Exception Model for more details.

pi@raspberrypi:~ $ cat /proc/cpuinfo
processor       : 0
model name      : ARMv7 Processor rev 3 (v7l)
BogoMIPS        : 108.00
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3

processor       : 1
model name      : ARMv7 Processor rev 3 (v7l)
BogoMIPS        : 108.00
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3

the stm is either armv6-m, arv7-m or one of the armv8-ms. The pi itself is armv8. You either need to run the pi in 32 bit aarch32 mode and use a native compiler or use a cross compiler. aarch64 is armv8-a (arm 64 bit, the armv7-a is the aarch32 compatibility mode).

So you will want to get arm-none-eabi, which you claim but you also claimed aarch64 if it were aarch64 then it would be aarch64-none-eabi or some such name.

Like any other computer you can just get or build for (not hard to build gnu toolchain from sources) arm (32 bit) and get the one that can build for stm32.

gcc version 3.x.x to the present, technically, can build code that will run on an stm32.

If you plan to use a C library then even though you can use the native toolchain on an armv7 based linux on the pi, it is arm-whatever-linux-gnueabi not arm-whatever-eabi and may not work for you.

Just get arm-none-eabi based toolchain, use the proper command line options, and be done with it.

Related