cancel
Showing results for 
Search instead for 
Did you mean: 

Get external I2C3 working on Sensor Tile.Box Pro

Mantis
Visitor

I have a Sensor Tile.Box pro and I want to communicate using I2C to an external peripheral using the PG7 and PG8 pins, which are the I2C3 SCL and SDA pins. However I am unable to get as much as basic GPIO working on those two pins, let alone I2C.

I have created a small standalone project for the ST32U585 chip, and using that project I can get I2C and GPIO working without any issues. But when I copy over the working code for initializing the clock and GPIO pins from the standalone project over to the SDDataLogFileX project (which I got from here, and uses the Azure RTOS) the GPIO pins no longer work. Below is the relevant code I'm using.

 

int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

#if (FX_STM32_SD_INIT == 0)
  BSP_SD_Init(FX_STM32_SD_INSTANCE);
#endif
  /* USER CODE END SysInit */

  /* Initialize ICache */
  MX_ICACHE_Init();
  /* USER CODE BEGIN 2 */
  MX_GPIO_Init();
  for (int i = 0; i < 5; i++) {
    HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_7);
    HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_8);
    HAL_Delay(10);
  }
  /* USER CODE BEGIN SysInit */
  BSP_LED_Init(LED_GREEN);
  BSP_LED_Init(LED_RED);
  /* RED is activated by default */
  BSP_LED_Off(LED_RED);
  
  /* Enable Button in Interrupt mode */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
  
  /* Init UART for printf */
  BSP_COM_Init(COM1);
  
  /* Print Banner */
  PrintInfo();
  
  /* Init Mems Sensors */
  InitMemsSensors();
  
  /* USER CODE END 2 */

  MX_ThreadX_Init();
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE4) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
  RCC_OscInitStruct.MSIState = RCC_MSI_ON;
  RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_4;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  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_PCLK3;
  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.APB3CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
}

static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOG_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOG, GPIO_PIN_7|GPIO_PIN_8, GPIO_PIN_RESET);

  /*Configure GPIO pins : PG7 PG8 */
  GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}

 

I have tried multiple different system clock configurations, including the default for the github project (not shown above, but easy to find), the one you see above, and an attempt to mix them to configure MSI along side everything else the sensor tile box needs. Regardless of how I configure it I can never control the GPIO pins. When stepping through with a debugger I observe the GPIOG registers get set to the correct values, I see the GPIOGEN bit in AHB2ENR1 get set, I see the ODR bits toggle, but I don't detect any change in output.

How do I need to configure these pins to get GPIO, and eventually I2C, working on the Sensor Tile.Box Pro along side everything else that's in there?

1 REPLY 1
Joe WILLIAMS
ST Employee

Hi Mantis

This post has been escalated to the ST Online Support Team for additional assistance.  We'll contact you directly.

Regards

Joe

STMicro Support