Closed mhmayyan closed 5 years ago
Sorry you're having problems! This used to work, but I think we might have inadvertently taken this out in the recent BSP release. @chwon64, am I right? I don't see a USB + Hardware Serial setting on the 4612.
Yes, that's correct. There is no USB + Hardware Serial setting. So it is expected link error -- undefined Serial1.
@mhmayyan -- I entered an issue in the BSP https://github.com/mcci-catena/Arduino_Core_STM32/issues/70.
The BSP is rather limited; it would be great if you could locally declare an object in your sketch by writing;
HardwareSerial Serial1(USART1);
But I don't think that will work because of how they handle events. We'll have to rewrite that portion because it's very limiting for us.
However, if you are brave and want to edit your platform.txt, you should be able to add HAVE_HWSERIAL1
to the list of -D
symbols at compile time. You'll see how it's manipulated by the menus.
Thank you, Terry, for this help. I actually got the Serial1 working by the following modifications:-
In file: ../hardware/stm32/2.2.0/cores/arduino/HardwareSerial.cpp; line: 33
Before: #if !defined(NO_HWSERIAL)
After: #if !defined(NO_HWSERIAL) || defined (FORCE_USE_SERIAL1)
In file: ../hardware/stm32/2.2.1/cores/arduino/stm32/uart.h; line: 50
Before: #if !defined(NO_HWSERIAL)
After: #if !defined(NO_HWSERIAL) || defined (FORCE_USE_SERIAL1)
In file: ../hardware/stm32/2.2.0/cores/arduino/HardwareSerial.cpp; function: HardwareSerial::HardwareSerial(void* peripheral)
Before: #if defined(Serial) && defined(PIN_SERIAL_RX) && defined(PIN_SERIAL_TX)
After: #if defined(Serial) && defined(PIN_SERIAL_RX) && defined(PIN_SERIAL_TX) && !defined(FORCE_USE_SERIAL1)
In file: ../hardware/stm32/2.2.0/boards.txt; add the lines below to the block # menu.xserial
mcci_catena_4612.menu.xserial.usbAndSeial=USB and Serial1
mcci_catena_4612.menu.xserial.usbAndSeial.build.xSerial={build.usb_flags} -DNO_HWSERIAL -DFORCE_USE_SERIAL1
Restart Arduino IDE and select USB and Serial1 in the serial interface dropdown menu.
For testing purpose, I used the following code on two catena 4612 boards:-
void setup() {
Serial.begin(115200);
Serial1.begin(115200);
while(!Serial);
}
void loop() {
if (Serial.available()) { // If anything comes in Serial (USB),
Serial1.write(Serial.read()); // read it and send it out Serial1 (pins 0 & 1)
}
if (Serial1.available()) { // If anything comes in Serial1 (pins 0 & 1)
Serial.println(Serial1.read()); // read it and send it out Serial (USB)
}
}
Connections
Catena#1 || || Catena#2
RX----------------------TX TX-----------------------RX GND--------------------GND
However, I don't know if these modifications are consistent and safe for the rest of the libraries and classes.
@mhmayyan Our latest BSP release has feature to enables both USB serial + HW serial. Please update the BSP and try.
@svelmurugan92 yes, it works. That is neat. Thank you so much.
I am trying to use the hardware serial port along with the USB on Catena4612 (D0, D1). I used the SerialPassThrough example as shown below:-
`void setup() { Serial.begin(115200); Serial1.begin(115200); }
void loop() { if (Serial.available()) { // If anything comes in Serial (USB), Serial1.write(Serial.read()); // read it and send it out Serial1 (pins 0 & 1) }
if (Serial1.available()) { // If anything comes in Serial1 (pins 0 & 1) Serial.write(Serial1.read()); // read it and send it out Serial (USB) } }`
The compilation output is shown in the attached file.
SerialProblemOut.txt