cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 HAL_SPI_DMA usage for halfword to halfword transfer

RK.1
Associate II

Hi

I am trying to construct an SPI based device driver for an ADC which has 16 bit Frame size .The examples provided for SPI DMA showcases the use of uint_8 * buffers

//HAL_SPI_TransmitReceive_DMA(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE)//

.So i am currently using FIFO for change in data size between peripheral and memory and endian behavior reverses the data

Is there a simple way to use the HAL_SPI_TransmitReceive_DMA to handle halfword directly for the CubeMX setting for HALFWORD to HALFWORD transfer between memory and peripheral and

HALFWORD to HALFWORD transfer between peripheral and memory

for eg :

uint16_t aTxbuffer[]={0x0001,0x0100,0xf000};

uint16_T aRxBuffer[TXSIZE]={0};

HAL_SPI_TransmitReceive_DMA(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE)

Thanks in Advance

3 REPLIES 3

You normally set the transfer size in PSIZE and MSIZE fields of DMA_SxCR register, read DMA chapter in RM (only PSIZE matters in Direct mode i.e.DMA FIFO not used, which is most probably what you use). There are some similarly sounding fields in the init struct of DMA unit in the generated code too, have a look. I don't know how to click it in CubeMX, I don't use it.

JW

I get what you have assumed .I am very clear about my configuration .I am currently using a DMA FIFO for byte to halfword conversion since my HAL_DMA _TransmitReceive function only supports byte transfers.There is a byte order reversal when using it and i have to use dummy data to fill the FIFO buffer to trigger a transfer.But when using halfword to halfword transfer all gimmmicks like byte order reversal and dummy data for filling FIFO is not needed.My current project team is deadset on using HAL functions without any modifications,so that they can port it easily in the later generations.My question is this .Is there a "Readymade" HAL DMA transmit receive function which transmits halfword data and receives halfword data ?,Or is there a custom HAL DMA function where we can set the type of the data [byte ,halfword ,word]to be transmitted and received like I2C_Mem Functionality (for eg:HAL_I2C_MEM_write )

> my HAL_DMA _TransmitReceive function only supports byte transfers

The data size is probably set at initialization, in the DMA's initialization struct. The relevant fields are named misleadingly as "alignment", IIRC.

JW