HAL Library 33- DMA extension for SPI on STM32Fxxx

SPI DMA library allows you to send and receive data via SPI in non-blocking mode. It can be use for TX only, RX only or both (transmissing mode).

This library is extension for my SPI library. It requires SPI library as basic to make this to work.

Library

Read more about HAL libraries

Features

  • SPI extension for non-blocking TX, RX or both modes
  • Supports all SPI peripherals on STM32F4 and STM32F7 device
  • Supports interrupt processing
  • Allows you to start DMA transmissing and wait till done
    • This is handy when working with RTOS for example and when you have to wait transmissing

Dependencies

  • HAL
  • TM
    • STM32Fxxx HAL
    • defines.h configuration file
    • TM DMA
    • TM SPI

Pinout, functions and enumerations

Pinout, list of functions and its enumerations can be found on SPI library API and SPI DMA library API.

Example

SPI DMA example is available on my Github account.

Icon
TM STM32 Libraries

STM32 libraries based on STM32Fxxx HAL drivers.

tilz0R

Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!
  • Imran

    Hi there!
    I am using STM32F7 Discovery board (STM32F746NGH6 to be exact). I downloaded your libraries and example code. I was particularly interested in SPI with DMA extension. So I loaded your example no. 33 titled 33-STM32Fxxx_DMA_SPI. I selected STM32F7_DISCOVERY as the target and ran your program without any modification. I shorted the MOSI and MISO pins which are Pin no. 4 and 5 on Arduino header for the sample given. But everytime I run the project I get “SPI Memory Fail” on the serial port. So I tried debugging it and by setting a breakpoint at
    if (memcmp(SPI_TX, SPI_RX, TX_SIZE) == 0)

    I can see that SPI_TX contains the valid data but SPI_RX is all zeroes.

    So I hook up an oscilloscope to the pins. I can see the clock on the SPI2_SCK pin which is pin no. 6 on the Arduino header. But when I hook the scope on the MOSI pin I get nothing. i.e no pulse or anything. Then I removed the connection between MOSI and MISO and then connected MISO to 3.3V so that it is always high. Then I ran the program but again at the breakpoint SPI_RX is all zeroes. Can you help me what am I doing wrong? the only modification that I did to your program was to Define USART as USART6 for it to be used with the Serial Port on the Arduino Header.
    Imran
    Islamabad, Pakistan.

    • Did you short MISO and MOSI pins? You have to read something, in example you read directly MOSI output on MISO input. That’s the idea.

      • Imran

        Thanks for the reply….. Yes this is the first thing that I did…. I connected the MISO and MOSI pins together. When I set breakpoint at

        if (memcmp(SPI_TX, SPI_RX, TX_SIZE) == 0)

        I can see that SPI_TX contains the valid data but SPI_RX is all zeroes.

        So for the example titled 33-STM32Fxxx_DMA_SPI I donot get any reply at all. In fact the code never outputs anything on the MOSI line (Verified by scope). The clock is outputed on the SPI2_SCK pin though.

        When I tried your Library No. 8 titled 08-STM32Fxxx_SPI I get the following response

        Transmit (0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E)

        and in the receive I get

        Transmit (0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B)

        So again I don’t receive what I transmitted. But at least I get something. For the DMA extension for SPI I don’t get anything back.