rogerclarkmelbourne / Arduino_STM32

Arduino STM32. Hardware files to support STM32 boards, on Arduino IDE 1.8.x including LeafLabs Maple and other generic STM32F103 boards
Other
2.54k stars 1.26k forks source link

Serial numbers are shifted if not using SERIAL_USB #655

Closed saloid closed 4 years ago

saloid commented 5 years ago

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 if SERIAL_USB disabled define Serial as Serial1

saloid commented 5 years ago

Example: I am using STM32F103RCT6 mcu.

| Pins       | CubeMX | with USB | without USB |
|------------|--------|----------|-------------|
| PC10, PC11 | UART4  | Serial4  | Serial3     |
| PA2, PA3   | USART2 | Serial2  | Serial1     |
stevstrong commented 5 years ago

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?

saloid commented 5 years ago

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?

saloid commented 5 years ago

And if no SERIAL_USB in this board, maybe better to define Serial as Serial1?

stevstrong commented 5 years ago

I think no warning is necessary because when SERIAL_USB is not defined then #define Serial Serial1 should do the trick.

saloid commented 5 years ago

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?

stevstrong commented 5 years ago

Yes, you need to change that for all boards.

victorpv commented 4 years ago

This could break compatibility with older sketches that expect that behavior. I remember it has been like that forever.

stevstrong commented 4 years ago

PR merged.