Using C++ for PSoC

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

Hi,

has anyone succesfully used C++ on PSoC? I want to use a C++ source code. On the first run I want to know if it will fit into a 5LP. I switched to the latest ARM GCC release (9-2020-q2). I replaced the GCC exe file with the G++ exe file.

There was an issue in CyLib.c with the initialization of the SysTick Callbacks regarding the void* 0 pointer. Replacing it with "nullptr" resolved the issue. Now, it seems(!) that it can be linked. As expected, it won't fit into the device on the first run, the error message is:

Build error: <...>/xyz.elf section `.ARM.exidx' will not fit in region `rom'

The bad thing is that the .elf file is deleted directly after the build process - it can be seen shortly in file explorer. Trying to copy it while it exists results in a empty file, unfortunately. I assume the created file is filled with valuable content for checking how much the flash content is in size. Too bad that the output window doesn't show the size in this configuration.

There's also an error "cm3gcc.ld:91: undefined symbol `RomVectors' referenced in expression". I don't know if this is related to the error mentioned above.

So, I've two questions:

1) how to get the information regarding the build size / prevent that the .elf file is deleted

2) how to check what's going on with those RomVectors?

Regards

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

> has anyone succesfully used C++ on PSoC?

I answered I have.

But please note that C++ is not supported by PSoC Creator, so what we are doing is hacking

and not guaranteed nor recommended.

And I also can not guarantee nor recommend it (at least for the time being).

Having written above, you know, I tried my hack using CY8CKIT-059 😉

schematic

002-schematic.JPG

pins

003-pins.JPG

animal.h

==============

#ifndef _ANIMAL_H_

#define _ANIMAL_H_

extern "C" {

#include "project.h"

}

#include "stdio.h"

  

class animal {

public:

    animal(char *name) ;

    ~animal() ;

    void move(int x, int y) ;

    void go(int x, int y) ;

private:

    char *_name ;

    int _x ;

    int _y ;

} ;

#endif /* _ANIMAL_H_ */

==============

animal.cpp

==============

extern "C" {

#include "project.h"

}

#include <stdio.h>

#include <string.h>

#include "main.h"

#include "animal.h"

animal::animal(char *name)

{

    _name = new char[strlen(name) + 1] ;

    strcpy(_name, name) ;

    _x = 0 ;

    _y = 0 ;

}

animal::~animal(void)

{

    delete [] _name ;

    _x = 0 ;

    _y = 0 ;

}

void animal::move(int x, int y)

{

    _x += x ;

    _y += y ;

    snprintf(str, STR_LEN, "%s moved to %d %d\n",_name, _x, _y) ;

    print(str) ;

}

void animal::go(int x, int y)

{

    _x = x ;

    _y = y ;

    snprintf(str, STR_LEN, "%s moved to %d %d\n",_name, _x, _y) ;

    print(str) ;

}

==============

main.h

==============

#ifndef _MAIN_H_

#define _MAIN_H_

extern "C" {

#include "project.h"

extern char str[] ;

extern void print(char *str) ;

}

#define STR_LEN 64

void *operator new(size_t size) ;

void  operator delete(void *ptr) ;

void *operator new[] (size_t size) ;

void  operator delete[] (void *ptr) ;

#endif /* _MAIN_H_ */

==============

main.cpp

==============

extern "C" {

#include "project.h"

}

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include "animal.h"

#include "main.h"

char str[STR_LEN+1] ;

void print(char *str)

{

    UART_PutString(str) ;

}

void init_hardware(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

}

int main(void)

{

    animal *cat ;

  

    init_hardware() ;

  

    print("\x1b[2J\x1b[;H") ;

    print("PSoC 5LP C++ Test (Experimental) ") ;

    snprintf(str, STR_LEN, "(%s %s)\n", __DATE__,__TIME__) ;

    print(str) ;

  

    cat = new animal("mikan") ;

  

    cat->move(3, 3) ;

    cat->move(3, 3) ;

    cat->go(2, 4) ;

  

    for(;;) {

    }

}

void *operator new(size_t size)

{

    return malloc(size) ;

}

void operator delete(void *ptr)

{

    free(ptr) ;

}

void *operator new[] (size_t size)

{

    return malloc(size) ;

}

void operator delete[] (void *ptr)

{

    free(ptr) ;

}

==============

Tera Term Log

001-tera-term-log.JPG

So the good news is at least my c++ program could be compiled and my cat can walk a little.

The bad news is that there is no one who will guarantee nor support for further exploration.

moto

View solution in original post

0 Likes
10 Replies