Skip to main content
LHarm.1
Associate III
April 18, 2023
Question

SPI example on Nucleo-g474

  • April 18, 2023
  • 3 replies
  • 1571 views

I'm using a Nucleo-g474RE

I want to use a timer / DMA to trigger a SPI Rx only transfer to memory.

I need to transfer two 9 bit words every trigger, 1 uSecs, and 4096 two word transfers

Can anyone point me to an MX cube example?

This topic has been closed for replies.

3 replies

waclawek.jan
Super User
April 18, 2023

Whatever you do, avoid Rx only with SPI.

JW

ST Technical Moderator
April 24, 2023

Hello @LHarm.1​, 

You can get started with this example. You need to consider reconfiguring SPI, DMA to perform a receive only continuous SPI transfer each timer trigger. Also, you add and set up the timer then request channel for DMA. Here is an example to start SPI then prepare TIM DMA to SPI

/* Start SPI RX DMA */
 SET_BIT(hspi1.Instance->CR2, SPI_RXFIFO_THRESHOLD);
 HAL_DMA_Start_IT(hspi1.hdmarx, (uint32_t)&hspi1.Instance->DR, (uint32_t)rxBuffer, RX_BUFFER_LENGTH);
 SET_BIT(hspi1.Instance->CR2, SPI_CR2_RXDMAEN);
 __HAL_SPI_ENABLE(&hspi1);
 
 /* Prepare TIM DMA to SPI_DR */
 HAL_DMA_Start(htim1.hdma[TIM_DMA_ID_UPDATE], (uint32_t)&txBuffer, (uint32_t)&hspi1.Instance->DR, 1);
 __HAL_TIM_ENABLE_DMA(&htim1, TIM_DMA_UPDATE);
 
 /* Start the timer */
 __HAL_TIM_ENABLE(&htim1);

Later some modifications are necessary to synchronize SPI and Timer. Otherwise, you can use a capture compare Timer. For further details about data transmission using DMA check the reference manual section 39.5.9 Data transmission and reception procedures and the subsection Communication using DMA.

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
LHarm.1
LHarm.1Author
Associate III
April 24, 2023

Thanks, I'll take a look.