[Solved] HardwareSerial 3 error on Maple Mini board

Post Reply
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

[Solved] HardwareSerial 3 error on Maple Mini board

Post by fredbox »

Code: Select all

HardwareSerial Serial3(USART3); // compiles
HardwareSerial Serial3(PB_11, PB_10); // compiles
HardwareSerial Serial3(PB11, PB10); // error: call of overloaded 'HardwareSerial(int, int)' is ambiguous
All three examples work if the board type is changed to a blue pill.
Casting PB11 to an int lets it compile. PB11 is defined as 0 in variant.h.
digitalPinToPinName(PB11) and PB_11 both print as 27.
I've been looking through cores/arduino/HardwareSerial.cpp and HardwareSerial.h for the problem but haven't spotted it.

Code: Select all

HardwareSerial::HardwareSerial(uint32_t _rx, uint32_t _tx)
I can't see why HardwareSerial() doesn't accept 0 as the first argument.

Code: Select all

HardwareSerial Serial3(0,1); //same as PB11, PB10 - error
HardwareSerial Serial3(2,1); // wrong values but compiles without error
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: HardwareSerial 3 error on Maple Mini board

Post by fpiSTM »

Right, seems strange.
Maybe a cache issue of the Arduino IDE. I will check if I can reproduce.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: HardwareSerial 3 error on Maple Mini board

Post by fpiSTM »

OK, I think, I found the issue.
Since the Half duplex was introduced, the error appears.

Code: Select all

    
- HardwareSerial(void *peripheral);
+ HardwareSerial(void *peripheral, bool halfDuplex = false);
So when 0 is used as first argument, the compiler doesn't know which constructor to use as 0 can be interpreted by NULL:

Code: Select all

    HardwareSerial(uint32_t _rx, uint32_t _tx);
    HardwareSerial(void *peripheral, bool halfDuplex = false);
as both prototype is valid.

One workaround is to use a cast:

Code: Select all

HardwareSerial Serial3((uint32_t)PB11, PB10);
Maybe this prototype can be added or changed the uint32_t to int:

Code: Select all

HardwareSerial(int _rx, int _tx);
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: HardwareSerial 3 error on Maple Mini board

Post by fredbox »

For "hello world" using the pin names gives the smallest code size:

Code: Select all

HardwareSerial Serial3((uint32_t)PB11,PB10);  // 8528 bytes flash - 676 bytes ram
HardwareSerial Serial3(USART3);          // 8452 bytes flash - 676 bytes ram
HardwareSerial Serial3(PB_11, PB_10);    // 8352 bytes flash - 676 bytes ram
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: HardwareSerial 3 error on Maple Mini board

Post by fpiSTM »

That is normal as PinName (PY_N) is the low level.
Using pin number PYN embeds the function to convert it to PinName.
Using peripheral name USARTx gave the PinName directly so it is an intermediate level.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: HardwareSerial 3 error on Maple Mini board

Post by fpiSTM »

@fredbox

I've made a PR on GitHub to fix this issue:
https://github.com/stm32duino/Arduino_C ... 2/pull/893

I define explicitly an enum then it is no more ambiguous.
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: HardwareSerial 3 error on Maple Mini board

Post by fredbox »

It was more of a puzzle to me than an actual problem. I'm reviewing the fix on Github to understand how you solved it. Thanks.
Post Reply

Return to “PR's bugs and enhancements”