SPI + DMA only transmitting half of total bytes sent?
- February 8, 2022
- 5 replies
- 2615 views
I am trying to setup SPI communication via DMA on the STM32L4S9AII6 MCU. It seems to be half working as you see in the image "SPI Bug". In this test I am sending a string of 6 bytes. As you can see, only the first half make it out of the MCU alive, but the MCU is obviously trying to send the full 6 bytes. This is over the SPI3 peripheral. Also note the PB12 signal at the bottom of the "SPI Bug" image attached. This is a GPO pin that I assert high when the "HAL_SPI_TxHalfCpltCallback" callback function is called. Likewise, I de-assert the same pin low when the "HAL_SPI_TxCpltCallback" callback function is called. Not sure why the half-transfer complete callback function is getting called at the beginning of the transfer. Maybe that is a hint as to what is wrong here.
I am also successfully using UART1 + DMA where I am consistently able to send messages with many bytes.
Yes, I have "MX_DMA_Init();" before all other peripherals that use DMA. By the way, when does ST plan to fix this bug, it has been there for at least a couple of years.
/* Initialize all configured peripherals */
MX_DMA_Init();
MX_GPIO_Init();
MX_I2C1_Init();
MX_OCTOSPI1_Init();
MX_OCTOSPI2_Init();
MX_SPI1_Init();
MX_SPI2_Init();
MX_SPI3_Init();
MX_ADC1_Init();
MX_I2C2_Init();
MX_IWDG_Init();
MX_USART1_UART_Init();
MX_DAC1_Init();
Here is how I have SPI3 configured. Note that I have adjusted many settings with no avail.
static void MX_SPI3_Init(void)
{
/* USER CODE BEGIN SPI3_Init 0 */
/* USER CODE END SPI3_Init 0 */
/* USER CODE BEGIN SPI3_Init 1 */
/* USER CODE END SPI3_Init 1 */
/* SPI3 parameter configuration*/
hspi3.Instance = SPI3;
hspi3.Init.Mode = SPI_MODE_MASTER;
hspi3.Init.Direction = SPI_DIRECTION_2LINES;
hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi3.Init.NSS = SPI_NSS_HARD_OUTPUT;
hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi3.Init.CRCPolynomial = 7;
hspi3.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi3) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI3_Init 2 */
/* USER CODE END SPI3_Init 2 */
}
Is this a bug anyone else has seen before?
Thanks!
