cancel
Showing results for 
Search instead for 
Did you mean: 

Using standard libraries with SPC560D

Patriks
Senior
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
1 ACCEPTED SOLUTION

Accepted Solutions
Erwan YVIN
ST Employee
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

View solution in original post

1 REPLY 1
Erwan YVIN
ST Employee
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