stm32duino / Arduino_Core_STM32

STM32 core support for Arduino
https://github.com/stm32duino/Arduino_Core_STM32/wiki
Other
2.79k stars 967 forks source link

Serialx need to be more generic and flexible #113

Closed mahesh2000 closed 6 years ago

mahesh2000 commented 7 years ago

Serial3, which used to work back in 2016, is now broken. Fix is below:

..\STM32\hardware\stm32\2017.9.22\boards.txt ..\STM32\hardware\stm32\2017.9.22\variants\NUCLEO_L476RG\variant.h ..\STM32\hardware\stm32\2017.9.22\variants\NUCLEO_L476RG\variant.cpp

Cleanup in #defines for Serial3 is needed.

Also, in ..\STM32\hardware\stm32\2017.9.22\variants\NUCLEO_L476RG\PeripheralPins.c, const PinMap PinMap_UART_TX[] has UART4 mapped to both PA_0 and PC_10. is this correct? the same with PA_1 and PC_11.

NUCLEO_L476RG.zip

fpistm commented 7 years ago

Hi @mahesh2000,

I think you talk about: https://github.com/stm32duino/Arduino_Core_STM32L4/blob/d30e65eed475fcdcafb9ce26e74be1055af860a5/variants/STM32L476RG_Nucleo/variant.cpp#L145

It is not really broken. Serial3 (map to UART4) is only not defined by default in this core. For the PeriperalPins.c this is correct. You can use one or the other pin to the Serial connection. Ex:

HardwareSerial Serial3(PA_1, PA_0);
HardwareSerial Serial3(PC_11, PA_0);
HardwareSerial Serial3(PA_1, PC_10);
HardwareSerial Serial3(PC_11, PC_10);

It's up to you to connect the serial interface on the right pins.

Howerver, I think you raised one issue: How to define an extra Serial and process it to the SerialEventRun() and define the related serialEventx();

mahesh2000 commented 6 years ago

hi, afaik, hardware serial ports numbers on the STM32L476 Nucleo-64 are specified to certain pins -- it would make sense to have the same nomenclature in the variant.cpp rather than let the user define his/her own. What do you think?

fpistm commented 6 years ago

Hi, in fact since #122 is merged, there is no more need to define HardwareSerial in the variant.cpp. Serial are now handle more generically. User could (re)define them from the sketch depending of his need (even the SerialEvent) If you want Serial3 enable the 'First third option in the Serial instance menu, this will enable the Serial 3.

fpistm commented 6 years ago

By default, when Serial 3 is enabled on Nucleo L476RG pins will be PB10(Tx) PB11(Rx). To change them call in the sketch:

  Serial.setRx(PC5);
  Serial.setTx(PC4);

before the Serial3.begin(9600)