cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F411RE cmsis led don't turn off

lukarzmen
Associate II
Posted on April 10, 2016 at 19:46

Hi,

I've got problem with code. LED on my board STM32F411RE don't turn off when I'm using cmsis library but in HAL or StdPeriph it works.

&sharpinclude ''stm32f4xx.h''

&sharpinclude ''core_cm4.h''

int main(void)

{

    //configure output

    RCC->AHB1ENR = RCC_AHB1ENR_GPIOAEN;

    __DSB();

    

    GPIOA -> MODER |= GPIO_MODER_MODER5_0; //as output

    GPIOA -> ODR |= GPIO_ODR_ODR_5; //set high

    GPIOA -> ODR &=~ GPIO_ODR_ODR_5;

        while(1){}

}

When I'm using ''GPIOA -> ODR ^=GPIO_ODR_ODR_5;'' led is still on.

Best regards,

?ukasz

#cmsis #stm32f4
7 REPLIES 7
Radosław
Senior
Posted on April 10, 2016 at 21:34

Everything is ok.

LED active on '1'??

lukarzmen
Associate II
Posted on April 11, 2016 at 10:35

Yes, LED is active on '1' but not turn off when I'm using

''GPIOA -> ODR &=~ (GPIO_ODR_ODR_5);''

or

    ''GPIOA -> BSRR = GPIO_BSRR_BR_5;''.

Is it problem with code or with Nucleo?
Radosław
Senior
Posted on April 11, 2016 at 11:08

Did you try debug? Maybe you get hardfault?

Walid FTITI_O
Senior II
Posted on April 11, 2016 at 17:33

Hi mendyk.lukasz,

This is a working code (tested on STM32F411RE Nucelo C-03).

Try to test it in a template project of Hal library to figure out what it is causing problem in your project. Step by step debugging is your freind.

The template project path is : stm32cubef4_1.11\STM32Cube_FW_F4_V1.11.0\Projects\STM32F411RE-Nucleo\Templates

-Hannibal-

lukarzmen
Associate II
Posted on April 11, 2016 at 22:20

Hi Hannibal,

I was using HAL library and it was working. I've already started with CMSIS. I was debugging it in Keil but LED didn't wanna turn off. I don't know what the problem is.
Posted on April 11, 2016 at 22:44

Use the peripheral view within Keil to confirm that the configuration is correct, and that as you toggle the output pin you can see that reflected in the register and the pin. Use the debugger and step through the code. You can contrast the peripheral settings between the cases you have working, against those that don't.

Where the configuration uses multiple bits, you might want to mask it into the register, rather than assume initial conditions.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lukarzmen
Associate II
Posted on April 11, 2016 at 23:37

Hi,

I don't know why but at this moment it's working.

Thanks for all answers. I should spend more time at debugging and check config.