Blinkinlabs / ch554_sdcc

CH554 software development kit for SDCC
306 stars 71 forks source link

make debug.c components optional to save code size #17

Open nerdralph opened 4 years ago

nerdralph commented 4 years ago

I was able to reduce the compiled size of the blink example from 700B to 232B by conditionally excluding the UART functions. Another 36B can be saved by excluding the WDT functions. Instead of adding #ifdef BUILD_UART around the code, another option would be to break up debug.c into separate files and build it as a library. Then the linker will only pull in .rel files that are actually used.

cibomahto commented 4 years ago

Both of those sound useful. One of the original design goals (that it looks like I didn't actually write down), was to avoid modifying the WCH code structure too much, so that it would be easier to pull in updates from WCH. From that angle, I would prefer #ifdefs. Separating them into individual library files does seem to be inline with how SDCC works, though.

nerdralph commented 4 years ago

I think you could probably do a lot better job if you had written it from scratch. The UART code isn't the only thing that needs work; mDelayuS could use a rewrite too. I also would've named it util.c instead of debug, since it's not specific to debugging.

cibomahto commented 4 years ago

Yeah, I agree- This was more of a strategy for keeping the scope of the project small enough so that I could get something working. As long as the example files are modified to work with the changes, it seems reasonable to rename and/or split the files up. We should probably put a short note at the top of the new files to say where they came from originally, for the probably few people who are trying to follow a Keil example.

nerdralph commented 4 years ago

Another idea is to make most of the functions inline.