cancel
Showing results for 
Search instead for 
Did you mean: 

DMA SPI transfer recovery time

fma23
Associate II

I am making this call:  if(HAL_SPI_Receive_DMA(&hspi3, &aRecvBuffer[0],3)!= HAL_OK)

inside an external GPIO interrupt handler that gets called every 20 us. It is used to read data from an external ADC. I noticed that this dma transfer works well only for transfers at 40 us periods or more. Otheriwse, the DMA shows it is in a RX_Busy state after every other sucessful transfer. for example out of 100 calls, I get only 50 calls with successful transfer. when the transfer fails, I see that the DMA is in an RX_Busy state.

Is this a limitation of STM32F7 or a bug in my code?

2 REPLIES 2
S.Ma
Principal

Knowing the core frequency, SPI SCK frequency, SPI configuration would give it a chance to community participant to contribute. Fog questions rarely gets sniper right answers.

fma23
Associate II

This is my clock and spi configuration:

/**

* @brief System Clock Configuration

* @retval None

*/

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct = {0};

RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

/** Supply configuration update enable

*/

HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);

/** Configure the main internal regulator output voltage

*/

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}

/** Initializes the RCC Oscillators according to the specified parameters

* in the RCC_OscInitTypeDef structure.

*/

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;

RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

RCC_OscInitStruct.PLL.PLLM = 4;

RCC_OscInitStruct.PLL.PLLN = 9;

RCC_OscInitStruct.PLL.PLLP = 2;

RCC_OscInitStruct.PLL.PLLQ = 2;

RCC_OscInitStruct.PLL.PLLR = 2;

RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;

RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOMEDIUM;

RCC_OscInitStruct.PLL.PLLFRACN = 3072;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

{

Error_Handler();

}

/** Initializes the CPU, AHB and APB buses clocks

*/

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2

|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;

RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;

RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;

RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;

RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)

{

Error_Handler();

}

}

/**

* @brief SPI3 Initialization Function

* @param None

* @retval None

*/

static void MX_SPI3_Init(void)

{

/* USER CODE END SPI3_Init 2 */

/*##-1- Configure the SPI peripheral #######################################*/

/* Set the SPI parameters */

hspi3.Instance = SPI3;

hspi3.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE; // Recommended setting to avoid glitches

hspi3.Init.Mode = SPI_MODE_MASTER;

hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;

hspi3.Init.Direction = SPI_DIRECTION_2LINES;

hspi3.Init.CLKPhase = SPI_PHASE_2EDGE;

hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;

hspi3.Init.DataSize = SPI_DATASIZE_8BIT;

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_8BIT;

hspi3.Init.NSS = SPI_NSS_HARD_OUTPUT; //SPI_NSS_SOFT;

hspi3.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;

hspi3.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE; /* Recommended setting to avoid glitches */

if (HAL_SPI_Init(&hspi3) != HAL_OK)

{

Error_Handler();

}

}