cortex m3 stm32 with gcc 4.3.1 on mac os x?

Everything ARM and LPC

Moderator: phalanx

Post Reply
harold
Posts: 2
Joined: Tue Aug 26, 2008 9:10 pm

cortex m3 stm32 with gcc 4.3.1 on mac os x?

Post by harold » Tue Aug 26, 2008 9:22 pm

I just got my stm32 and ideally would like to program it from my Mac. Has anyone gotten this to work? I think it should be possible as of gcc 4.3, which claims to support ARMv7/Thumb2 directly.

I've tried compiling gcc with various --target=... and --disable-... options, but I'm basically just guessing and always run into trouble. So if anyone here has already succeeded I'd love to know your methods.

Thanks!

inventore123
Posts: 257
Joined: Sat Aug 18, 2007 5:41 am

Post by inventore123 » Thu Aug 28, 2008 11:48 am

Maybe you can find this thread useful:
viewtopic.php?t=8923

BusError
Posts: 54
Joined: Mon Apr 14, 2008 5:29 am
Location: Berkshire, UK

Post by BusError » Fri Aug 29, 2008 5:32 am

I managed to build CodeSourcery Lite 2008q1 on Leopard, and I use to to program Stellaris targets (Cortex M3)
The process to build the toolchain is nowhere near trivial, but it works in the end. You can lift most of the needed 'configure' options from the CodeSourcery useless build script too.

denial
Posts: 113
Joined: Sun Apr 27, 2008 12:42 am
Location: 51.5°N 9.9°E

Post by denial » Fri Aug 29, 2008 10:18 am

To build GCC for Cortex-M3 first build Binutils with

Code: Select all

--target=arm-elf
Then configure GCC with

Code: Select all

--target=arm-elf --with-cpu=cortex-m3 --with-tune=cortex-m3 --with-mode=thumb --with-float=soft --disable-libssp
This will ensure that libgcc.a is optimized for Cortex-M3 and that you later don't need to pass -mcpu=cortex-m3 and -msoft-float to GCC.
It will prevent libgcc from being build in non-thumb mode, though.
Libssp needs the target's C header files to build, so it's easier to disable it.

If you get any error, post it. You might miss some prerequisites on OS X.

inventore123
Posts: 257
Joined: Sat Aug 18, 2007 5:41 am

Post by inventore123 » Fri Aug 29, 2008 11:58 am

Have you installed Xcode? if I remenber correctly, when installing it there's an option that allow installing gcc, binutils ... in the standard Unix/Linux directory /usr. You must check this option.
This is because you need gcc for your platform to compile the gcc cross compiler.

pburgess
Posts: 7
Joined: Tue Sep 23, 2008 10:35 pm

Post by pburgess » Tue Sep 23, 2008 10:46 pm

This page may provide some insight on building the CodeSourcery ARM compiler (GCC 4.2-derived) on Mac OS X:

http://www.paintyourdragon.com/uc/osxstm32/index.html

The page is focused on the STM32 Primer, but the compiler-building parts will likely still apply. Linking device-specific libraries and transferring compiled code to the device in question will be a different matter.

I've tried building a 4.3 compiler on OS X, but kept hitting walls...I don't think all of the Thumb2 changes have fully made it back into the official GCC releases yet. A CodeSourcery "q3" release will probably be along in a matter of weeks, and I'd be very surprised if it did not include a later GCC version. But for now the "q1" release is your best bet.

denial
Posts: 113
Joined: Sun Apr 27, 2008 12:42 am
Location: 51.5°N 9.9°E

Post by denial » Wed Sep 24, 2008 4:43 am

pburgess wrote:I've tried building a 4.3 compiler on OS X, but kept hitting walls...
Can you describe that wall?
My instructions from above in Linux result in a functioning compiler.
I don't think all of the Thumb2 changes have fully made it back into the official GCC releases yet.
So it generates invalid code?

harold
Posts: 2
Joined: Tue Aug 26, 2008 9:10 pm

Post by harold » Wed Oct 08, 2008 2:38 pm

thanks for all the help everyone!

i got busy for a while, so i only just had a chance to try this again and i got it working!

one big difference is that i have an intel mac with OS X 10.5 now (previously had a G4 with 10.4) which makes building everything actually work as opposed to having endless confusing errors.

so anyway for posterity here's everything i did to get it working:


1. I downloaded a prebuilt arm-GCC from http://www.paintyourdragon.com/uc/osxstm32/ (thanks pburgess!), which is basically just a prebuilt CodeSourcery distribution.

2. then I downloaded the D2XX drivers from http://www.ftdichip.com/Drivers/D2XX.htm and installed them as per the included readme

3. then built OpenOCD as per http://openfacts.berlios.de/index-en.ph ... ng_OpenOCD with the configure option --enable-ft2232_ftd2xx

4. then made an openocd.cfg file for the STM32 / ARM-USB-TINY combination, based on /usr/local/lib/openocd/interface/olimex-jtag-tiny-a.cfg and /usr/local/lib/openocd/target/stm32.cfg which were almost correct but needed the TINY's product id and needed to specify the offset and size of the flash address bank. the resulting openocd.cfg file:

Code: Select all

# REFERENCE:  http://www.olimex.com/dev/arm-usb-tiny.html
interface ft2232
ft2232_device_desc "Olimex OpenOCD JTAG TINY A"
ft2232_layout olimex-jtag
ft2232_vid_pid 0x15ba 0x0004


# script for stm32

# jtag speed
jtag_khz 500

jtag_nsrst_delay 100
jtag_ntrst_delay 100

#use combined on interfaces or targets that can't set TRST/SRST separately
reset_config trst_and_srst

#jtag scan chain
#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask, IDCODE)
jtag_device 4 0x1 0xf 0xe
jtag_device 5 0x1 0x1 0x1e

#target <type> <startup mode>
#target arm7tdmi <reset mode> <chainpos> <endianness> <variant>
target cortex_m3 little 0


working_area 0 0x20000000 16384 nobackup

#flash bank str7x <base> <size> 0 0 <target#> <variant>
flash bank stm32x 0x08000000 0x20000 0 0 0

# For more information about the configuration files, take a look at:
# openocd.texi
5. lastly i found a simple blinking light example:
http://www.siwawi.arubi.uni-kl.de/avr_p ... tm32_blink

i changed the PC4 led pin in main.c to PC12 (the Olimex STM32-H103 board's led pin), ran make, and plugged the programmer USB in as well as the board USB (for power).

finally, I ran openocd with my openocd.cfg file from above, telnetted to localhost:4444, and ran the commands:

Code: Select all

halt
stm32x mass_erase 0
flash write_bank 0 main.bin 0
reset
And the light blinked! So, next time I have some time I can hopefully do something more substantial...

gregson
Posts: 28
Joined: Mon Apr 14, 2008 12:58 pm

gcc for ARM Cortex-M3 on Mac - a question

Post by gregson » Sun Dec 28, 2008 2:52 pm

Last summer I installed the gnu gcc toolchain with openocd on a Windows box successfully, but it required Lanchon's mods to make it work.

Am I to understand from the posts in this forum that Lanchon's mods are no longer necessary for installation of the toolchain on a Mac? If I recall correctly, Lanchon's mods were required for the startup code and for floating point. libcs3 sources were not available, and Lanchon created equivalent ones from scratch. Does the Codesourcery Lite distribution now contain the working code?

I will be running my code on an embedded system that starts cold, so I need startup code to set stack pointers and the like, or I need to know that I must write it.

Best regards,

Peter

Post Reply