Error RLP power function will not fit in RAM

Help
When using STM32F405 on Cerbuino Bee board in EMblocks, I get an error when I try to build my RLP code after I place the math function ‘pow’ in it.
Simple example:
double result = pow(2,3);
Error:
section ‘.text.__ieee754_pow’ will not fit in region 'RAM’
region ‘RAM’ overflowed by 4616 bytes
How can I fix this error besides not using the power function.
Thanks

@ tdcooper33 - there is only 4092 bytes of RAM allocated for RLP on the Cerb Family. The library you are trying to include for pow just won’t fit.

@ John - I’m including the “math.h” library which worked fine before when I included it to use the ‘floor’ math function in another RLP function. So why is it giving an out of ram error when I included the same library and use the ‘pow’ function? Thx

@ tdcooper33 - The pow function is just larger I imagine.

Including library doesn’t mean it will be compiled entirely. Functions you do not use don’t make it to the final image. “pow” funtion is a lot more sophisticated than “floor”, so it is quite possible that code, using “pow” function, gets too big.

I’ve pulled out every line of code in my RLP function and the only thing I have left is one line:
return = pow(2,3);
And I still get an out of RAM error.
There’s got to be something else wrong.
Do I have an EM blocks setup problem?
Can someone please try to complie this one line of code in EM blocks to see if they get the same error.
Thx

Choose different mainboard (e.g. Raptor, G120 etc.) and try to compile your code.

I selected a different board, G120, and it builds fine. Total program size is 8245 bytes with one line of code:
return = pow(2,3);
Can I edit the math.h file or something to make it not compile math functions I don’t need? Or is there another way to get the memory size of this program down so that it fits on an Cerbuino Bee board?
Thx

edit: you’ve proved it is memory constraint in the device.

Is there a way to reduce the amount of ram that the ‘pow’ function requires in RLP? Thx

Yes. Limit the first value to the number 2 and just use left shifts for to get powers of two.

Seriously though…if you are dealing with integers only you could write your own pow function in a line or two of code… that should be small enough. If you need floats then that brings in a bunch of other stuff (I think)

@ mtylerjr - What do you mean by “Limit the first value to the number 2 and just use left shifts for to get powers of two.” Can you give me more explanation? Thx

There are loads of ways to do really fast math approximations in binary. The IEEE methods are designed for accuracy not speed, but if you don’t mind a bit of error there is normally a good trick. This is especially true if you can limit things to powers of 2.

A left shift is just moving all the binary digits N places to the left. Each single shift is the same as multiplying by 2. So shifting 2 left 2 raises it to the power of 4.

Thanks guys, I’ll use this as a work around.

@ John - is there a way to increase the 4092 bytes of RAM allocated for RLP on the Cerb Family?

@ tdcooper33 - Increasing the memory available for RLP would require a change to the build configuration of the firmware and given the resource constraints of the MCU might even require removal of some of the NETMF functionality to accommodate a larger RLP memory area. So at the very least a custom firmware build would be required.

IIRC GHI originally toyed with removing RLP a entirely for the Cerb family devices in favor of USB Host, but popular demand prompted GHI to squeeze both in, but of course memory is limited.

@ taylorza - 4092 bytes is not really useful. I need about double this amount. How do I change the firmware? Can I get the guys at GHI to do this somehow? Thx

@ tdcooper33 - 4096bytes is not that small by microcontroller standards.

You can probably pay GHI to build you a custom firmware, but you would be abandoned on a build that wasn’t being developed or maintained.

How do I request a quote from GHI to build custom firmware for the Cerbuino Bee that would increase the size of RAM allocated for RLP?
Thanks

Are you still just trying to add a Power function?

I’m sure we could give you an integer-only power function in a line or two of code.