Skip to content

Adafruit Feather STM32F405: undefined reference to Serial1 #1990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zfields opened this issue Apr 2, 2023 · 1 comment
Closed

Adafruit Feather STM32F405: undefined reference to Serial1 #1990

zfields opened this issue Apr 2, 2023 · 1 comment
Milestone

Comments

@zfields
Copy link
Contributor

zfields commented Apr 2, 2023

Describe the bug
The UART for the variant is misconfigured and Serial1 does NOT identify the Rx/Tx pins of the Adafruit Feather STM32F405.

Instead, Serial3 identifies Rx/Tx, as configured in the peripheral pins file, and targeted in the variant file.

#ifndef SERIAL_UART_INSTANCE
  #define SERIAL_UART_INSTANCE  3
#endif

Serial1 is the common interface for the Rx/Tx pins on Adafruit Feather boards. This can be validated by looking at the bottom of the variant header.

// SERIAL_PORT_HARDWARE       Hardware serial port, physical RX & TX pins.
...
#ifndef SERIAL_PORT_HARDWARE
  #define SERIAL_PORT_HARDWARE  Serial1
#endif

Not only is this unintuitive, but this breaks the portability of software between disparate Feather MCUs.

To Reproduce

Hardware:

  • Adafruit Feather STM32F405
  • FTDI cable

Firmware:

#define REPRO_ON_SERIAL 0

#if REPRO_ON_SERIAL == 0
  HardwareSerial txRxSerial(PIN_SERIAL_RX,PIN_SERIAL_TX);
#elif REPRO_ON_SERIAL == 1
  #define txRxSerial Serial1
#elif REPRO_ON_SERIAL == 2
  #define txRxSerial Serial2
#elif REPRO_ON_SERIAL == 3
  #define txRxSerial Serial3
#else
  #error "Unknown Repro Mode"
#endif

void setup (void) {
  txRxSerial.begin(115200);
  const size_t usb_timeout_ms = 3000;
  for (const size_t start_ms = millis(); !txRxSerial && (millis() - start_ms) < usb_timeout_ms;);
}

void loop (void) {
  txRxSerial.println("Hello, stm32duino!");
  ::delay(5000);
}

Steps to reproduce the behavior:

  1. Set REPRO_ON_SERIAL to the desired SerialX object to test.
  2. Open Serial Monitor
  3. See error

Expected behavior

  • When REPRO_ON_SERIAL is either 0 or 3, then the sketch will write "Hello, stm32duino!" on the Rx/Tx pins.
  • When REPRO_ON_SERIAL is either 1 or 2, then the sketch will fail to compile.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Linux (Pop!_OS)
  • Arduino IDE version: 1.8.19
  • STM32 core version: 2.5.0
  • Tools menu settings if not the default:
    • U(S)ART support: Enabled (generic 'Serial')
    • USB support (if available): CDC (generic 'Serial' supercede U(S)ART)
    • USB speed (if available): Low/Full Speed
    • Optimize: Debug (-Og)
    • Debug symbols and core logs: Symbols Enabled (-g)
    • C Runtime Library: Newlib Nano (default)
  • Upload method: SWD

Board (please complete the following information):

  • Name: Adafruit Feather STM32F405

Additional context

I noticed something else strange about the configuration while I was looking through it. You specify the RX pin for UART2 in the configuration, but not the TX pin:
https://github.com/stm32duino/Arduino_Core_STM32/blob/main/variants/STM32F4xx/F405RGT_F415RGT/PeripheralPins_FEATHER_F405.c#L175

@fpistm fpistm added this to the 2.6.0 milestone Apr 3, 2023
@fpistm
Copy link
Member

fpistm commented Apr 3, 2023

Hi @zfields
OK, will update to this:

  #ifndef SERIAL_PORT_HARDWARE
    #define SERIAL_PORT_HARDWARE  Serial3
  #endif

About

  • When REPRO_ON_SERIAL is either 1 or 2, then the sketch will fail to compile.

This is normal, only one default Serialx is instantiate and mapped to Serial. Up to you to instantiate Serial1 and Serial2.
See https://github.com/stm32duino/Arduino_Core_STM32/wiki/API#hardwareserial

About UART2, yes, probably PA2 was commented because it is not connected. I will comment also PA3.

@fpistm fpistm closed this as completed in 8363c25 Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants