9

I'm trying to get started with the STM32 (Cortex-M3) and my plan is get this working from Ubuntu (9.04 / AMD64).

To start with I got the Olimex stm32-h103 header board and the Olimex ARM-USB-OCD jtag, and on to of that I will probably use OpenOCD, gcc and Eclipse.

But right now I'm looking into what version of gcc to use and how to setup that to be able to crosscompile the code.

There seem to be some arm projects out there but I don't know what to start with, can somebody push me in the right direction?

Thanks Johan


Update: There seems almost to be what I want from codesourcery, but they seem to focus on IA32 and not AMD64.

However in the supported devices I find the Cortex-M3

  • ARM EABI, ARM M-profile Simulator -mcpu=cortex-m3 -mthumb

Update: There is a possibility to install IA32 on AMD64, so maybe the marked answer is obsolete already.

Update: Found this link about crosscompile for the Cortex-M3.

artless noise
  • 21,212
  • 6
  • 68
  • 105
Johan
  • 20,067
  • 28
  • 92
  • 110
  • See http://stackoverflow.com/questions/1523810/toolchain-for-any-arm-processor/1523907#1523907 – themis Oct 21 '09 at 08:10
  • Buildroot is good for bigger arm:s, like ARM9,ARM11, Cortex-A8 (and if you want to run Linux on it). But not for the MCU style Cortex-M3 (that is more like ARM7). But thanks anyway. – Johan Oct 21 '09 at 14:46
  • 1
    The link you have there is no longer correct after we restructured the eLua site, you can find the same page here: http://www.eluaproject.net/en_tc_cortex.html FYI, I have some separate instructions that work for building CodeSourcery's toolchain for 64-bit on OS X. It may not be too hard to adapt them to work on Linux as well: http://fanplastic.org/gcc-for-arm-eabi/ – James Snyder Dec 02 '09 at 14:22
  • It's also worth noting that, since Ubuntu 64-bit installations can run 32-bit applications, CodeSourcery's tools should have no problems running on your Ubuntu/AMD64 installation. (Disclaimer: I'm a CodeSourcery employee.) – Brooks Moses Mar 25 '10 at 23:13
  • Thanks for the note on AMD64, I updated the question with the info. – Johan Mar 26 '10 at 05:08

1 Answers1

6

Since this answer became a little bit "unreadable", I created a page with this info.



This is a free interpretation based on these two guides, but I had to change versions and apply some patches to get it to work.

First some basic stuff

sudo apt-get install flex bison libgmp3-dev libmpfr-dev autoconf texinfo build-essential

Then I created a place to store the toolchain (change cj.users to whatever is good for you).

export TOOLPATH=/usr/local/cross-cortex-m3
sudo mkdir /usr/local/cross-cortex-m3
sudo chown cj.users /usr/local/cross-cortex-m3

Binutils

wget http://ftp.gnu.org/gnu/binutils/binutils-2.19.tar.bz2
tar -xvjf binutils-2.19.tar.bz2
cd binutils-2.19
mkdir build
cd build
../configure --target=arm-none-eabi --prefix=$TOOLPATH --enable-interwork --enable-multilib --with-gnu-as --with-gnu-ld --disable-nls

Apply patch to tc-arm.c according this info http://sourceware.org/bugzilla/show_bug.cgi?id=7026 / http://sourceware.org/bugzilla/attachment.cgi?id=3058&action=view

vi ../gas/config/tc-arm.c


make 
make install
export PATH=${TOOLPATH}/bin:$PATH
cd ../..

gcc

wget ftp://ftp.sunet.se/pub/gnu/gcc/releases/gcc-4.3.4/gcc-4.3.4.tar.bz2
tar -xvjf gcc-4.3.4.tar.bz2
cd gcc-4.3.4
mkdir build
cd build
../configure --target=arm-none-eabi --prefix=$TOOLPATH --enable-interwork --enable-multilib --enable-languages="c,c++" --with-newlib --without-headers --disable-shared --with-gnu-as --with-gnu-ld
make all-gcc
make install-gcc
cd ../..

Newlib

wget ftp://sources.redhat.com/pub/newlib/newlib-1.17.0.tar.gz
wget http://www.esden.net/content/embedded/newlib-1.14.0-missing-makeinfo.patch
tar -xvzf newlib-1.17.0.tar.gz
cd newlib-1.17.0

Then I would like to apply the patch with something like this (but it did not work)

patch -p1 -i ../newlib-1.14.0-missing-makeinfo.patch

So I opened it manually and edited line 6651 according to the patch.

vi configure

mkdir build
cd build
../configure --target=arm-none-eabi --prefix=$TOOLPATH --enable-interwork --disable-newlib-supplied-syscalls --with-gnu-ld --with-gnu-as --disable-shared
make CFLAGS_FOR_TARGET="-ffunction-sections -fdata-sections -DPREFER_SIZE_OVER_SPEED -D__OPTIMIZE_SIZE__ -Os -fomit-frame-pointer -mcpu=cortex-m3 -mthumb -D__thumb2__ -D__BUFSIZ__=256" CCASFLAGS="-mcpu=cortex-m3 -mthumb -D__thumb2__"
make install
cd ../..

More gcc

cd gcc-4.3.4/build
make CFLAGS="-mcpu=cortex-m3 -mthumb" CXXFLAGS="-mcpu=cortex-m3 -mthumb" LIBCXXFLAGS="-mcpu=cortex-m3 -mthumb" all
make install

Sum up

Now I just added some paths to my ~/.bashrc

#STM32 gcc...
export TOOLPATH=/usr/local/cross-cortex-m3
export PATH=${TOOLPATH}/bin:$PATH

And I should be ready for the next step...

Johan
  • 20,067
  • 28
  • 92
  • 110
  • 1
    Thank you very much for posting this. I've been trying to work out how to build for Cortex M3 chips for ages. I was going through my old favourited questions and found this one, which I'll be using as essentially all my reference. Thanks again! – Bojangles Dec 25 '11 at 19:45