File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -913,12 +913,13 @@ and compare generated assembly code:
913913 bx lr bx lr
914914```
915915
916- Long story short: if there is no `volalile`, the `delay()` function will
917- loop forever and never return. Because it caches (optimises) the value of
918- `s_ticks` in a register and never updates it. The generated code with
919- `volatile`, on the other hand, loads `s_ticks` value on each iteration.
920- So, the rule of thumb: those values in memory that get updated by interrupt
921- handlers, or by the hardware, declare as `volatile`.
916+ Long story short: if there is no `volalile`, the `delay()` function will loop
917+ forever and never return. Because it caches (optimises) the value of `s_ticks`
918+ in a register and never updates it. A compiler does that because it doesn' t
919+ know that ` s_ticks` can be updated elsewhere - by the interrupt handler! The
920+ generated code with ` volatile` , on the other hand, loads ` s_ticks` value on
921+ each iteration. So, the rule of thumb: those values in memory that get updated
922+ by interrupt handlers, or by the hardware, declare as ` volatile` .
922923
923924Now we should add ` SysTick_Handler()` interrupt handler to the vector table:
924925
You can’t perform that action at this time.
0 commit comments