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, 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"