mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 10:37:46 +00:00
5ed0cecf0d
There was a very subtle bug in the ADC read code: it stores a pointer to a variable in a register, waits for the hardware to complete the read, and then reads the value again from the local variable. Unfortunately, the compiler doesn't know there is some form of synchronization happening in between. This can be fixed in roughly two ways: * Introduce some sort of synchronization. * Do a volatile read from the variable. I chose the second one as it is probably the least intrusive. We certainly don't need atomic instructions (the chip is single threaded), we just need to tell the compiler the value could have changed by making the read volatile.