Closed saloid closed 4 years ago
Example: I am using STM32F103RCT6 mcu.
| Pins | CubeMX | with USB | without USB |
|------------|--------|----------|-------------|
| PC10, PC11 | UART4 | Serial4 | Serial3 |
| PA2, PA3 | USART2 | Serial2 | Serial1 |
Yes, you are right. The solution would be to assign Serial x always to the corresponding U(S)ART interface, and leave Serial only for USB serial. Can you prepare a PR which solves that?
I have checked and found that Serial number assigns in every board individually. https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/e009a060eb58e4a7a619e07557ac7f476fc20915/STM32F1/variants/generic_stm32f103c/board.cpp#L127-L139 How better to do in this case? Change it in every board and add #warning that Serial has changed?
And if no SERIAL_USB in this board, maybe better to define Serial as Serial1?
I think no warning is necessary because when SERIAL_USB is not defined then
#define Serial Serial1
should do the trick.
I mean if somebody already use shifted numbers (like me), and they will be no more shifted - in this case I'd prefer to be warned. And how about changing this - I need to change it in all boards, right?
Yes, you need to change that for all boards.
This could break compatibility with older sketches that expect that behavior. I remember it has been like that forever.
PR merged.
Hello, if I am using board without USB, all serial ports are shifted, so I should use Serial3 when i mean 4 port (in stm32CubeMX it's 4 port, and if i turn on
SERIAL_USB
it is 4 port too). https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/a3a56866505eeca4b49fc435700dcd4bd5540c8c/STM32F1/cores/maple/HardwareSerial.h#L184-L222 I think port numbers should be always the same (in old versions of this file they were same) and for example ifSERIAL_USB
disabled defineSerial
asSerial1