Wednesday, January 19, 2011

STM32 Discovery: The Basics - Creating a project

In this post I will be discussing how I got the stm32 discovery board working with the Keil IDE. This was my first time using an ARM processor, so I decided to go with a commercial grade IDE since they tend to be easier to use. As I switch over to GCC I will document that process as well.

For starters you need the STM32 discovery board
check it out at mouser
Also you will need the Keil IDE. You can download a free limited to 32kb program space version here

First off you need to create a new project and select the processor in the ST Micro section


It will then ask you if you want to Copy STM32 Start up Code to the Project Folder. Choose yes. I would then recommend you use the Keil STM32_init files. I found them in a example code. It can be found here
Once you have downloaded the files, unzip it. Copy over the following files to the same folder as the project file.
STM32_Init.c
STM32_Init.h
STM32_Reg.h
Now add STM32_Init.c to your project. Right click on the Source Group 1 and click add file to group. You can group them however you want, it doesn't change how any thing builds.

Also, to keep things clean we will create a Bin folder. So we make a new directory in the same folder as our project. Next, right click on the Target folder and click options for target.

Then click output and click Select Folder for Objects and go find our bin folder that we created.


Finally, create and add a file (lets call it main.c). In there, add a main function that will call the Init code and include the init file. You might also want to include the STM32 lib file.

#include <stm32f10x_lib.h>
#include "STM32_Init.h"

int main (void)
{

stm32_Init();
return 0;
}
Now we need to set up our debugging environment for the STM32 Discovery.  First we need to choose our debugger.  So right click on the project and click options for target and head to the debug tab.  Next, you don't want to be running a simulator so we will click the Use: radio button to the right half.  in the drop down we will choose the ST-Link Debugger.  Then you need to click setting and choose SWD.  finally I like to have run to main() check so that is stops at the main before running.


Next we need to define the flashing tool to upload your program to the STM32.  So head over to the Utilities tab and select the "Use Target Driver for Flash programming" radio button.  Then you can choose the ST-Link Debugger from the drop down.



Now you are all ready to debug.  In my next entry I will be making code to echo a terminal with The STM32 USART.

You can download the project form my Code Project article

6 comments:

  1. Dear jmlb,

    Since I really want to get going with the STM32discovery board I have, I followed your getting started from top to bottom (I got it from http://www.codeproject.com/KB/cpp/STM32_Discovery_Project.aspx)

    I can not get it running.... When I simulate it stops in STM_init.c

    Can you help me out with it? Is there some way I can show/send you my project files?

    Cheers,
    Dennis

    ReplyDelete
  2. I never managed to simulate it properly. I all ways had to run it off the chip it self. I don't think there is a simulator for it.

    yeah sure send me an email at jeanmarc.leblanc (I am with Gmail) I will send you my code. I'll add a contact section right now

    ReplyDelete
  3. Dear jmlb,

    Hi, i’m a newbie at ARM, after (just a little) working with sam7 now i want to switch to STM32 and i’m seeking of some good tutorials . . .
    could u plz help me to find some? could u plz suggest me some sites or ebooks for STM32 learning?
    spcl tnx

    Mostafa

    ReplyDelete
  4. I updated my resource section. I have gotten really busy this year and did not put out as many tutorials as I would have liked.

    I updated my resource page to add a web site that I found a couple weeks ago. take a look. If you have any questions feel free to email me directly. You can find my email in the contact me section.

    If any one would want to request a tutorial, I could probably find time to write it.

    ReplyDelete
  5. Thanks a lot for links. . .

    ReplyDelete
  6. Hello,

    Do you have document for stm32 in Linux using GCC.

    Also another good website to mention in your URL is http://dangerousprototypes.com/

    Kumar

    ReplyDelete