Skip to main content
Patriks
Senior
September 16, 2014
Solved

Using standard libraries with SPC560D

  • September 16, 2014
  • 1 reply
  • 649 views
Posted on September 16, 2014 at 16:03

Hello,

I would like to do some mathematical calulations like square root, sin, cos,... with the SPC560D. Does ST provide any libraries for that purpose which I can include in my SPC5 project?

Best regards,

Patrik
    This topic has been closed for replies.
    Best answer by Erwan YVIN
    Posted on September 19, 2014 at 15:30

    Hello Patrik ,

    In your SPC5 Project, you can use some classic mathematical libraries on OS-LESS Test application by adding this piece of code :

    /* sin example */

     

    #include <errno.h>

     

    #include <stdio.h>      /* printf */

     

    #include <math.h>       /* sin */

     

    #include <float.h>

     

     

    #define PI 3.14159265

     

     

    /* For sprintf porting */

     

    void *sbrk(size_t incr) {

     

      extern uint8_t __heap_base__;

     

      extern uint8_t __heap_end__;

     

      static uint8_t *p = &__heap_base__;

     

      static uint8_t *newp;

     

     

      newp = p + incr;

     

      if (newp > &__heap_end__) {

     

        errno = ENOMEM;

     

        return (void *)-1;

     

      }

     

      return p = newp;

     

    }

     

     

     

    /*

     

     * Application entry point.

     

     */

     

    int main(void) {

     

     

        char string[60];

     

        double param, result;

     

      .......................

     

      param = 30.0;

     

      result = sin (param*PI/180)*1000;

     

      

     

      sprintf (string, ''The sine of %d degrees is %d.\n'', (int)param, (int)result );

     

     

      it works well ;)

     

     

                        Best regards

                                         Erwan

    1 reply

    Erwan YVIN
    Erwan YVINBest answer
    ST Employee
    September 19, 2014
    Posted on September 19, 2014 at 15:30

    Hello Patrik ,

    In your SPC5 Project, you can use some classic mathematical libraries on OS-LESS Test application by adding this piece of code :

    /* sin example */

     

    #include <errno.h>

     

    #include <stdio.h>      /* printf */

     

    #include <math.h>       /* sin */

     

    #include <float.h>

     

     

    #define PI 3.14159265

     

     

    /* For sprintf porting */

     

    void *sbrk(size_t incr) {

     

      extern uint8_t __heap_base__;

     

      extern uint8_t __heap_end__;

     

      static uint8_t *p = &__heap_base__;

     

      static uint8_t *newp;

     

     

      newp = p + incr;

     

      if (newp > &__heap_end__) {

     

        errno = ENOMEM;

     

        return (void *)-1;

     

      }

     

      return p = newp;

     

    }

     

     

     

    /*

     

     * Application entry point.

     

     */

     

    int main(void) {

     

     

        char string[60];

     

        double param, result;

     

      .......................

     

      param = 30.0;

     

      result = sin (param*PI/180)*1000;

     

      

     

      sprintf (string, ''The sine of %d degrees is %d.\n'', (int)param, (int)result );

     

     

      it works well ;)

     

     

                        Best regards

                                         Erwan