Differences in using c user-defined functions on PC and on ARM
The difference isn't in the platfrom.

The difference is that CodeBlocks probably compiles to no optimisation at Debug setting, whereas many, if not most, embedded compilers - as configured out of the box - optimise away function calls that have no macroscopic effect.

If you go to debug mode you will see you can't put any breakpoints inside mySleep(). This is because the compiler decided to not include it in the limited code space of your processor, since inside it nothing happens.

That said, Atmel has Delay(), Delay_ms() and Delay_us() that use an ASM VOLATILE nop loop to get very close to guaranteed delays if the CPU speed is set correctly.

You can also include inline ASM code (google it if you want) as VOLATILE inside your loop, having it execute a single NOP instruction (NOP = No Operation = Do nothing). For ARM GCC, an online cookbook quotes:

asm volatile("mov r0, r0");

Volatile means "do not touch!" or otherwise "Do not optimise it away for me!".

I'm too lazy to check, but I believe ARM also has the NOP instruction.



You can also probably change the settings for optimisation, but that means your code will become huge very quickly if you're just starting out.