Skip to main content
HDaji.1
Senior
September 6, 2021
Question

problem in LL SPI example code

  • September 6, 2021
  • 2 replies
  • 4260 views

I have been testing Examples_LL code (SPI_TwoBoards_FullDuplex_DMA_Master_Init ) in STM32Cube_FW_G4_V1.4.0 package.

Here is my problem:

I modified the original code such that I only need one board.

/* Enable the SPI1 peripheral */
 Activate_SPI();
 
 /* Wait for the end of the transfer and check received data */
 /* LED blinking FAST during waiting time */
 //WaitAndCheckEndOfTransfer();
 /* USER CODE END 2 */
 
 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */
 LL_mDelay(1);
 //while (ubTransmissionComplete != 1)
 //{
 //}
 
 LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_3);
 
 /* USER CODE BEGIN 3 */
 }

In the while loop, I keeps calling LL_DMA_EnableChannel, expecting to see repeated transmitting SPI message.

I used PicoScope to monitor SCLK and MOSI lines signal as showed below (D3 and D4). I expected repeated signals in those two lines, which did not happen. As showed in the picture below SPI transmission only happens once.

0693W00000DmFfgQAF.jpg 

Another weird thing is that I define uint8_t aTxBuffer[] = {0x01, 0x02, 0x03, 0x04}; so I expect SPI to transmit 4 bytes out in MOSI line. What I captured is

 0693W00000DmFvZQAV.jpgD3 is clock and D4 is MOSI. Obviously, the signals are far off from what is expected.

In fact, I did something similar with Nucleo-F411RE and example code SPI_TwoBoards_FullDuplex_DMA in package STM32Cube_FW_F4_V1.26.0, for which there is no problem. The only difference I notice is the function call to transmit SPI data: in F4 package it is called LL_DMA_EnableStream, while in G4 LL_DMA_EnableChannel.

I cannot find LL_DMA_EnableStream in STM32G4 HAL and low-layer drivers manual. BTW, the function descriptions in both HAL and low-layer driver manuals are sometimes too simple to be helpful.

This topic has been closed for replies.

2 replies

Amel NASRI
Technical Moderator
September 9, 2021

Hi @HDaji.1​ ,

DMA peripheral isn't the same when comparing STM32G4 to STM32F4.

You can review the following 2 application notes to understand more about the difference between both of them:

  • AN4031: Using the STM32F2, STM32F4 and STM32F7 Series DMA controller 
  • AN2548: Using the STM32F0/F1/F3/Gx/Lx Series DMA controller

Now, as you have only one board, why don't you use the example STM32Cube_FW_G4\Projects\NUCLEO-G474RE\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA?

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
HDaji.1
HDaji.1Author
Senior
September 10, 2021

@Amel NASRI​ Thanks for your info.

I just want to transmit a few bytes to another device through SPI the fastest as the MCU can do.

HDaji.1
HDaji.1Author
Senior
September 10, 2021

Purely based on example code in SPI_TwoBoards_FullDuplex_DMA: one possible way, to achieve repeated sending out a few bytes through SPI, could be to disable the DMA channel after SPI transmission has completed and re-enable it later. However, it seems not as efficient as the case in F4, whereby one enabling function does the job.