Skip to content

fix(stm32): fl::Esp32SpiBus enumerators collide with CMSIS SPI2/SPI3 macros, breaking 7 ARM builds on master #4113

Closed

Description

@zackees

Master is red on seven boards

arduino_uno_q, check_stm32f103c8_bluepill_size, nucleo_f429zi, nucleo_f439zi, stm32f103c8_bluepill, stm32f103cb_maplemini, stm32f103tb_tinystm.

Failing since #4088 (c39dc599a6, "feat(esp32): select SPI host per controller"). Confirmed present on d68e1e50de, 809d0bd32d, 37c401a9ec and 6990cdc3e4 — it is not caused by any of those commits, it just predates them. I hit it while verifying master after #4112 and it is unrelated to that work.

Cause

src/fl/spi_bus.h:

enum class Esp32SpiBus : u8 {
    AUTO = 0,
    SPI2 = 2,
    SPI3 = 3,
};

On every STM32 target, CMSIS has already defined those names as object-like macros — stm32f439xx.h:1278:

#define SPI2 ((SPI_TypeDef *) SPI2_BASE)

so the preprocessor rewrites the enum body to

    ((SPI_TypeDef *) SPI2_BASE) = 2,

which is exactly the reported diagnostics:

stm32f439xx.h:1278:29: error: expected identifier before '(' token
stm32f439xx.h:1278:29: error: expected '}' before '(' token
stm32f439xx.h:1278:43: error: expected ')' before '*' token
lib/FastLED/fl/spi_bus.h:15:1: error: expected declaration before '}' token

The blast radius is wide because fl/spi_bus.h is included from fl/channels/cled_controller.h, which is core — so the enum is compiled on every platform, not just ESP32.

Options

  1. Rename the enumerators (BUS2/BUS3, or HOST2/HOST3). Cleanest. The public API cost is near zero: feat(esp32): select SPI host per controller (#1516) #4088 landed hours ago and examples/MultipleEsp32SpiBuses/MultipleEsp32SpiBuses.ino is the only caller.
  2. #undef SPI2 / #undef SPI3 in fl/spi_bus.h. One line, keeps the API — but a core library header quietly deleting a CMSIS peripheral macro would also delete it from user sketches on STM32. Rude, and a latent surprise.
  3. Compile the enum only under #if defined(ESP32). Leaves fl::Esp32SpiBus undeclared elsewhere, so every non-ESP32 reference in core would need guarding too.

Option 1 looks right. Flagging rather than doing it unilaterally since it renames a just-shipped public API — happy to take it if the shape is agreed.

Refs #4088

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions