2018-10-10 06:04 AM
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)?
2023-10-05 02:13 PM
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.
2023-10-05 02:25 PM - last edited on 2023-10-06 01:40 AM by Amelie ACKERMANN
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.
2023-10-05 05:38 PM - edited 2023-10-06 10:55 AM
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.
2023-10-05 05:39 PM
So is that a feature request and not a bug?