EEVblog Electronics Community Forum

Electronics => Projects, Designs, and Technical Stuff => Topic started by: CM800 on December 10, 2014, 12:36:28 pm

Title: STM32F407 Discovery
Post by: CM800 on December 10, 2014, 12:36:28 pm
Heya,

A while back I brought an STM32F407 Cortex M4 Discovery board

I can't find any decent tutorials that are up to date and work.
Does anyone have any good links to tutorials? Just somthing like a simple blink would be a good starter. I don't have too much experiance with microcontrollers other then arduino.

Thanks!

EDIT:

I have already tried CooCox's IDE but I can't seem to figure out config properly. I really need some kind of starting tutorial to get to understand these things.
Title: Re: STM32F407 Discovery
Post by: AndreasF on December 10, 2014, 10:05:19 pm
I've been using the CooCox IDE with this Discovery board, and I agree, it's not as easy for a beginner. But there are a few resources out there that will help. One thing that may not be obvious is that CoIDE alone is not enough. You also need the ARM compiler and the ST-LINK utility from STM to program and debug the board. This is reasonably well explained here (http://techwithdave.blogspot.co.uk/2013/04/hello-world-tutorial-for-stm-discovery.html) and also in this video (https://www.youtube.com/watch?v=nP6TR6NAZTQ). Both are slightly outdated and for a different Discovery board, but should help get you started.

On my own blog I have a few post about some of the peripherals, including some things that are not obvious to users of smaller micros (e.g. having to explicitly turn on clocks for peripherals including the GPIO's - the video talk about this too).
Title: Re: STM32F407 Discovery
Post by: dannyf on December 11, 2014, 12:11:01 am
A big fan of CoIDE too.

The set-up is super easy and tons of context-sensitive examples to get you going in no time.
Title: Re: STM32F407 Discovery
Post by: CM800 on December 11, 2014, 03:50:19 pm
Thanks for the help everyone. It's a bit of a pain as I'm going off out of home for a week. But you will hear from me later if its working or not :)

Title: Re: STM32F407 Discovery
Post by: pyrohaz on December 11, 2014, 07:02:21 pm
A big fan of CoIDE too.

The set-up is super easy and tons of context-sensitive examples to get you going in no time.

Completely agree! I've used CoIDE for the past year and I find it really easy to use once you get it setup. If I recall correctly, the method I used is:


Probably isn't the greatest bit of help but keep trying and it will definitely pay off, the ST micros are brill.

Edit: I've got a few STM32F0 tutorials on my blog if you also have an STM32F0 discovery board - www.hsel.co.uk (http://www.hsel.co.uk)
Title: Re: STM32F407 Discovery
Post by: dannyf on December 11, 2014, 07:41:26 pm
Simpler than that:

1) download the gcc compiler from the launchpad and install it;
2) download coide and install it;
3) configure coide to use the installed gcc compiler: coide will prompt you;
4) create a new project for your chip, link in the components;
5) compile, download and you have a working project, :)

Cannot be simpler than that.
Title: Re: STM32F407 Discovery
Post by: pyrohaz on December 11, 2014, 07:43:07 pm
Simpler than that:

1) download the gcc compiler from the launchpad and install it;
2) download coide and install it;
3) configure coide to use the installed gcc compiler: coide will prompt you;
4) create a new project for your chip, link in the components;
5) compile, download and you have a working project, :)

Cannot be simpler than that.

+1
Title: Re: STM32F407 Discovery
Post by: CM800 on December 11, 2014, 11:46:16 pm
Okay. Something isn't working.

Code: [Select]
#include "stm32f4xx.h"

int main(void)
{

RCC -> AHB1ENR |= (1 << 3);

GPIOD -> MODER |= (1 << 26);

GPIOD -> ODR |= (1 << 13);



    while(1)
    {
    }
}

I can't seem to get the LED on PD13 to turn on.

Could anyone figure out whats wrong?

These are the errors I'm getting.
(http://i.imgur.com/ojSmiCB.png)

Title: Re: STM32F407 Discovery
Post by: dannyf on December 12, 2014, 02:46:43 am
cannot see your error message.

the code is largely right. i would clear bit 27 and explictly set other port registers, just in case they have some weird values.

make sure the port/pin for the led is right, the led polarity is right.

make sure your project is set up right.

when i get some time i will try on my f4 discovery.
Title: Re: STM32F407 Discovery
Post by: pyrohaz on December 12, 2014, 03:45:39 am
Okay. Something isn't working.

Code: [Select]
#include "stm32f4xx.h"

int main(void)
{

RCC -> AHB1ENR |= (1 << 3);

GPIOD -> MODER |= (1 << 26);

GPIOD -> ODR |= (1 << 13);



    while(1)
    {
    }
}

I can't seem to get the LED on PD13 to turn on.

Could anyone figure out whats wrong?

These are the errors I'm getting.
(http://i.imgur.com/ojSmiCB.png)

I think thats to do with administrative privileges/firewall when running CoIDE. tasklist.exe generally contains each task required to get the program from code to microcontroller (compile, link, download etc.), if its failing to run, it's likely that your computer is stopping it. Try temporarily disabling your firewall to see if that helps OR try running CoIDE as administrator. I might not be getting this problem because I have CoIDE installed directly to my C:\ instead of in program files (Don't ask me why!).

The fact that gdbserver also fails to launch (for debugging) really shows that it could be something on your computer blocking the program from running.
Title: Re: STM32F407 Discovery
Post by: CM800 on December 12, 2014, 05:34:36 pm
Can't seem to get debug working at all. I have all the correct files including tasklist.exe.

I can live with that not working, the bigger problem is that I can't seem to get any reaction out of my microcontroller.
I can upload that program but the LED doesn't come on, nor does the pin change its voltage from 0.00v.
Title: Re: STM32F407 Discovery
Post by: splin on December 12, 2014, 06:47:37 pm
Try running tasklist and gdbserver from a dos command prompt. If they don't start then hopefully you'll get some error messages that will help eg. wrong permissions etc.
Title: Re: STM32F407 Discovery
Post by: AndreasF on December 12, 2014, 07:28:50 pm
...I can upload that program but ...

This might be a stupid question, but how do you know this if nothing happens?

Also, in CoIDE, when you upload a file to the board via the "Debug" button, it is actually (for me at least) paused by the debugger, and you have to push the "play" button to make it run.
Title: Re: STM32F407 Discovery
Post by: CM800 on December 12, 2014, 10:39:12 pm
...I can upload that program but ...

This might be a stupid question, but how do you know this if nothing happens?

Also, in CoIDE, when you upload a file to the board via the "Debug" button, it is actually (for me at least) paused by the debugger, and you have to push the "play" button to make it run.
Well, It said that it had flashed and the data LED was flashing.

Try running tasklist and gdbserver from a dos command prompt. If they don't start then hopefully you'll get some error messages that will help eg. wrong permissions etc.

Will give that a try :)
Title: Re: STM32F407 Discovery
Post by: dannyf on December 12, 2014, 11:40:53 pm
I can confirm for you that on the F4 discovery board, your code runs and debugs as expected.
Title: Re: STM32F407 Discovery
Post by: CM800 on December 13, 2014, 12:20:43 am
I can confirm for you that on the F4 discovery board, your code runs and debugs as expected.

Well, that makes me worry a little really. Thanks for checking though :)
Title: Re: STM32F407 Discovery
Post by: CM800 on December 13, 2014, 12:36:05 am
When setting up, was there anything you changed at all?

I can't seem to find gdbserver.exe on my computer, even in the GNU Tools ARM Embedded folder.
Title: Re: STM32F407 Discovery
Post by: pyrohaz on December 17, 2014, 03:56:43 pm
When setting up, was there anything you changed at all?

I can't seem to find gdbserver.exe on my computer, even in the GNU Tools ARM Embedded folder.

It should be present in your .../CoIDE/bin folder :)
Title: Re: STM32F407 Discovery
Post by: CM800 on December 18, 2014, 10:25:46 pm
Found it :)

Still can't get stuff running though. I'm gonna buy another board incase mine is faulty somehow.
Title: Re: STM32F407 Discovery
Post by: pyrohaz on December 18, 2014, 10:41:56 pm
Found it :)

Still can't get stuff running though. I'm gonna buy another board incase mine is faulty somehow.

Before you do that! Download the ST STLink utility, plug it in and see if it connects to the board. If it does, you should be able to see what microcontroller you have and a few specs about it (SRAM and Flash) memory. If this succeeds, your board should be working successfully.
Title: Re: STM32F407 Discovery
Post by: CM800 on December 18, 2014, 11:09:34 pm
Yeh, It does seem to connect and all just fine... but the fact I can't program it etc is causing me some worry and no small amount of fustration...
Title: Re: STM32F407 Discovery
Post by: pyrohaz on December 19, 2014, 12:10:37 am
Yeh, It does seem to connect and all just fine... but the fact I can't program it etc is causing me some worry and no small amount of fustration...

