2021-10-21 03:26 AM
I am struggling on SPI Master receive on STM32F407-disco board.
I plan to interface to the microphone using SPI2 master receive.
I setup the DMA but I always get to HAL_SPI_ErrorCallback().
I setup the same setup using Nucleo-G474 but it can go to HAL_SPI_RxCpltCallback().
I used the same codes for both G474 and F407.
HAL_SPI_Receive_DMA(&hspi2, receive_data, 5);
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
{
printf("SPI Received! \n");
}
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)
{
printf("TRANSFER_ERROR! \n");
}
I am using CubeMX to setup F407 as shown below.
F407 parameter setting
F407 DMA setting
I used the same on G474 as shown below.
G474 parameter setting
G474 DMA setting
Basically everything is almost the same.
When debug, I checked the before and after HAL_SPI_Receive_DMA() of both SPI and DMA register data as shown below.
G474 DMA1 before HAL_SPI_Receive_DMA()
G474 DMA1 after HAL_SPI_Receive_DMA()
G474 SPI2 before HAL_SPI_Receive_DMA()
G474 SPI2 after HAL_SPI_Receive_DMA()
F407 DMA1 before HAL_SPI_Receive_DMA()
F407 DMA1 after HAL_SPI_Receive_DMA()
Any idea what did I miss? I am using CubeIDE 1.7.0 and STM32Cube_FW_F4_V1.26.2 and STM32Cube_FW_G4_V1.4.0.
Here are the IOC files for both devices.
Solved! Go to Solution.
2021-10-21 07:41 AM
Within HAL_SPI_ErrorCallback, what is the error code stored in hspi->ErrorCode?
Receive-only mode on the SPI is odd and could be causing issues. Using two-way transfer using MOSI uninitialized may work better.
2021-10-21 07:41 AM
Within HAL_SPI_ErrorCallback, what is the error code stored in hspi->ErrorCode?
Receive-only mode on the SPI is odd and could be causing issues. Using two-way transfer using MOSI uninitialized may work better.
2021-10-22 02:10 AM
So the error code is 32 using this code.
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)
{
UNUSED(hspi);
printf("HAL_SPI_ErrorCallback : Error code %d \n", hspi->ErrorCode);
}
When I changed to FullDuplex Master, it is working, though I wont be using the MOSI.
HAL_SPI_TransmitReceive_DMA(&hspi2, send_data, receive_data, 5);
Goes to
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
{
UNUSED(hspi);
printf("HAL_SPI_TxRxCpltCallback \n");
}
while
HAL_SPI_Receive_DMA(&hspi2, receive_data, 5);
goes to
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
{
UNUSED(hspi);
printf("HAL_SPI_RxCpltCallback \n");
}
So I guess the errors would be
#define HAL_SPI_ERROR_NONE (0x00000000U) /*!< No error */
#define HAL_SPI_ERROR_MODF (0x00000001U) /*!< MODF error */
#define HAL_SPI_ERROR_CRC (0x00000002U) /*!< CRC error */
#define HAL_SPI_ERROR_OVR (0x00000004U) /*!< OVR error */
#define HAL_SPI_ERROR_FRE (0x00000008U) /*!< FRE error */
#define HAL_SPI_ERROR_DMA (0x00000010U) /*!< DMA transfer error */
#define HAL_SPI_ERROR_FLAG (0x00000020U) /*!< Error on RXNE/TXE/BSY Flag */
#define HAL_SPI_ERROR_ABORT (0x00000040U) /*!< Error during SPI Abort procedure */
HAL_SPI_ERROR_CRC + HAL_SPI_ERROR_DMA + HAL_SPI_ERROR_FLAG?
In case I would need the extra IO and still pursue Master Receive DMA only, how to tackle this problem?
2021-10-22 07:04 AM
> HAL_SPI_ERROR_CRC + HAL_SPI_ERROR_DMA + HAL_SPI_ERROR_FLAG?
The error is 32, which is 0x20, which is HAL_SPI_ERROR_FLAG. Most like due to the RXNE flag due to the clock not stopping at the end of the data you want to receive.
> In case I would need the extra IO and still pursue Master Receive DMA only, how to tackle this problem?
You can just leave the pin uninitialized since you don't care about that data.
I do think you'll need an additional DMA stream for the TX data, but it doesn't matter what you're sending, as long as it's valid memory. One option would be to use the same buffer for TX and RX.
2021-10-22 10:54 AM
> The error is 32, which is 0x20, which is HAL_SPI_ERROR_FLAG. Most like due to the RXNE flag due to the clock not stopping at the end of the data you want to receive.
Sorry my bad, yes I can see the CLK continuously pulsing and giving the clock/waveform.
> You can just leave the pin uninitialized since you don't care about that data.
I may not use the IO but ST should at least take a look at why there is an error.
Thanks for the help btw.