When running without wait states everything is fine and performing as expected. But when I enable change the wait states for flash from 0 to 1, my loop takes 833 milliseconds instead of 500 milliseconds, or a 66% loss in performance roughly.
When I use GDB to debug, I can see the FLASH_ACR register has the contents of 0b0011 0000
which signify that the prefetch buffer is both enabled and has a status of enabled, with 0 wait states for flash. Plus, the prefetch buffer should be enabled on reset as per the datasheet. When I write to the register by oringor'ing it with 0b001
I get the expected result of 0b0011 0001
back after reading from it again. This is done doing the following:
// Change the flash wait states to 1.
volatile uint32_t foo1 = FLASH_ACR;
FLASH_ACR = FLASH_ACR | (0b001 << 0);
volatile uint32_t foo2 = FLASH_ACR;
Interestingly enough, enabling or disabling the prefetch buffer with a 1 wait state makes no difference in my loop, which doesn't seem to make sense.
And here is the relevant section of the datasheet