Etherkit Si5351 example gets huge

mankan
Sun Oct 30, 2016 3:52 pm
Planned to hook a Si5351 clock generator board to my blue pill but the example binaries get larger than the available flash, about 70+kB.
First I thought is was something with my Arduino installation, the computer, with Windows 7, have had several versions and flavors of Arduino installed (and still have) so I took my Arduino free Windows 10 laptop and installed 1.6.9, added Due boards, installed Arduino_STM32 package, installed Etherkit Si5351 library and started building the si5351example sketch.

After fixing a compile error which I assume is to changed Wire interface I once again got a 70+kB binary. Googled around and found the following http://danieleff.com/stm32/result.php?n … t%20Si5351 which indicates that the example code should be around 18kB.

Where do I start looking?


Pito
Sun Oct 30, 2016 4:44 pm
Lot of 64bit math there.. For example in si5351.h:
/* NOTE: macro parameter n is evaluated multiple times,
* beware of side effects!
*/

# define do_div(n,base) ({ \
uint64_t __base = (base); \
uint64_t __rem; \
__rem = ((uint64_t)(n)) % __base; \
(n) = ((uint64_t)(n)) / __base; \
__rem; \
})


mankan
Sun Oct 30, 2016 5:31 pm
Ok, so upgrading from 1.6.9 won’t solve this. Could downgrading be an option in order to see if and when it was introduced? Any particular versions to recommend?

Pito
Sun Oct 30, 2016 5:33 pm
Most probably you have to remove “new” from the source, it may load a tons of c++ crap (alloc, malloc) into the code..

void Si5351::set_ms(enum si5351_clock clk, struct Si5351RegSet ms_reg, uint8_t int_mode, uint8_t r_div, uint8_t div_by_4)
{
uint8_t *params = new uint8_t[20];


mankan
Sun Oct 30, 2016 5:59 pm
I never thought anyone used new in embedded code, I’m proven wrong. I’ll certainly give it a try but it does not explain why the code in the link I provided is 18kB.

Pito
Sun Oct 30, 2016 6:03 pm
Better to ask danieleff :P

mankan
Sun Oct 30, 2016 6:28 pm
I replaced the two “new statements” with stack allocation as well as removed the corresponding deletes and ended up with the following sizes:
ST Link 19 716
Serial 14 316
Bootloader: 19 732
BMP: 14,300

much more reasonable in comparison with Daniels 18 868 bytes.

And the example works too :-) Thanks a lot Pito.


RogerClark
Sun Oct 30, 2016 8:52 pm
BTW. The reason for the STLink upload being bigger is that USB Serial is compiled into the code ( as most people want to use the built in USB when using STLink rather than hooking up another USB to Serial adaptor)

But as you know you can remove USB Serial from and of the builds by removing the appropriate defines from boards.txt and restarting the IDE.

I know we could have yet another menu option to allow people to choose if they want USB serial on Stlink, Bmp, or Jlink etc, but we already have one of the most complicated menu systems for any Arduino core, and I think it could end up more confusing and potentially annoying to a lot of users


mankan
Sun Oct 30, 2016 8:57 pm
Understood and also agreeing with you Roger. It’s easy enough to add menu options for advanced users instead of making it cluttered for new and intermediate users.

danieleff
Mon Oct 31, 2016 6:02 am
mankan wrote:
After fixing a compile error which I assume is to changed Wire interface I once again got a 70+kB binary. Googled around and found the following http://danieleff.com/stm32/result.php?n … t%20Si5351 which indicates that the example code should be around 18kB.

Where do I start looking?


RogerClark
Mon Oct 31, 2016 7:03 am
danieleff wrote:

Compiling the example code with the maple core gives me 77kb. Compiling just “void setup() { new int();}” is 71kb.
Compiling with the new stm core the example is 18kb, and “new int()” 8kb.

danieleff
Mon Oct 31, 2016 7:31 am
RogerClark wrote:danieleff wrote:

Compiling the example code with the maple core gives me 77kb. Compiling just “void setup() { new int();}” is 71kb.
Compiling with the new stm core the example is 18kb, and “new int()” 8kb.

RogerClark
Mon Oct 31, 2016 7:33 am
Interesting

I wonder what the downside is…


danieleff
Tue Nov 01, 2016 4:02 am
Given it is in arduino, esp8266, teensy source codes; I guess it is safe to do.

RogerClark
Tue Nov 01, 2016 4:53 am
OK

I’ll try adding it to the F103 core and see if it builds etc


Leave a Reply

Your email address will not be published. Required fields are marked *