2016-03-24 03:17 AM
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. #spi-flash-speed #no-hablo-hal2016-03-24 04:16 AM
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.2016-03-24 07:42 AM
2016-03-24 08:34 AM
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-
2016-03-29 12:31 AM
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);2016-03-29 12:44 AM
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.2016-03-29 01:29 AM
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...