Hi, I am trying to add a function called counter() to Serial.h.
I have done a lot of research and implemented the following, but I get an error.
I have tried to find a way to deal with the error but I am stuck.
Please give me some advice.
Descriptions in the standard library are omitted except for the counter() function. This is because no changes have been made.
Error Description
{path of the ino file}/sketch.ino: : undefined reference to `arduino::UART::counter()'
collect2.exe: error: ld returned 1 exit status
sketch.ino
#include "Serial.h"
UART *cuart;
void setup() {
Serial.begin(BAUD_RATE, SERIAL_8E1);
}
void loop(){
unsigned long value;
value = cuart->counter();
Serial.println(value);
}
Serial.h
...
class UART : public HardwareSerial {
public:
UART(int tx, int rx, int rts = -1, int cts = -1);
UART(PinName tx, PinName rx, PinName rts = NC, PinName cts = NC) : _tx(tx), _rx(rx), _rts(rts), _cts(cts) {}
UART() {
is_usb = true;
}
void begin(unsigned long);
void begin(unsigned long baudrate, uint16_t config);
void begin(unsigned long baudrate, uint16_t config, bool no_rx_pullup);
void end();
int available(void);
int peek(void);
int read(void);
void flush(void);
size_t write(uint8_t c);
size_t write(const uint8_t*, size_t);
using Print::write; // pull in write(str) and write(buf, size) from Print
operator bool();
operator mbed::FileHandle*(); // exposes the internal mbed object
unsigned long counter(void);
....
Serial.cpp
...
unsigned long UART::counter(void){
return 3;
}
...