[libmaple] Latest - issues

Limited support for STM32F4 Discovery, Nucleo and custom F4 boards
User avatar
Pito
Posts: 1600
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [libmaple] Latest - issues

Post by Pito » Tue Aug 15, 2017 10:22 pm

Where is the duplicate please??
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 7183
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: [libmaple] Latest - issues

Post by RogerClark » Tue Aug 15, 2017 10:50 pm

viewtopic.php?f=41&t=2434

"Libmaple problem, program crashes with call to malloc."

You have linked to it yourself

stevestrong
Posts: 1749
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: [libmaple] Latest - issues

Post by stevestrong » Sat Aug 19, 2017 8:08 am

RogerClark wrote:
Tue Aug 15, 2017 10:03 pm
This is a duplicate post thread and will be removed
OK from my side.

User avatar
Pito
Posts: 1600
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [libmaple] Latest - issues

Post by Pito » Sat Sep 02, 2017 10:07 am

While messing with map() function I see it returns wrong results with larger arguments.
It is because the multiplication in map() overflows.

This is a fix which works fine here (there is "long" in the original, I assume "long" == "int32_t"):

Code: Select all

 // Fix by Pito 9/2017
  static inline int32_t map(int32_t value, int32_t fromStart, int32_t fromEnd,
     int32_t toStart, int32_t toEnd) {
     return ((int64_t)(value - fromStart) * (toEnd - toStart)) / (fromEnd - fromStart) +
         toStart;
 }
Example:

Code: Select all

period = 2000000;
maxduty = 65000;
mypulse =  1000000; 
duty = map(mypulse, 0, period, 0, maxduty);
Results:
Original Libmaple's map() -> duty = 287
Fixed map() -> duty = 32500
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 7183
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: [libmaple] Latest - issues

Post by RogerClark » Sun Sep 03, 2017 1:03 am

Thanks

I've updated LibMaple F1 and F4 with your fix

(and attributed it to you)

victor_pv
Posts: 1682
Joined: Mon Apr 27, 2015 12:12 pm

Re: [libmaple] Latest - issues

Post by victor_pv » Sun Sep 03, 2017 3:18 am

Pito new.cpp was missing from the libmaple F4. Both Roger and Steve have merged it. That should resolve the issues about malloc, or at least reduce the code size, since it will not pull new from stdlib.

On map(), looks like at least Teensy, and perhaps Arduino, have gone a bit further:
https://github.com/PaulStoffregen/cores ... ring.h#L46

And I saw some conversation on allowing toend < tostart, not sure if that case is covered already?

User avatar
Pito
Posts: 1600
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [libmaple] Latest - issues

Post by Pito » Tue Sep 05, 2017 8:57 am

I've seen somewhere (not sure where) the guys did an overloaded map() which worked with all types (as well as with single/double float)..
Pukao Hats Cleaning Services Ltd.

Post Reply