stm32duino / Arduino_Core_STM32

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

SerialUSB and Hardware Serial1 & Serial2 support for custom board. #543

Closed svelmurugan92 closed 5 years ago

svelmurugan92 commented 5 years ago

Hello All,

Here is our BSP for STM32 https://github.com/mcci-catena/Arduino_Core_STM32

We add USB Serial or Generic serial or No serial options. For reference our variant file UART definitions. https://github.com/mcci-catena/Arduino_Core_STM32/blob/9864576a4cc77b25efe446da907acd7ba5c5e793/variants/CATENA_461x/variant.h#L124

// UART Definitions
// Define here Serial instance number to map on Serial generic name
#define SERIAL_UART_INSTANCE    1 //ex: 2 for Serial2 (USART2)
// Default pin used for 'Serial' instance (ex: ST-Link)
// Mandatory for Firmata
#define PIN_SERIAL_RX           D0
#define PIN_SERIAL_TX           D1

#ifdef __cplusplus
} // extern "C"
#endif
/*----------------------------------------------------------------------------
 *        Arduino objects - C++ only
 *----------------------------------------------------------------------------*/

#ifdef __cplusplus
// These serial port names are intended to allow libraries and architecture-neutral
// sketches to automatically default to the correct port name for a particular type
// of use.  For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
//
// SERIAL_PORT_MONITOR        Port which normally prints to the Arduino Serial Monitor
//
// SERIAL_PORT_USBVIRTUAL     Port which is USB virtual serial
//
// SERIAL_PORT_LINUXBRIDGE    Port which connects to a Linux system via Bridge library
//
// SERIAL_PORT_HARDWARE       Hardware serial port, physical RX & TX pins.
//
// SERIAL_PORT_HARDWARE_OPEN  Hardware serial ports which are open for use.  Their RX & TX
//                            pins are NOT connected to anything by default.
#ifdef USBCON
# define SERIAL_PORT_MONITOR  SerialUSB
#elif defined(NO_HWSERIAL)
# define SERIAL_PORT_MONITOR  SerialNo
#else
# define SERIAL_PORT_MONITOR  Serial
#endif
#define SERIAL_PORT_HARDWARE  Serial
#endif 

Would like to use both SerialUSB and Serial1 and Serial2 at same time. While select the USB serial in the Arduino IDE drop down and declare the hardware serial in the sketch returns below error

C:\Users\VELMUR~1\AppData\Local\Temp\arduino_build_685662\sketch\pms_7003_test.ino.cpp.o: In function `setup':

pms_7003_test.ino.cpp:(.text.setup+0x56): undefined reference to `HardwareSerial::begin(unsigned long, unsigned char)'

pms_7003_test.ino.cpp:(.text.setup+0x62): undefined reference to `HardwareSerial::begin(unsigned long, unsigned char)'

C:\Users\VELMUR~1\AppData\Local\Temp\arduino_build_685662\sketch\pms_7003_test.ino.cpp.o: In function `_GLOBAL__sub_I_Serial1':

pms_7003_test.ino.cpp:(.text.startup._GLOBAL__sub_I_Serial1+0x8): undefined reference to `HardwareSerial::HardwareSerial(unsigned long, unsigned long)'

pms_7003_test.ino.cpp:(.text.startup._GLOBAL__sub_I_Serial1+0x12): undefined reference to `HardwareSerial::HardwareSerial(unsigned long, unsigned long)'

collect2.exe: error: ld returned 1 exit status

Please share your views. Give some ideas to handle it.

Thank you in advance

fpistm commented 5 years ago

Hi @svelmurugan92, well looking at the log you have the answer:

pms_7003_test.ino.cpp:(.text.setup+0x56): undefined reference to 'HardwareSerial::begin(unsigned long, unsigned char)' https://github.com/mcci-catena/Arduino_Core_STM32/blob/9864576a4cc77b25efe446da907acd7ba5c5e793/cores/arduino/HardwareSerial.h#L112-L114

pms_7003_test.ino.cpp:(.text.startup._GLOBAL__sub_I_Serial1+0x8): undefined reference to 'HardwareSerial::HardwareSerial(unsigned long, unsigned long)'

https://github.com/mcci-catena/Arduino_Core_STM32/blob/9864576a4cc77b25efe446da907acd7ba5c5e793/cores/arduino/HardwareSerial.h#L109-L111

You don't have this prototype, so simply check your sketch and how you define your Serial1 instance. Type have to be the same or simply cast them.