diff --git a/arch/arm/src/samv7/sam_spi_slave.c b/arch/arm/src/samv7/sam_spi_slave.c index 71e54057df..a156254b19 100644 --- a/arch/arm/src/samv7/sam_spi_slave.c +++ b/arch/arm/src/samv7/sam_spi_slave.c @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -1149,23 +1150,30 @@ struct spi_sctrlr_s *sam_spi_slave_initialize(int port) DEBUGASSERT(spino == 1); #endif - /* Allocate a new state structure for this chip select. NOTE that there - * is no protection if the same chip select is used in two different - * chip select structures. - */ - - priv = (struct sam_spidev_s *)zalloc(sizeof(struct sam_spidev_s)); - if (!priv) +#if defined(CONFIG_SAMV7_SPI0_SLAVE) && defined(CONFIG_SAMV7_SPI1_SLAVE) + if (spino == 0) { - spidbg("ERROR: Failed to allocate a chip select structure\n"); - return NULL; + priv = &g_spi0_sctrlr; + } + else + { + priv = &g_spi1_sctrlr; } +#elif defined(CONFIG_SAMV7_SPI0_SLAVE) + priv = &g_spi0_sctrlr; + +#elif defined(CONFIG_SAMV7_SPI1_SLAVE) + priv = &g_spi1_sctrlr; +#endif + /* Set up the initial state for this chip select structure. Other fields - * were zeroed by zalloc(). + * are zeroed. */ - /* Initialize the SPI operations */ + memset(priv, 0, sizeof(struct sam_spidev_s)); + + /* Initialize the SPI operations */ priv->sctrlr.ops = &g_sctrlr_ops;