Are you using windows 7 or  windows 8? I sometimes have a few problems with the STLink under windows 8. If you're using windows 7, you could try installing CoIDE to your C:\ drive. Windows 8 has problems with creating and modifying files in the program files folder at times.
Title: Re: STM32F407 Discovery
Post by: CM800 on December 19, 2014, 12:07:47 pm
I've been using windows 7. As of now CoIDE is installed in the C drive but still does not seem to want to debug... not sure what else to try.


EDIT:
Don't know why I wrote 'Windows 8' I'm actually using windows 7.
Title: Re: STM32F407 Discovery
Post by: AndreasF on December 19, 2014, 02:49:54 pm
When setting up, was there anything you changed at all?
...

I'm pretty sure the only things I manually changed was setting (http://www1.coocox.org/CoIDE/Compiler_Settings.html) the "toolchain path" (i.e. compiler etc), and selecting (http://www1.coocox.org/CoIDE/Configuring_configuration.html) the correct hardware adapter for debug (ST-Link/V2).
Title: Re: STM32F407 Discovery
Post by: CM800 on December 19, 2014, 05:48:10 pm
I seem to have done all that and it all checks out... I still get these errors:
(http://i.imgur.com/W97s3Ge.png)
Title: Re: STM32F407 Discovery
Post by: pyrohaz on December 20, 2014, 02:01:53 pm
When you installed the toolchain, did you add the path as an environmental variable?
Title: Re: STM32F407 Discovery
Post by: AndreasF on December 20, 2014, 07:45:37 pm
Way out of my league here, but my guess is that there is something on your computer that interferes with gdbserver setting up a remote connection to the target. There is a "GDBserverParam.ini" file in the "..CoIDE\bin" folder. Maybe try changing the port number at the bottom. Maybe something (firewall?) blocks that particular port? (see the footnote in the GDB/GDBserver documentation (https://sourceware.org/gdb/current/onlinedocs/gdb/Server.html#FOOT13))

Edit: Those appear to be the same settings as in the project configuration itself, so maybe it's easier to just change them there.
Title: Re: STM32F407 Discovery
Post by: CM800 on December 23, 2014, 07:13:44 pm
And the plot thickens....

my STM32F051 board arrived today. That completely worked and was just fine... however this bored still doesn't work...

The debug on the new board works, but it doesn't on the original STM32F407 board.
Title: Re: STM32F407 Discovery
Post by: pyrohaz on December 24, 2014, 05:09:15 pm
And the plot thickens....

my STM32F051 board arrived today. That completely worked and was just fine... however this bored still doesn't work...

The debug on the new board works, but it doesn't on the original STM32F407 board.

How odd! Maybe try using the STLink section of the STM32F0 board for the STM32F4 processor and see if that makes a difference? If so, the STLink section of your STM32F4 might be messed up though the fact you could detect the processor with the STLink utility is quite odd. I'm sorry I can't be much more helpful!
Title: Re: STM32F407 Discovery
Post by: CM800 on December 28, 2014, 09:02:12 pm
And the plot thickens....

my STM32F051 board arrived today. That completely worked and was just fine... however this bored still doesn't work...

The debug on the new board works, but it doesn't on the original STM32F407 board.

How odd! Maybe try using the STLink section of the STM32F0 board for the STM32F4 processor and see if that makes a difference? If so, the STLink section of your STM32F4 might be messed up though the fact you could detect the processor with the STLink utility is quite odd. I'm sorry I can't be much more helpful!

I'm afraid that hasn't made any difference... Really not sure what to do now. I might buy another STM32F4 board, they arn't that expensive.
Title: Re: STM32F407 Discovery
Post by: dannyf on December 28, 2014, 09:18:35 pm
What's the chance of 3 boards not working?

I think the issue isn't with the boards.
Title: Re: STM32F407 Discovery
Post by: CM800 on December 30, 2014, 12:49:04 am
There arn't 3 boards not working... I don't think you have read the thread correctly.


I have 2 STM boards, one is an STM32F407.... the other an STM32F051

The 407 does not work however the 051 does work. I'm trying to work out what is wrong with the 407. I believe it may have been static'd to death as I have had it laying about for a long time.