Skip to content

Adafruit Feather STM32F405: undefined reference to Serial1 #1990

Closed
@zfields

Description

@zfields

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions