Help with STM32F4DISCOVERY

Discussion in 'Embedded Systems and Microcontrollers' started by Dawud Beale, Nov 13, 2014.

  1. Dawud Beale

    Thread Starter Member

    Feb 10, 2012
    275
    7
    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 (Text):
    1.  
    2. #include "stm32f4xx.h"
    3. #include "stm32f4xx_gpio.h"
    4. #include "stm32f4xx_rcc.h"
    5.  
    6. #define LED GPIO_Pin_8
    7.  
    8. void init(void);
    9. void delay(uint32_t ms);
    10.  
    11. int main()
    12. {
    13.     init();
    14.  
    15.     while(1)
    16.     {
    17.         GPIO_ToggleBits(GPIOA, LED);
    18.    
    19.         delay(10000);
    20.     }
    21. }
    22.  
    23. void init()
    24. {
    25.     GPIO_InitTypeDef gpio_init_structure;
    26.  
    27.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
    28.  
    29.     GPIO_StructInit(&gpio_init_structure);
    30.     gpio_init_structure.GPIO_Mode = GPIO_Mode_OUT;
    31.     gpio_init_structure.GPIO_Pin = LED;
    32.     gpio_init_structure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    33.     GPIO_Init(GPIOA, &gpio_init_structure);
    34. }
    35.  
    36. void delay(uint32_t ms)
    37. {
    38.     ms *= (168000000 / 4) / 1000;
    39.  
    40.     while(ms--)
    41.     {
    42.         __NOP();
    43.     }
    44. }
    45.  
    46.  
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,360
    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.
     
  3. rstevenson

    New Member

    Apr 5, 2011
    21
    1
    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 (Text):
    1. #define LED GPIO_Pin_12
    2.  
    3. void init(void);
    4. void delay(uint32_t ms);
    5.  
    6. int main()
    7. {
    8.     init();
    9.  
    10.     while(1)
    11.     {
    12.         GPIO_ToggleBits(GPIOD, LED);
    13.  
    14.         delay(10000);
    15.     }
    16. }
    17.  
    18. void init()
    19.  
    20. {
    21.     GPIO_InitTypeDef gpio_init_structure;
    22.  
    23.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
    24.  
    25.     GPIO_StructInit(&gpio_init_structure);
    26.     gpio_init_structure.GPIO_Mode = GPIO_Mode_OUT;
    27.     gpio_init_structure.GPIO_Pin = LED;
    28.     gpio_init_structure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    29.     GPIO_Init(GPIOD, &gpio_init_structure);
    30. }
    31.  
    32. void delay(uint32_t ms)
    33. {
    34.     ms *= (168000000 / 4) / 1000;
    35.  
    36.     while(ms--)
    37.     {
    38.         __NOP();
    39.     }
    40. }
    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: Nov 13, 2014
  4. Dawud Beale

    Thread Starter Member

    Feb 10, 2012
    275
    7
    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: Nov 17, 2014
  5. Dawud Beale

    Thread Starter Member

    Feb 10, 2012
    275
    7
    Is no one able to help me with targeting this device?
     
Loading...