Skip to main content
DKope.1
Associate
February 11, 2020
Question

GAP in SPI transfere on STM32WB55RGVx

  • February 11, 2020
  • 4 replies
  • 2443 views

Iam trying to setup SPI1 on STM32WB nucluo (STM32WB55RGVx), I made a configuration trough the STM cube and do some adjustments, the problem is that in every sequence iam trying to transmit with HAL_SPI_Transmit is a gap for couple of microseconds. Then the sequence follows normally.

0690X00000D9WUIQA3.png

Firstly i thought, that the problem is caused by RTOS since i use the mbed, but when the issue was not resolved even if i configured transmit over DMA. Is there any chance that this is the problem of SPI or clock configuration?

SPI Configuration:

static void MX_SPI1_Init(void)
{
 
 /* USER CODE BEGIN SPI1_Init 0 */
 
 /* USER CODE END SPI1_Init 0 */
 
 /* USER CODE BEGIN SPI1_Init 1 */
 
 /* USER CODE END SPI1_Init 1 */
 /* SPI1 parameter configuration*/
 hspi1.Instance = SPI1;
 hspi1.Init.Mode = SPI_MODE_MASTER;
 hspi1.Init.Direction = SPI_DIRECTION_1LINE;
 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
 hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
 hspi1.Init.NSS = SPI_NSS_SOFT;
 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
 hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
 hspi1.Init.CRCPolynomial = 7;
 hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
 //hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
 if (HAL_SPI_Init(&hspi1) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN SPI1_Init 2 */
 
 /* USER CODE END SPI1_Init 2 */
 
}

Clock configuration:

void SystemClock_Config(void)
{
 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
 
 /** Configure the main internal regulator output voltage
 */
 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
 /** Initializes the CPU, AHB and APB busses clocks
 */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_MSI;
 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 RCC_OscInitStruct.MSIState = RCC_MSI_ON;
 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_10;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler();
 }
 /** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers
 */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK4|RCC_CLOCKTYPE_HCLK2
 |RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 RCC_ClkInitStruct.AHBCLK2Divider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.AHBCLK4Divider = RCC_SYSCLK_DIV1;
 
 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
 {
 Error_Handler();
 }
 /** Initializes the peripherals clocks
 */
 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SMPS;
 PeriphClkInitStruct.SmpsClockSelection = RCC_SMPSCLKSOURCE_HSI;
 PeriphClkInitStruct.SmpsDivSelection = RCC_SMPSCLKDIV_RANGE1;
 
 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN Smps */
 
 /* USER CODE END Smps */
}

Transmit command

int rc;
rc = HAL_SPI_Transmit(&hspi1, _collor_buffer, NUMBER_OF_LEDS*24,10);
printf("Return value %d \n",rc);

This topic has been closed for replies.

4 replies

waclawek.jan
Super User
February 11, 2020

Do you see the same gap if you observe SCK?

JW

DKope.1
DKope.1Author
Associate
February 13, 2020

yes, there is the same gap as on MOSI pin

0690X00000DALiVQAX.png

DK

berendi
Principal
February 12, 2020

> trying to transmit with HAL_SPI_Transmit is a gap for couple of microseconds

Yes, there is. Don't use it if that matters.

https://community.st.com/s/question/0D50X0000BxyRtJSQU/spi-too-slow

waclawek.jan
Super User
February 13, 2020

Is this with using DMA?

JW

DKope.1
DKope.1Author
Associate
February 13, 2020

I have tried Transmit with DMA and also just simple Transmit, both work the same. Also i have tried to disable all interrupts during transmit, but it does not help.

waclawek.jan
Super User
February 14, 2020

- start a new project with only the SPI Tx using DMA, and observe

- try a different SPI channel, again with DMA

JW