Skip to content

un-useful and bloaty assert() in SPI library. #559

@WestfW

Description

@WestfW

The SPIClass Constructor in the SPI library contains an assert:

SPIClass::SPIClass(SERCOM *p_sercom, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI, SercomSpiTXPad PadTx, SercomRXPad PadRx) : settings(SPISettings(0, MSBFIRST, SPI_MODE0))
{
  initialized = false;
  assert(p_sercom != NULL);
  _p_sercom = p_sercom;

It turns out that assert() generates live code on samd processors, and the default (defined in newlib) function invokes fiprintf()
Since stdio isn't set up in most Arduino compiles, this is pretty useless, and it can cause code bloat in sketchs that include SPI.
(I think this is normally masked because there is only one SPI port on most SAMD platforms, so the constructor always optimizes away the assert. But it's an issue for boards with more than one SPI. See https://forums.adafruit.com/viewtopic.php?f=62&t=169034 )

(Note that this is the ONLY use of assert in the entire SAMD core.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions