cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a possible bug in function HAL_SPI_Transmit_DMA() (STM32Cube_FW_H7_V1.3.0)?

ddl22
Associate

Hi everyone!

I'm trying to transmit some data using SPI2 on a NUCLEO-H743ZI board (only TX). To do it fast I'm using DMA with HAL_SPI_Transmit_DMA(), but it returns with an error (from line 1465 in stm32h7xx_hal_spi.c):

/* Packing mode management is enabled by the DMA settings */
  if (((hspi->Init.DataSize > SPI_DATASIZE_16BIT) && (hspi->hdmarx->Init.MemDataAlignment != DMA_MDATAALIGN_WORD))    || \
      ((hspi->Init.DataSize > SPI_DATASIZE_8BIT) && ((hspi->hdmarx->Init.MemDataAlignment != DMA_MDATAALIGN_HALFWORD) && \
                                                         (hspi->hdmarx->Init.MemDataAlignment != DMA_MDATAALIGN_WORD))))
  {
    /* Restriction the DMA data received is not allowed in this mode */
    errorcode = HAL_ERROR;
    __HAL_UNLOCK(hspi);
    return errorcode;
  }

After replacing 'hdmarx' to 'hdmatx' (as I'm only trying to transmit some data and I'm not interested in receiving) it works as it supposed to.

Is this a possible bug, or am I just lucky to make it work somehow (I'm new to HAL)?

13 REPLIES 13

I tried changing the hdmarx and hdmartx values in the MX_SPI5_Init() call and this fixes the problem.

I found that the the HAL_SPI_Init() call includes a call to HAL_SPI_MspInit() and in there the hdma[rt]x values are hard coded to by Byte Aligned and nothing is done to provide for other alignments.

 

Piranha
Chief II

https://github.com/STMicroelectronics/STM32CubeH7/blob/dd1b1d7144e6c61f995a368bbbeaad1936d60cd1/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c#L2319-L2320

These two lines and other code in HAL drivers have a backslash at the end of line. This shows that the person, who wrote it, doesn't even understand the difference between C code and preprocessor macros.

Edited by moderators to adhere to community guidelines.

GreenGuy
Senior III

OK not a bug, but simply not aware of everything to touch.  In CubeMx the DMA selection for the SPI I am using needs to be configured as HALF_WORD.  This sets the DMA_MDATAALIGN_xxxx parameter.  Not sure with all the error checking that CubeMx does why it would allow 16 bit in the SPI setup and then align DMA as Byte which causes the HAL_ERROR.

 

GreenGuy
Senior III

So is that a feature request and not a bug?