cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_SPI_Transmit times out

KBunn.1
Associate II

I have STM32CubeIDE Version: 1.12.0 and a STM32MP157F evaluation board.

Created a M4 project and assigned SPI1 to it, generated the code.

I then created a function to read a register:

const uint16_t opcode = 0xe000;

uint8_t value = 0;

HAL_GPIO_WritePin(GPIOZ, GPIO_PIN_3, GPIO_PIN_RESET);

HAL_SPI_Transmit(&hspi1, &opcode, 2, 100);

HAL_SPI_Receive(&hspi1, &value, 1, 100);

HAL_GPIO_WritePin(GPIOZ, GPIO_PIN_3, GPIO_PIN_SET);

It always fails in HAL_SPI_Transmit at SPI_WaitOnFlagUntilTimeout.

Any ideas on why?

6 REPLIES 6
Bob S
Principal

I've no direct experience with the MP family. What flag is the SPI_WaitOnFlagUntilTimout() waiting for? Do you have SPI1 (and it's GPIO pins) mapped to the F4 (purely a guess - I've read that GPIO pins need to be mapped to whichever CPU core, don't know if peripherals do as well). Do you see any activity on the MOSI/MOSI lines? Also, you don't show your SPI init code,

KBunn.1
Associate II

It's waiting on SPI_FLAG_EOT.

And here's the SPI init code:

 /* SPI1 parameter configuration*/

 hspi1.Instance = SPI1;

 hspi1.Init.Mode = SPI_MODE_MASTER;

 hspi1.Init.Direction = SPI_DIRECTION_2LINES;

 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;

 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;

 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;

 hspi1.Init.NSS = SPI_NSS_SOFT;

 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;

 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;

 hspi1.Init.TIMode = SPI_TIMODE_DISABLE;

 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

 hspi1.Init.CRCPolynomial = 0x0;

 hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;

 hspi1.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;

 hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;

 hspi1.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;

 hspi1.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;

 hspi1.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;

 hspi1.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;

 hspi1.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;

 hspi1.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE;

 hspi1.Init.IOSwap = SPI_IO_SWAP_DISABLE;

 if (HAL_SPI_Init(&hspi1) != HAL_OK)

 {

   Error_Handler();

 }

MM..1
Chief II

Check Clock config and peripheral enabling calls. Too spi interrupt .

Pavel A.
Evangelist III

> It's waiting on SPI_FLAG_EOT

Need to set transfer size to 0, to prevent using "transfer" mode.

(don't remember how to do this with HAL).

Or, if you want to use the "transfer" mode, set it up correctly and check if there's related errata.

S.Ma
Principal

Use the SPI_TransmitReceive function. Data bits goes out while others are coming in.

Timed out waiting on SPI_FLAG_RXP.