We're using MK22FN256xxx12, running bare metal KSDK 1.0.0 (I know it's old, but we don't have the resource to update it yet). The SPI on this board is running as a slave to a master (Nordic NRF51822 chip). When the Kinetis code is built regularly, everything runs ok. But recently we're short on space so I tried to build with optimized (I tried specifically with "-O1"). When I do that, then SPI slave starts failing. The data coming into K22F is okay generally, but the data going to Nordic is so messed up it's unusable.
Has anyone ever experienced this? Is this caused by something trivial, perhaps some Compiler settings that I can modify?
In general I do see when building with Optimized (C/C++ Build->Settings->Optimization Level->Optimize...) then the system degenerates. But I've never tried to pinpoint exactly where it's happening. This time, it's very reproducible and obvious.