cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743 cannot use HAL_SPI_Transmit_DMA with Nor Flash

ryawi
Associate

I'm working on STM32H743 applied SPI DMA with MT25 QL128ABA1(NOR Flash) and initial mode to master mode.

My problem is I cannot receive (HAL_SPI_Receive_DMA) return data when I use HAL_SPI_Transmit_DMA by run code through but I can receive return data when I apply breakpoints before HAL_SPI_IRQHandler. I probe to confirm return data already.

The Nor flash must transmit command first and then receive return data later.

Note: I try to transmit data by using HAL_SPI_TransmitReceive_DMA then receive data by HAL_SPI_Receive_DMA it work!! but I want to know why I cannot use HAL_SPI_Transmit_DMA .

0690X00000AsLVSQA3.png

This is my configuration

	/* Initialize the SPI module */
	SpiHandle.Instance               = SPI2;
	SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
	SpiHandle.Init.CLKPolarity       = SPI_POLARITY_LOW;
	SpiHandle.Init.CLKPhase          = SPI_PHASE_1EDGE;
	SpiHandle.Init.Direction         = SPI_DIRECTION_2LINES;
	SpiHandle.Init.CRCCalculation    = SPI_CRCCALCULATION_DISABLED;
	SpiHandle.Init.CRCPolynomial     = 7;
	SpiHandle.Init.DataSize          = SPI_DATASIZE_8BIT;
	SpiHandle.Init.FirstBit          = SPI_FIRSTBIT_MSB;
	SpiHandle.Init.NSS               = SPI_NSS_SOFT;
	SpiHandle.Init.TIMode            = SPI_TIMODE_DISABLED;
	SpiHandle.Init.Mode              = SPI_MODE_MASTER;
        SpiHandle.Init.CRCLength         = SPI_CRC_LENGTH_8BIT;
        SpiHandle.Init.NSSPMode          = SPI_NSS_PULSE_ENABLE;
        SpiHandle.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE; 
	HAL_SPI_Init(&SpiHandle);
 
 
        /* Configure the DMA streams */
	/* Configure the DMA handler for Transmission process */
	DmaTxHandle.Instance                 = DMA2_Stream4;
	DmaTxHandle.Init.FIFOMode            = DMA_FIFOMODE_DISABLE;
	DmaTxHandle.Init.FIFOThreshold       = DMA_FIFO_THRESHOLD_FULL;
	DmaTxHandle.Init.MemBurst            = DMA_MBURST_SINGLE;
	DmaTxHandle.Init.PeriphBurst         = DMA_PBURST_SINGLE;
        DmaTxHandle.Init.Request             = DMA_REQUEST_SPI2_TX;
	DmaTxHandle.Init.Direction           = DMA_MEMORY_TO_PERIPH;
	DmaTxHandle.Init.PeriphInc           = DMA_PINC_DISABLE;
	DmaTxHandle.Init.MemInc              = DMA_MINC_ENABLE;
	DmaTxHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
	DmaTxHandle.Init.MemDataAlignment    = DMA_MDATAALIGN_BYTE;
	DmaTxHandle.Init.Mode                = DMA_NORMAL;
	DmaTxHandle.Init.Priority            = DMA_PRIORITY_LOW;
 
	HAL_DMA_Init(&DmaTxHandle);
 
	/* Associate the initialized DMA handle to the the SPI handle */
	__HAL_LINKDMA(&SpiHandle, hdmatx, DmaTxHandle);
 
	/* Configure the DMA handler for Transmission process */
	DmaRxHandle.Instance                 = DMA2_Stream3;
	DmaRxHandle.Init.FIFOMode            = DMA_FIFOMODE_DISABLE;
	DmaRxHandle.Init.FIFOThreshold       = DMA_FIFO_THRESHOLD_FULL;
	DmaRxHandle.Init.MemBurst            = DMA_MBURST_SINGLE;
	DmaRxHandle.Init.PeriphBurst         = DMA_PBURST_SINGLE;
        DmaRxHandle.Init.Request             = DMA_REQUEST_SPI2_RX;
	DmaRxHandle.Init.Direction           = DMA_PERIPH_TO_MEMORY;
	DmaRxHandle.Init.PeriphInc           = DMA_PINC_DISABLE;
	DmaRxHandle.Init.MemInc              = DMA_MINC_ENABLE;
	DmaRxHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
	DmaRxHandle.Init.MemDataAlignment    = DMA_MDATAALIGN_BYTE;
	DmaRxHandle.Init.Mode                = DMA_NORMAL;
	DmaRxHandle.Init.Priority            = DMA_PRIORITY_HIGH;
 
	HAL_DMA_Init(&DmaRxHandle);
 
	/* Associate the initialized DMA handle to the the SPI handle */
	__HAL_LINKDMA(&SpiHandle, hdmarx, DmaRxHandle);
 
        HAL_NVIC_SetPriority(SPI2_IRQn, 8, 0);
        HAL_NVIC_EnableIRQ(SPI2_IRQn);
	/* Configure the NVIC for DMA */
	/* NVIC configuration for DMA transfer complete interrupt (SPI2_TX) */
	HAL_NVIC_SetPriority(DMA2_Stream4_IRQn, 8, 0);
	HAL_NVIC_EnableIRQ(DMA2_Stream4_IRQn);
	/* NVIC configuration for DMA transfer complete interrupt (SPI2_RX) */
	HAL_NVIC_SetPriority(DMA2_Stream3_IRQn, 8, 0);
	HAL_NVIC_EnableIRQ(DMA2_Stream3_IRQn);

0 REPLIES 0