Help with STM32F4DISCOVERY

Thread Starter

David_Baratheon

Joined Feb 10, 2012
285
Hi everyone, my university has some ST Discovery boards laying around and I wanted to have a little go with them. Tried using some code and it built ok with no errors but for some reason the LED is not lighting up. I am hoping to do a few things with this board and wondered if anyone knows the board well and might be able to help me? If anyone knows the hardware please post here and I have a few questions. I am using uVision v.4.74.

It builds fine but when I try to load it I get a debug cortex error saying "unknown target connected". How do I make sure I am properly targeting the hardware?

Code:
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"

#define LED GPIO_Pin_8

void init(void);
void delay(uint32_t ms);

int main()
{
    init();
 
    while(1)
    {
        GPIO_ToggleBits(GPIOA, LED);
    
        delay(10000);
    }
}

void init()
{
    GPIO_InitTypeDef gpio_init_structure;

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

    GPIO_StructInit(&gpio_init_structure);
    gpio_init_structure.GPIO_Mode = GPIO_Mode_OUT;
    gpio_init_structure.GPIO_Pin = LED;
    gpio_init_structure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOA, &gpio_init_structure);
}

void delay(uint32_t ms)
{
    ms *= (168000000 / 4) / 1000;
 
    while(ms--)
    {
        __NOP();
    }
}
 

Attachments

MrChips

Joined Oct 2, 2009
30,808
I can look over your code and attempt to run it on my system.
But it will have to wait for another day. Hang in there.
 

rstevenson

Joined Apr 5, 2011
20
I dont know if you are using the onboard LEDs or not, I modified it to use the green LED and it seems to work perfectly fine for me. I changed it to GPIO Pin PD12

Code:
#define LED GPIO_Pin_12

void init(void);
void delay(uint32_t ms);

int main()
{
    init();

    while(1)
    {
        GPIO_ToggleBits(GPIOD, LED);

        delay(10000);
    }
}

void init()

{
    GPIO_InitTypeDef gpio_init_structure;

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

    GPIO_StructInit(&gpio_init_structure);
    gpio_init_structure.GPIO_Mode = GPIO_Mode_OUT;
    gpio_init_structure.GPIO_Pin = LED;
    gpio_init_structure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOD, &gpio_init_structure);
}

void delay(uint32_t ms)
{
    ms *= (168000000 / 4) / 1000;

    while(ms--)
    {
        __NOP();
    }
}
edit: noticed you were using a led off the board. Its not the code, check that you are outputting to the correct pin
 
Last edited:

Thread Starter

David_Baratheon

Joined Feb 10, 2012
285
Hi thanks for the replies.

My initial problem isn't with the code. The error says that I haven't targeted the board correctly so needed help targeting the board correctly. Can anyone run Me through the process and help me identify which settings are wrong?
 
Last edited:
Top