Page 1 of 1

Problem with mmcConnect() function by SPI: the thread is suspended indefinitely

Posted: Mon Jul 20, 2020 12:22 pm
by sntnjrg
Hi,

I'm using the MMC over SPI driver to write data to a memory card using an STM32L4R5ZI-NUCLEO144 board. I'm using SP1 bus (8 bits) and these speeds:

Code: Select all

  //---------------------------------------------------------------------------
  // Maximum speed SPI configuration
  //---------------------------------------------------------------------------
  // 3.75 MBits/s, CPHA=0, CPOL=0, MSb first.
  //---------------------------------------------------------------------------
  static const SPIConfig highspeed = {
      // Enables the circular buffer mode.
      false,
      // Operation complete callback or @p NULL.
      NULL,
      // The chip select port.
      GPIOF,
      // The chip select pad number.
      14U,
      // SPI CR1 register initialization data.
      SPI_CR1_BR_2,
      // SPI CR2 register initialization data.
      SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0
  };
 
  //---------------------------------------------------------------------------
  // Low speed SPI configuration
  // 468.75 KBits/s, CPHA=0, CPOL=0, MSb first.
  //---------------------------------------------------------------------------
  static const SPIConfig lowspeed = {
      // Enables the circular buffer mode.
      false,
      // Operation complete callback or @p NULL.
      NULL,
      // The chip select port.
      GPIOF,
      // The chip select pad number.
      14U,
      // SPI CR1 register initialization data.
      SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0,
      // SPI CR2 register initialization data.
      SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0
  };


Occasionally, the mmconnect() function does not respond. After carrying out a trace, I have noticed that the program gets stuck on the line: (void) osalThreadSuspendS(&spip->thread); of the spiReceive() function.

Code: Select all

/**
 * @brief   Receives data from the SPI bus.
 * @details This synchronous function performs a receive operation.
 * @pre     In order to use this function the option @p SPI_USE_WAIT must be
 *          enabled.
 * @pre     In order to use this function the driver must have been configured
 *          without callbacks (@p end_cb = @p NULL).
 * @note    The buffers are organized as uint8_t arrays for data sizes below
 *          or equal to 8 bits else it is organized as uint16_t arrays.
 *
 * @param[in] spip      pointer to the @p SPIDriver object
 * @param[in] n         number of words to receive
 * @param[out] rxbuf    the pointer to the receive buffer
 *
 * @api
 */
void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) {

  osalDbgCheck((spip != NULL) && (n > 0U) && (rxbuf != NULL));
#if SPI_SUPPORTS_CIRCULAR
  osalDbgCheck((spip->config->circular == false) || ((n & 1U) == 0U));
#endif

  osalSysLock();
  osalDbgAssert(spip->state == SPI_READY, "not ready");
  spiStartReceiveI(spip, n, rxbuf);
  (void) osalThreadSuspendS(&spip->thread);
  osalSysUnlock();
}


I don't know why. Is it a problem with the specified speed (Prescaler 32: 3.75 MBits/s)? Why does the thread is suspended and never wake up?

Thanks.

Re: Problem with mmcConnect() function by SPI: the thread is suspended indefinitely

Posted: Mon Jul 20, 2020 12:38 pm
by Giovanni
Try to reduce speed and see if the problem is still there.

Giovanni

Re: Problem with mmcConnect() function by SPI: the thread is suspended indefinitely

Posted: Tue Jul 21, 2020 9:02 am
by sntnjrg
Hi Giovanni,

I was using an ARDUINO WIRELESS SD SHIELD as an SD card reader by SPI. I used another card reader and it works fine. I thought the Arduino Shield was compatible with STM32L4R5ZI-NUCLEO144 board.

Thanks for the help.