cancel
Showing results for 
Search instead for 
Did you mean: 

enhancing SPI flash reading speed

jeff23
Associate II
Posted on March 24, 2016 at 11:17

I have a stm32f439 board with a 128MB SPI flash in hand, this board also has a 32MB external RAM. My target is to copy the large scale data from flash to RAM.

So far I can read the data to RAM from flash by polling, however, the speed is quite limited. My SPI speed is set 42MHz, but the final flash read speed is only <8Mbps. The following figure shows the actual test result. Obviously there is a big interval between 2 SPI read, which waste quite a lot time, and so I want to reduce the interval between 2 SPI read. However, I don't know where can I do that modification.  I'm using ST's HAL driver for all SPI's operation, so far I'm always using the function ''HAL_SPI_TransmitReceive()'' to keep polling/receiving data. Still not sure if DMA receiving can improve it or not(principlly I don't think so because even in polling mode I do nothing but checking status and transceiving). For your convenience, I also put the ST's source code file[stm32f4xx_hal_spi.c] here.0690X000006038HQAQ.jpg

#spi-flash-speed #no-hablo-hal
6 REPLIES 6
Posted on March 24, 2016 at 12:16

Yes, it seems to be burning a hundred or so machine cycles between bytes which is slow even for HAL

Pretty sure I could saturate with DMA.

Posting code that is generally available is of less value than the code that is unique to the case being presented.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jeff23
Associate II
Posted on March 24, 2016 at 15:42

Hi Clive, many thanks for your confirmation. I'll try to use DMA to speed up the nand read. If you have any sample code which has same function, please share that with me. 

Walid FTITI_O
Senior II
Posted on March 24, 2016 at 16:34

Hi gu.jeff,

Try to use the DMA transfer. You can get inspired form “DMA_FLASHToRAM� example if you want to use only the DMA in STM32CubeF4 at this path STM32Cube_FW_F4_V1.11.0\Projects\STM32F429I-Discovery\Examples\DMA\DMA_FLASHToRAM

-Hannibal-

jeff23
Associate II
Posted on March 29, 2016 at 09:31

Hi, I met problem in applying DMA. Actually I'm using a external RAM when I copy data from Flash to RAM via SPI, not sure if DMA can work correctly when I use that external RAM. Here is my setting for using DMA, can you help check if this is correct?

 

 __HAL_RCC_DMA2_CLK_ENABLE();

 hDma_Spi4Tx.Instance    = DMA2_Stream1;

 hDma_Spi4Tx.Init.Channel   = DMA_CHANNEL_4;

 hDma_Spi4Tx.Init.Direction    = DMA_MEMORY_TO_PERIPH;

 hDma_Spi4Tx.Init.PeriphInc    = DMA_PINC_DISABLE;

 hDma_Spi4Tx.Init.MemInc     = DMA_MINC_ENABLE;

 hDma_Spi4Tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

 hDma_Spi4Tx.Init.MemDataAlignment  = DMA_MDATAALIGN_BYTE;

 hDma_Spi4Tx.Init.Mode     = DMA_NORMAL;

 hDma_Spi4Tx.Init.Priority    = DMA_PRIORITY_LOW;

 hDma_Spi4Tx.Init.FIFOMode    = DMA_FIFOMODE_DISABLE;

 hDma_Spi4Tx.Init.FIFOThreshold   = DMA_FIFO_THRESHOLD_FULL;

 hDma_Spi4Tx.Init.MemBurst    = DMA_MBURST_INC4;

 hDma_Spi4Tx.Init.PeriphBurst   = DMA_PBURST_INC4;

 HAL_DMA_Init(&hDma_Spi4Tx);

 /* Associate the initialized DMA handle to the UART handle */

  __HAL_LINKDMA(&hspiFlash, hdmatx, hDma_Spi4Tx);

  /* Configure the DMA handler for reception process */

 hDma_Spi4Rx.Instance     = DMA2_Stream0;

 hDma_Spi4Rx.Init.Channel    = DMA_CHANNEL_4;

 hDma_Spi4Rx.Init.Direction     = DMA_PERIPH_TO_MEMORY;

 hDma_Spi4Rx.Init.PeriphInc     = DMA_PINC_DISABLE;

 hDma_Spi4Rx.Init.MemInc     = DMA_MINC_ENABLE;

 hDma_Spi4Rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

 hDma_Spi4Rx.Init.MemDataAlignment   = DMA_MDATAALIGN_BYTE;

 hDma_Spi4Rx.Init.Mode      = DMA_NORMAL;

 hDma_Spi4Rx.Init.Priority     = DMA_PRIORITY_HIGH;

 hDma_Spi4Rx.Init.FIFOMode     = DMA_FIFOMODE_DISABLE;   

 hDma_Spi4Rx.Init.FIFOThreshold    = DMA_FIFO_THRESHOLD_FULL;

 hDma_Spi4Rx.Init.MemBurst     = DMA_MBURST_INC4;

 hDma_Spi4Rx.Init.PeriphBurst    = DMA_PBURST_INC4;

 HAL_DMA_Init(&hDma_Spi4Rx);

 __HAL_LINKDMA(&hspiFlash, hdmarx, hDma_Spi4Rx);

 /* NVIC configuration for DMA transfer complete interrupt (USARTx_TX) */

 HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0, 1);

 HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);

 HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 0, 0);

 HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);

 /* NVIC configuration for USART TC interrupt */ 

 HAL_NVIC_SetPriority(SPI4_IRQn, 0, 0);

 HAL_NVIC_EnableIRQ(SPI4_IRQn);

mark239955_stm1
Associate II
Posted on March 29, 2016 at 09:44

DMA2 should have no problem accessing external RAM via the FMC/FSMC.

However, depending on the type of external RAM, it may be slow to access due to a variety of factors, including the RAM technology and access speed, board layout and FMC/FSMC configuration.  If your RAM is slower than your SPI, then it will become the performance bottleneck.

jeff23
Associate II
Posted on March 29, 2016 at 10:29

0690X000006034uQAA.jpg

Put my SPI clock waveform here, The whole process seems OK, but there is data error. I don't have any good way for next...