Skip to main content
Devipriya Soundararajan
Associate
August 9, 2017
Solved

LED Blinking with STM32F030F4

  • August 9, 2017
  • 16 replies
  • 3960 views
Posted on August 09, 2017 at 13:57

Hi,

I'm using STM32F030F4 MCU for LED blinking function. I used below code with Keil IDE.

But I'm not able to get the output.

Boot0 pin pulled low for internal flash boot loader.

Added Corresponding ST pheripheral library(gpio,misc,rcc file), CMSIS(core_cm3,system_stm32f0xx) and Startup file.

LED connected to Port A_Pin_9. I'm using ST link/v2 for programming. Do I missed anything? or any issue with code?

#include <stm32f0xx.h>

#include <stm32f0xx_gpio.h>

#include <stm32f0xx_rcc.h>

GPIO_InitTypeDef Gp;

#define GreenLED_Pin GPIO_Pin_9

#define LED_GPIO GPIOA

void delay(unsigned int time)

{

for(time=0;time>0;time--);

}

int main(void)

{

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);

Gp.GPIO_Pin=GreenLED_Pin;

Gp.GPIO_Mode=GPIO_Mode_OUT;

Gp.GPIO_OType=GPIO_OType_OD;

Gp.GPIO_Speed=GPIO_Speed_Level_1;

GPIO_Init(LED_GPIO,&Gp);

while(1)

{

GPIO_SetBits(LED_GPIO,GreenLED_Pin);

delay(10000);

GPIO_ResetBits(LED_GPIO,GreenLED_Pin);

delay(10000);

}

}
    This topic has been closed for replies.
    Best answer by waclawek.jan
    Posted on August 11, 2017 at 13:40

    Yes, but there's no VSSA on the TSSOP20 package.

    JW

    16 replies

    Tesla DeLorean
    Guru
    August 9, 2017
    Posted on August 09, 2017 at 14:33

    I'd probably make the time variable volatile so Keil doesn't optimize away the loop.

    Try using the debugger to step the code. Try without a delay between them, and just step the two GPIO Set/Reset functions.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Vangelis Fortounas
    Associate II
    August 9, 2017
    Posted on August 09, 2017 at 22:16

    Hi!

    void delay(unsigned int time)

    {

    for(time=0;time>0;time--);

    }

    time is unsigned

    at first loop (time>0) is false and exits

    so the delay until zero is too low

    S.Ma
    Principal
    August 9, 2017
    Posted on August 09, 2017 at 23:04

    Additionally, make the pin as push pull in case the led terminals are swapped by mistake...

    Tamas Novak
    Associate III
    August 10, 2017
    Posted on August 10, 2017 at 09:33

    If not clear what Vangelis meant: when entering delay()  variable time gets the parameter value (e.g. 10000), but

    then  for (time=0;   erases this value.  You may use for statement without initial setting (there is an empty semicolon!!)

    like

    for ( ;  time>0;  time--);

    Mariano Abad
    Associate
    August 10, 2017
    Posted on August 10, 2017 at 09:56

    besides defining 'time' as volatile you could also add a few nops in the for-loop.

    You could also set up a timer to use as delay comparator , or you can even easily use the internal systick timer and block waiting for it to reach a value.

    btw:

    in

    for(time=0;time>0;time--);

    time>0

    condition will never be met as you are setting it as 0 in the loop initializer.

    Devipriya Soundararajan
    Associate
    August 10, 2017
    Posted on August 10, 2017 at 10:54

    Hi,

    Yes I made a mistake in delay loop. And I have corrected that. Thanks for that.

    Another thing I need to make sure is that, I'm not able to add core_cm3.c file from standard peripheral STM32F0xx library provided by ST. I'm able to add only the header file.

    Is it enough? If not means how to get it?

    Vangelis Fortounas
    Associate II
    August 10, 2017
    Posted on August 10, 2017 at 12:34

    Hi

    Devipriya

    !!

    You use ARM Cortex M0  not   M3.

    So this file is not suitable for your MCU

    Devipriya Soundararajan
    Associate
    August 10, 2017
    Posted on August 10, 2017 at 13:51

    yes vangelis I got your point. Thanks

    Devipriya Soundararajan
    Associate
    August 11, 2017
    Posted on August 11, 2017 at 10:30

    0690X00000607pFQAQ.png0690X00000607peQAA.png

    Hi,

    The above is my circuit and program. Hope added all library and everything. But I'm unable to make it work in STM32 MCU. Is there anything need to be done in addition to it?

    waclawek.jan
    Super User
    August 11, 2017
    Posted on August 11, 2017 at 10:44

    Use volatile for the variables in the loopdelay, so that the compiler does not optimize it out.

    JW

    Devipriya Soundararajan
    Associate
    August 11, 2017
    Posted on August 11, 2017 at 11:13

    In addition to that, I'm unable to debug in keil. 

    Found error 65: access violation 0x40021000: no read permission

    Will it create issue?

    Devipriya Soundararajan
    Associate
    August 11, 2017
    Posted on August 11, 2017 at 14:31

    Hi, 

    I'm missing out something. I'm able to flash correctly, but I'm not able to blink LED?