[SOLVED] SPI DMA doesnt transmit anything, is my configuration wrong?
Im having problems with DMA SPI transmit. Im using stm32f429zi mcu and would like to implement SPI DMA with MOSI only, I dont need MISO. SPI and DMA configuration was generated using CubeMX. Using HAL_SPI_Transmit function SPI works great. But HAL_SPI_Transmit_DMA does not send anything and gets stuck in while loop where it checks HAL_SPI_STATE_READY flag. HAL_SPI_Transmit_DMA returns HAL_OK. I am thinking that I have missed something in configuration but I havent been able to figure it out yet. If I create data to receive buffer and use HAL_SPI_TransmitReceive_DMA it also does not send anything but it doesnt get stuck in loop as spi status is ready.
Im monitoring MOSI and SCK pin with logic analyzer.
Here is my code
PeripheralInit.c:
void MX_SPI5_Init(void)
{
/* SPI5 parameter configuration*/
hspi5.Instance = SPI5;
hspi5.Init.Mode = SPI_MODE_MASTER;
hspi5.Init.Direction = SPI_DIRECTION_2LINES;
hspi5.Init.DataSize = SPI_DATASIZE_8BIT;
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi5.Init.NSS = SPI_NSS_SOFT;
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
hspi5.Init.FirstBit = SPI_FIRSTBIT_LSB;
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi5.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi5) != HAL_OK)
{
Error_Handler();
}
}
void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA2_CLK_ENABLE();
/* DMA interrupt init */
/* DMA2_Stream4_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Stream4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream4_IRQn);
}stm32f4xx_hal_msp.c:
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hspi->Instance==SPI5)
{
/* Peripheral clock enable */
__HAL_RCC_SPI5_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
/**SPI5 GPIO Configuration
PF7 ------> SPI5_SCK
PF9 ------> SPI5_MOSI
*/
GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI5;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
/* SPI5 DMA Init */
/* SPI5_TX Init */
hdma_spi5_tx.Instance = DMA2_Stream4;
hdma_spi5_tx.Init.Channel = DMA_CHANNEL_2;
hdma_spi5_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_spi5_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_spi5_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_spi5_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_spi5_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_spi5_tx.Init.Mode = DMA_NORMAL;
hdma_spi5_tx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
hdma_spi5_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
if (HAL_DMA_Init(&hdma_spi5_tx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(hspi,hdmatx,hdma_spi5_tx);
}
}main.cpp:
uint8_t data_to_send[]={
0xFF, 0xEE, 0xEE, 0xEE, 0xEE
};
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SPI5_Init();
MX_DMA_Init();
HAL_SPI_Transmit_DMA(&hspi5,data_to_send, sizeof(data_to_send));
while(HAL_SPI_GetState(&hspi5) != HAL_SPI_STATE_READY);