Managing Application Size and Speed with PSoC Creator | Cypress Semiconductor
Managing Application Size and Speed with PSoC Creator
In embedded systems it is often true to say that "every byte counts". When your application runs solely from on-chip memory you have two very hard limits (flash ROM and SRAM) on the amount of memory you can use in your application. Modern compilers do an excellent job of optimizing code and data space, often getting very close to hand-crafted assembler in terms of memory-efficiency.
Watch out though because, by default, PSoC Creator does not optimize your code!
This is because of an inherent side-effect of compiler optimizations - they make the application harder to debug. The obvious example of this is when the code you are stepping through in the debugger has been modified by the tail merging optimization, which replaces multiple sequences of identical instructions with a single sequence. When you step the code it can jump about to really strange places in your source code, because the code you think you are debugging isn't where you think it is! But, as I said before, optimizations are really important and so, to avoid total madness, we need a way to turn optimizations on when we need them and off when we're designing and debugging.
PSoC Creator makes it really easy to do this by offering build configurations. There are two of them - Debug and Release - and they are complete sets of build options for a project. By default, a new project uses the Debug configuration which enables debugging and turns off all but the "safest" optimizations. With this configuration you can use the debugger to perfect your code before swapping to the Release configuration and simply re-building the source code.
The Release configuration turns on optimizations and disables debugging. Try it now and see your flash and SRAM usage drop! By default this configuration optimizes for space but you can quickly switch to speed optimization by simply editing the Build settings (look for Optimization in the Compiler section).
Switching configurations is really simple. There is a pull-down in PSoC Creator's main button panel and all you need to do is make your choice and build. It will only re-compile the source code - the hardware design does not change after all - and so experimenting with the options can be very fast indeed. If you are on the edge of your memory budget, or have a very tight window of time to complete a task, I strongly recommend using build configurations to help you make a careful, informed evaluation of compiler optimizations for your application.