Enable global O3 optimisation in KEIL Problems with reading back properly when using SPI1
Presumably this is because O3’s aggressive optimisation took out some key variables in the SPI library
So change the optimisation of apm32f10x_spi.c back to O0 test
I found that I still couldn’t read back the data properly, so I took a closer look at the functions that call the spi, and speculated that they might have been optimised.
The most likely optimisation is the SPI1 structure. Change the definition of the SPI1 structure to volatile.
Test again, the data read back is normal.
There is another way to solve this problem, because the problem is in the functions that use spi, and because you don’t want to modify the library functions.
There is an official optimisation method for individual functions, which is as follows.
Refer to the following two articles
[ARM Compiler v5.06 for uVision armcc User Guide](https://developer.arm.com/documentation/dui0375/g/Compiler-specific-Features/-pragma- Onum)
[ARM Compiler v5.06 for uVision armcc User Guide](https://developer.arm.com/documentation/dui0375/g/Compiler-specific-Features/-pragma- Otime)
Optimise the functions related to spi library functions and apm32f10x_spi.c with O0 alone, and turn on O3 for the rest.
Test again, it can read back the data normally.