Template for building STM32F0-Discovery project in GCC

Yep, that blue light is blinking and I made it happen. I’ve been hard at work since I got my free STM32F0-Discovery board in the mail. Most recently I put together a starting template for building STM32F05x project on Linux. You’ll still need to install your own tool chain (I’m using the Code Sourcery G++: Lite Edition), but this makes it a snap to compile your projects with support for STM’s peripheral libraries.

As for programming, you may remember that I added support for writing to RAM in the stlink project. I’ve wasted spent a ton of time trying to get support for writing to Flash into that project. It’s just less of a hassle to use stlink than it is to work with OpenOCD. But I’ve really hit a wall getting the flash loader code to work. If you want to check out what I’ve done so far in that area I committed a very messy branch (see the commits for what code changes I’ve made).

In the mean time you can use OpenOCD to write images compiled with the template to your device. I included the ‘make program’ option in the Makefile to do this from command line. If you need help compiling OpenOCD check the readme in the template repository.

Comments

  1. akismet-d4f06bf8cb803502684f1683ad779e95 says:

    That’s awesome Mike. Projects on the Discovery kit are showing up slowly.
    Also, I’m trying to build a small ARM community around all the Raspis, Discoveries and Beagleboards so it acts for a one stop place for all things arm.
    Link is below.

    http://forum.arm-hq.com

    You are welcome to say hi. Continue your awesome tutorials.

  2. Mathias says:

    I ordered an STM32F4 Discovery a few months ago as my first Microcontroller and I found it quite hard to use with free software on Linux. I still didn’t manage to use the STM lib with eclipse and had many problems with it in general. I recently tried chibios which seemed pretty promising especially with the hal, but it doesn’t really abstract the hardware that much, when you have to use specific register definitions that aren’t documented in the project…
    I will definitely check out your forum akismet, but is there another page with good tutorials and examples (especially) for STM32 stuff?

    • akismet-d4f06bf8cb803502684f1683ad779e95 says:

      Hi Mathias, We are still building the community up slowly. There is a discovery kits subforum if your interested. The board is fairly new and will take some time to catch on. I’m sure there will be a HAL soon enough.

      Unsure why my name came up as “akismet”, I’ll change it in my profile later.

  3. herrkami says:

    Here’s another link to a tutorial on that:

    http://www.triplespark.net/elec/pdev/arm/stm32.html

    • gabe says:

      really? that’s the length sti wants me to go? my free board will sit in a closet for way longer than i anticipated.

      • gabe says:

        …forgot to add, that despite the extra hardware, this one seems more interesting than using code sorcery shenanigans.

      • Zach Reser says:

        Not all tutorials are as epic as that one. Here’s a shorter one. (I know its windows but follow it replacing linux equivalents as you go. I did and it works nicely)

        First follow (skip requirement d & f)(make sure you apply enviroment variables when installing codesourcery):
        http://shareee.netne.net/wordpress/?p=5

        Then (make sure to setup udev rules):
        http://gpio.kaltpost.de/?page_id=148

        Setup your debugger as so (replace zach with your name of course)(Make sure to use GDB Hardware Debugging):
        GDB Command – /home/zach/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-eabi-gdb
        Port – 4242

        External tools config (location of your installed st-util):
        Location – /home/zach/stlink.git/st-util

        This isn’t a too terribly nice format, but I don’t have much time as of late to write a full tutorial. Hope this helps you out.

  4. 1one says:

    On a related note, does anyone know how to buy one of those boards without paying 20 € for shipping?

  5. Daniel H. says:

    I get some slightly different hex when compiling the flash loader in line:

    e: 60c6 str r6, [r0, #12]

    and

    18: 6906 ldr r6, [r0, #16]

    No time to test it yet…

  6. Elias Önal says:

    “Distribution of this file (unmodified or modified) is not permitted.”

    You seem to have some legal issues with the linkerscript you distribute:
    https://github.com/szczys/stm32f0-discovery-basic-template/blob/master/Device/stm32_flash.ld
    ** (c)Copyright Atollic AB.
    ** You may use this file as-is or modify it according to the needs of your
    ** project. Distribution of this file (unmodified or modified) is not
    ** permitted. Atollic AB permit registered Atollic TrueSTUDIO(R) users the
    ** rights to distribute the assembled, compiled & linked contents of this
    ** file as part of an application binary file, provided that it is built
    ** using the Atollic TrueSTUDIO(R) toolchain.

    • Mike Szczys says:

      Well isn’t that just FANTASTIC?

      Thanks for bringing it to my attention. I’ve deleted the file from the repo history. Not sure how to replace it but I’ll start learning about how to write one myself I guess.

      It’s unfortunate that STM is distributing a file with that much restriction on it along with their much-less restrictive peripheral libraries.

    • Zach Reser says:

      Don’t distribute the file but rather write instructions on how to modify the existing file a user would have if they registered True Studio . Dumb restriction but it can be bypassed. Good work on figuring it out.

  7. bflorea says:

    STM32 is a very good family from hardware perspective .. lots of power at a cost similar to the one for an 8 bit microcontroller.

  8. mupfelofen says:

    Hey there,
    that’s great work. I cleaned it up and now it fits perfectly into my own little project.

    But is there any way to compile C++ instead of C code? As long I compile it with a .cpp-extension, the LED doesn’t light up.

    Suggestions are welcome!

    Greetings
    Michael

  9. Lieven says:

    In C++ probably your interrupthandler is not called due to the name mangling that happens with c++.

    just make it extern “C”.

    just a guess, i encountered the same.

  10. I found these products to be a great deal. The Lida lida daidaihua makes me less hungry and the fat burn is helping me wipe out my flab. The instructions that came with it told me that getting my eating in check was necessary for a winning approach. I really took that to heart and have owned a lot more discipline when I am eating and the hoodia makes all that easier. I am doing sit ups and taking these products every day and so far, My flab is going away. I dont own a working scale but more than likely that things are improving.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 91,902 other followers