Pi Pico Serial pointer

My first attempt to use a Pi Pico.
I am using Earle Philhower's core wit the board selected as Raspberry Pi Pico W

I want a function to which I can pass the required setup parameters and have the function configure the serial ports as desired (I've done similar with the 4809 without issue).

This compiles OK:

#include "Arduino.h"        // I know, it's included automatically, 
                            // I have included it to make this example close to the actual, much larger, sketch I am working on.


void setup_serial(HardwareSerial* ptr = nullptr, uint8_t RxPin = 2, uint8_t TxPin = 1, uint32_t baudRate = 9600);

void setup() {
    setup_serial(&Serial1, 2, 1, 115200);
}

void loop() {
}

void setup_serial(HardwareSerial * ptr, uint8_t RxPin, uint8_t TxPin, uint32_t baudRate) {
    if (ptr != nullptr) {
        Serial1.end();
        Serial1.setRX(RxPin);
        Serial1.setTX(TxPin);
        Serial1.begin(baudRate);
        
        //ptr -> end();
        //ptr -> setRX(RxPin);
        //ptr -> setTX(TxPin);
        //ptr -> begin(baudRate);
    }
}

So that tells me that the class that contains the function begin also contains the functions setRX and setTX.

If I change the code to this then it fails:

#include "Arduino.h"        // I know, it's included automatically, 
                            // I have included it to make this example close to the actual, much larger, sketch I am working on.

void setup_serial(HardwareSerial* ptr = nullptr, uint8_t RxPin = 2, uint8_t TxPin = 1, uint32_t baudRate = 9600);

void setup() {
    setup_serial(&Serial1, 2, 1, 115200);
}

void loop() {
}

void setup_serial(HardwareSerial * ptr, uint8_t RxPin, uint8_t TxPin, uint32_t baudRate) {
    if (ptr != nullptr) {
        //Serial1.end();
        //Serial1.setRX(RxPin);
        //Serial1.setTX(TxPin);
        //Serial1.begin(baudRate);
        
        ptr -> end();
        ptr -> setRX(RxPin);
        ptr -> setTX(TxPin);
        ptr -> begin(baudRate);
    }
}

The error message is:
C:\Users\Perry Bebbington\Documents\Arduino\Forum questions\pi_pico_serial_setup\pi_pico_serial_setup.ino: In function 'void setup_serial(arduino::HardwareSerial*, uint8_t, uint8_t, uint32_t)':
pi_pico_serial_setup:22:16: error: 'class arduino::HardwareSerial' has no member named 'setRX'
   22 |         ptr -> setRX(RxPin);
      |                ^~~~~
pi_pico_serial_setup:23:16: error: 'class arduino::HardwareSerial' has no member named 'setTX'
   23 |         ptr -> setTX(TxPin);
      |                ^~~~~
exit status 1
'class arduino::HardwareSerial' has no member named 'setRX'

So my guess is that the class I really want isn't the Arduino HardwareSerial but some other class inside Earle Philhower's core. Is this correct? If so, I don't know how to find it because of the vast number of files involved. I've searched header files with names that look likely and not found it. Or maybe I've got the wrong idea.

Suggestions and help welcome please.

is this your core??

/cores/rp2040/SerialUART.h

good luck.. ~q

Yes!

And it contains the class and the member functions I was looking for!

More testing required, but I think that was the answer I was looking for.

So, this leads to a common frustration for me: How did you find it so quickly? I have spent ages trawling through header files and not found it, it seem to have taken you 30 seconds. What's the secret?

google.. :slight_smile:

1 Like

What IDE are you using? Any of them but Arduino 1.x have the ability to trace and object or class back its definition.

1 Like

1.8.19

That would have been useful. MPLABX has all sorts of things like that, very helpful, but no use for Arduino.
I've used 2.x once, didn't like it, continued with 1.x, mostly does what I want.

For the benefit of anyone else reading this here is the code that compiles:

#include "Arduino.h"        // I know, it's included automatically, 
                            // I have included it to make this example close to the actual, much larger, sketch I am working on.

void setup_serial(SerialUART* ptr = nullptr, uint8_t RxPin = 2, uint8_t TxPin = 1, uint32_t baudRate = 9600);

void setup() {
    setup_serial(&Serial1, 2, 1, 115200);
}

void loop() {
    // put your main code here, to run repeatedly:
}

void setup_serial(SerialUART * ptr, uint8_t RxPin, uint8_t TxPin, uint32_t baudRate) {
    if (ptr != nullptr) {
        //Serial1.end();
        //Serial1.setRX(RxPin);
        //Serial1.setTX(TxPin);
        //Serial1.begin(baudRate);
        
        ptr -> end();
        ptr -> setRX(RxPin);
        ptr -> setTX(TxPin);
        ptr -> begin(baudRate);
    }
}
2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.