cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5 Enabling CLK for GPIO Port resets MODE Register to 0.

LBöhm.1
Associate III

Hello,

I have a problem with STM32U5 with TrustZone enabled. I use standard startupfile and have a simple init Routine:

int main(void)
{
  /* SAU/IDAU, FPU and interrupts secure/non-secure allocation setup done */
/* in SystemInit() based on partition_stm32u575xx.h file's definitions. */
  /* 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 */
	__HAL_DBGMCU_FREEZE_IWDG();
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* Configure the System Power */
  SystemPower_Config();
  /* GTZC initialisation */
  MX_GTZC_S_Init();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_TIM2_Init();
  MX_LPUART1_UART_Init();
  MX_SPI1_Init();
  MX_GPDMA1_Init();
  MX_IWDG_Init();
  MX_SPI3_Init();
  /* USER CODE BEGIN 2 */
  HAL_TIM_Base_Start_IT(&htim2);
  /* USER CODE END 2 */
 
  /*************** Setup and jump to non-secure *******************************/
 
  NonSecure_Init();
 
  /* Non-secure software does not return, this code is not executed */
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

GPIO_INIT:

static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
 
  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOG_CLK_ENABLE();
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOC, CONT1_OUT_Pin|CONT2_OUT_Pin|SPI3_NSS_Pin, GPIO_PIN_RESET);
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(SPI1_NSS_GPIO_Port, SPI1_NSS_Pin, GPIO_PIN_RESET);
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_SET);
 
  /*Configure GPIO pins : CONT1_OUT_Pin CONT2_OUT_Pin SPI3_NSS_Pin */
  GPIO_InitStruct.Pin = CONT1_OUT_Pin|CONT2_OUT_Pin|SPI3_NSS_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
  /*Configure GPIO pins : CONT1_STAT_Pin INA229_ALERT_Pin */
  GPIO_InitStruct.Pin = CONT1_STAT_Pin|INA229_ALERT_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
  /*Configure GPIO pin : CONT2_STAT_Pin */
  GPIO_InitStruct.Pin = CONT2_STAT_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(CONT2_STAT_GPIO_Port, &GPIO_InitStruct);
 
  /*Configure GPIO pin : SPI1_NSS_Pin */
  GPIO_InitStruct.Pin = SPI1_NSS_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(SPI1_NSS_GPIO_Port, &GPIO_InitStruct);
 
  /*Configure GPIO pin : LED_RED_Pin */
  GPIO_InitStruct.Pin = LED_RED_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(LED_RED_GPIO_Port, &GPIO_InitStruct);
 
  /*IO attributes management functions */
  HAL_GPIO_ConfigPinAttributes(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_NSEC);
 
  /*IO attributes management functions */
  HAL_GPIO_ConfigPinAttributes(GPIOD, GPIO_PIN_0|GPIO_PIN_1, GPIO_PIN_NSEC);
 
  /*IO attributes management functions */
  HAL_GPIO_ConfigPinAttributes(LED_BLUE_GPIO_Port, LED_BLUE_Pin, GPIO_PIN_NSEC);
 
}

In debugging I can see the MODER register is 0 after _HAL_RCC_GPIOG_CLK_ENABLE() and stays so after all. LED_RED does not turn on.

We use Keil MDKv5 Toolchain.

Can anyone help me, what I miss here?

Thanks in advance.

5 REPLIES 5
TDK
Guru

Should work. LED_RED_GPIO_Port is GPIOG? Can you modify any other registers such as ODR within GPIOG?

If you feel a post has answered your question, please click "Accept as Solution".
LBöhm.1
Associate III

 LED_RED_GPIO_Port is GPIOG, yes. When I try to set the ODR in debug mode, it stays 0 as if someone is overwriting me.

TDK
Guru

Reset value of GPIOG->MODER is 0xFFFFFFFF. Perhaps the clock isn't really enabled. Is GPIOGEN set in RCC_AHB2ENR1?

Might also check the GPIOG address definition in the SVD file, or whatever you're using to "read" it, and compare that against what the reference manual says.

Can't think of anything else it would be. Even if it was held in reset, wouldn't explain things. Could be some STM32U5 magic I'm not familiar with.

If you feel a post has answered your question, please click "Accept as Solution".

GPIOGEN is set. I checked that.