How to slim down the program when flash overflows?
A MCU was selected, and the product development went smoothly. At the end of the curtain, I suddenly found an overflow error in Flash. This is a very sad thing, you can't replace the chip. I don't want to go to so much trouble, and the boss doesn't want to be behind schedule. There is no choice but to streamline the procedures. Error [e 104]: Unable to fit all segments into the specified range. A problem was found in the segment code. Unable to fit 84 blocks (0x3f68 bytes in total) into 0x3dee bytes of memory. There was a problem when processing the segment placement command "-P (code) CODE=C000-FFDF", and the available memory range during placement was "code: c1F2-ffdf"1. A large number of conditional judgment statements if (setoption sflag = = preset temp)/* whether to enter the preset temperature setting mode */{...} else if (setoption sflag = = preset tem 3rd)/* the preset temperature for the third timing heating */{...} Else if (setoption sflag = = preset temperature 2th)/* preset temperature for the second scheduled heating */ {...} else if (setoption sflag = = preset temperature 1 time)/* preset temperature for the first heating */{...} ... Otherwise/* when it is not in the setting mode, the temperature control module displays. The program takes up 4328 bytes after switching to the switch statement. Save flash memory space 168KB. When there are many branches to choose from, it is best to use the switch statement. Of course, it doesn't matter if your flash is big enough. Of course, the most important thing to slim down the program is to write a module that can be written as a subroutine into a separate subroutine as far as possible without affecting the execution efficiency of the program, and call the relevant subroutine function whenever the application involves this module, which can save code space to a great extent, especially when the program has many branches.