I am using Keil to flash the software to my stm32f407 discovery. But the software only starts working when i pullout the JLINK cable and plug it again. Why is that? Thanks.
Hello Andy, I have a really big problem with KEIL setting to run my BLINKING LED program for my STM32F407 which photo shown bellow.I have defined KEIL 5.0 with the following settings shown bellow
My flashilng LOG and the code i tried to flash is shown bellow.I get absolutly nothing on the board no blinking no even LED turning ON where did i go wrong?Thanks.
Build started: Project: try1*** Using Compiler 'V6.15', folder: 'C:\Keil_v5\ARM\ARMCLANG\Bin'Build target 'Target 1'compiling bob.c...compiling system_stm32f4xx.c...linking...Program Size: Code=432 RO-data=408 RW-data=0 ZI-data=1632 ".\Objects\try1.axf" - 0 Error(s), 0 Warning(s).Build Time Elapsed: 00:00:00Load "C:\\Keil_v5\\less01\\Objects\\try1.axf" Erase Done.Programming Done.Verify OK.Application running ...Flash Load finished at 13:30:06
#include "stm32f407xx.h" int main() { RCC->AHB1ENR|=(1uL<<3); //set thirdbit //GPIOD->MODER&=~(1uL<<31);//reset 0 on 31 01 to gpio_moder 31,30 bits in register //GPIOD->MODER|=(1uL<<30);//set 1 on 30 output mode for pin 15 port D GPIOD->MODER=0x55000000; GPIOD->OTYPER=0; //all register is push pull GPIOD->OSPEEDR=0;//speed low //GPIOD->ODR|=(1<<15); //Sets pin 15 while(1) { GPIOD->BSRR=(1uL<<15); for(uint32_t i=0;i<500000;i++){} GPIOD->BSRR=(1uL<<(15+16)); } }
so what happens if you step it in the debugger?
Hello Andy,In debug mode its turning on and off,So the for loop is not creating any delay.Could you please reccomend me an alternative for a delay?
Also maybe the compiler dissables the for loop(optmisation) i set it to be -1 as shwn bellow.Thanks.
rocko874 said:the for loop is not creating any delay
That'll be because it's being optimised away:
See https://www.avrfreaks.net/comment/3083281#comment-3083281 and the following 4 posts about optimisation.
Follow the links
Hello Andy, they say that its about the index variable being local.But i used a video manual where it worked just fine.What do you reccomend?Thanks.
rocko874 said:they say that its about the index variable being local
you've missed the point.
Did you follow the link I gave?
The compiler sees your loop as totally pointless, so is perfectly entitled to optimise it out.
It may help if you make the loop index volatile:
while(1) { volatile uint32_t i; GPIOD->BSRR=(1uL<<15); for( i=0; i<500000; i++ ){} GPIOD->BSRR=(1uL<<(15+16)); }
So every variable has to volotile now?I tried to write a function with a loop and it canceled it in optimisation too.What could be done other then using volotile?
rocko874 said:So every variable has to volotile now?
No - it's just a kludge to get your busy-loop delay working.
rocko874 said:I tried to write a function with a loop and it canceled it in optimisation too
re-read the linked posts - you need to understand that this is expected behaviour when you write useless loops.
In particular: https://www.avrfreaks.net/comment/3078001#comment-3078001 - the bit, "what a 'C' program is actually about"
The compiler will not optimize out __NOP() intrinsic instructions.
Change your loop from
for(uint32_t i=0;i<500000;i++){}
To
for(uint32_t i=0;i<500000;i++) { __NOP(); }