Monday, June 11, 2012

STM32f0 Discovery Board with Keil

I applied for and got a STM32F0DISCOVERY board from STmicro which is based on the STM32F051R8 ARM Cortex-M0 MCU and ST-Link. I didn't really expect STmicro to actual give me one of these for free, as i am a hobbyist, and was amazed when it came in the mail; I didn't even know what i was going to use it for :).

The first the thing I needed was a IDE. I was going for a open source portable option like Eclipse with a Code Sourcery G++ compiler, but i could never get the tutorial to work! Some other free good IDEs are FreeRTOS, CoCox, and Keil AMR. I first tried Keil first, and it works fairly well, so, i think i'll keep it. Whatever ARM you have, its always good to get the ST-Link Utility(if you have a ST-Link), the standard peripheral library, and the example package(those links are for the STM32F051R8).

Keil Setup
First you need to download and install it. It's as simple as that; no tinkering with compilers etc. Then you need to create a new project by clicking Project-> New uVision Project. Then create a new folder to hold your project files; in there is where you save the new uVision project file from dialog that is opened when you click new project. Select the processor you use in the window that pops up next.

Next, it will ask if you want to import the startup file; you do.

Next, you go to the project folder and create a main.c file and add  it to the project by right clicking on Source Group 1 and clicking "Add files to..." and select main.c

Then, in the standard peripheral, or discovery firmware project, folder copy the files inside the include and source folders in Libraries\CMSIS\Device\ST\STM32F0xx\ to the Keil project folder; then import the .c file like you did main.c before. This is the bare minimum you need to program and so now you can go to main .c and write code(haven't got this part yet :)).

If you want more features you can go to the standard peripheral folder\Libraries\STM32F0xx_StdPeriph_Driver and add all the files inside inc and src to your project folder and then add all the .c to Source Group 1 and clicking "Add files to..." for all the .c files.

Rather than dealing with all of this stuff, i just like to open the STM32F0-Discovery_FW_V1.0.0\Project\Demonstration\MDK-ARM project(it already has all the .h and .c files in it) and then delete all the code in main.c and put my own there.

Programming
To program the discovery program you first press the build button(red box below). then upload it by pressing the program button(blue box below).

If you have a brand new discovery board, it will ask you to update the firmware, but when you click ok, it says "not in DFU mode". Unplug your board, takeout the two jumpers on the top right(when USB is at the top), and then plug it back in and then attempt to upload again. It should work now with no errors. Then unplug the board and put the jumpers back on.

Some times it doesn't work and it just sits there at Load "..." in the info window at the bottom of the Keil program. To fix this click the green boxed button; check that you have the correct device selected in the Device tab, and then go to Utilities and makes sure ST-Link is selected(or ST-Link depreciated if you haven't updated the firmware yet). But it still may not work; now go to the Utilities tab and click on settings(like in the second pic below). You see that mine has a programming algorithm in there; if your window doesn't have this, go to add and find your board. Now it should program correctly.



Now i need to figure out how to write code for this thing; its different than Arduino, not because of its syntax(C is almost like Arduino Wire), but because of the "micro syntax"-- AKA the code to change GPIO registers, use I2C etc.

2 comments:

  1. Hi Jordan,
    Good post. We would also like to invite you to the Arm-HQ forums(link below). We have the discovery kits as one of the sub-forums. We could surely use your help to share and to contribute.
    http://forum.arm-hq.com

    ReplyDelete
  2. Some useful info, thanks. I've got teh similar F4 discovery board up and running, but not got a F0 yet.

    Any idea why a newly released board would require a firmware update? Seems odd. My F4 also prompted for an update, but I decided against it as it was working ok.

    ReplyDelete