cancel
Showing results for 
Search instead for 
Did you mean: 

I cannot use SW pins as GPIO for some reason

Javier1
Principal

I swear i was able to do this in the past but then ...... then i updated from 6.3.0 to cubeMX 6.6.1.

Maybe thats the reason, maybe not .

 0693W00000WJQkaQAH.pngIm using a stm32f105RBT6

When i flash the chip and remove the stlink both PA13 and PA14 are stuck into some idle 1,3V floating state instead of toggle each second like PA10

I am not sure where should i look to be sure pin SW functions are not on.

Setting up pins as GPIOs in cubeMX

0693W00000WJQhvQAH.png 

Code inside main, simple GPIO toggle

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();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_ADC1_Init();
  MX_CAN1_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_TIM4_Init();
  MX_TIM7_Init();
  /* USER CODE BEGIN 2 */
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  HAL_Delay(1000);
	  HAL_GPIO_TogglePin(uC_OUT_01_GPIO_Port, uC_OUT_01_Pin);
	  HAL_GPIO_TogglePin(uC_OUT_02_GPIO_Port, uC_OUT_02_Pin);
	  HAL_GPIO_TogglePin(uC_OUT_03_GPIO_Port, uC_OUT_03_Pin);//Only thisone works
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

I am flashing the release version wchih is not supposed to be using SW debugging pins at all..... i ran out of ideas

we dont need to firmware by ourselves, lets talk
1 ACCEPTED SOLUTION

Accepted Solutions
Herve PIERROT
ST Employee

Hello @Javier Muñoz​ ,

Maybe this could give you some hints if you are in this case :

Reuse-swd-pins-on-stm32f0

View solution in original post

5 REPLIES 5
Javier1
Principal

0693W00000WJQjrQAH.pngCUBEMX generated GPIO init looks okay to me

/** Configure pins as
        * Analog
        * Input
        * Output
        * EVENT_OUT
        * EXTI
*/
void MX_GPIO_Init(void)
{
 
  GPIO_InitTypeDef GPIO_InitStruct = {0};
 
  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOC, uC_OUT_19_Pin|uC_AUX_19_Pin|uC_OUT_18_Pin|uC_AUX_18_Pin
                          |uC_OUT_17_Pin|uC_AUX_17_Pin|uC_OUT_16_Pin|uC_AUX_12_Pin
                          |uC_OUT_11_Pin|uC_OUT_06_Pin|uC_AUX_06_Pin|uC_OUT_05_Pin
                          |uC_AUX_05_Pin, GPIO_PIN_RESET);
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, uC_AUX_16_Pin|uC_OUT_15_Pin|uC_AUX_15_Pin|uC_OUT_14_Pin
                          |uC_AUX_14_Pin|uC_OUT_13_Pin|uC_AUX_13_Pin|uC_OUT_12_Pin
                          |uC_OUT_04_Pin|uC_AUX_04_Pin|uC_OUT_03_Pin|uC_AUX_03_Pin
                          |uC_LED_POWER_Pin|uC_OUT_02_Pin|uC_OUT_01_Pin, GPIO_PIN_RESET);
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, uC_AUX_11_Pin|uC_OUT_10_Pin|uC_AUX_10_Pin|uC_OUT_09_Pin
                          |uC_OUT_08_Pin|uC_AUX_08_Pin|uC_OUT_07_Pin|uC_AUX_07_Pin
                          |uC_OUT_20_Pin|uC_AUX_20_Pin, GPIO_PIN_RESET);
 
  /*Configure GPIO pins : PCPin PCPin PCPin PCPin
                           PCPin PCPin PCPin PCPin
                           PCPin PCPin PCPin PCPin
                           PCPin */
  GPIO_InitStruct.Pin = uC_OUT_19_Pin|uC_AUX_19_Pin|uC_OUT_18_Pin|uC_AUX_18_Pin
                          |uC_OUT_17_Pin|uC_AUX_17_Pin|uC_OUT_16_Pin|uC_AUX_12_Pin
                          |uC_OUT_11_Pin|uC_OUT_06_Pin|uC_AUX_06_Pin|uC_OUT_05_Pin
                          |uC_AUX_05_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
  /*Configure GPIO pins : PAPin PAPin PAPin PAPin
                           PAPin PAPin PAPin PAPin
                           PAPin PAPin PAPin PAPin
                           PAPin PAPin */
  GPIO_InitStruct.Pin = uC_AUX_16_Pin|uC_OUT_15_Pin|uC_AUX_15_Pin|uC_OUT_14_Pin
                          |uC_AUX_14_Pin|uC_OUT_13_Pin|uC_AUX_13_Pin|uC_OUT_12_Pin
                          |uC_OUT_04_Pin|uC_AUX_04_Pin|uC_OUT_03_Pin|uC_AUX_03_Pin
                          |uC_OUT_02_Pin|uC_OUT_01_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
  /*Configure GPIO pins : PBPin PBPin PBPin PBPin
                           PBPin PBPin PBPin PBPin
                           PBPin PBPin */
  GPIO_InitStruct.Pin = uC_AUX_11_Pin|uC_OUT_10_Pin|uC_AUX_10_Pin|uC_OUT_09_Pin
                          |uC_OUT_08_Pin|uC_AUX_08_Pin|uC_OUT_07_Pin|uC_AUX_07_Pin
                          |uC_OUT_20_Pin|uC_AUX_20_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = uC_LED_POWER_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(uC_LED_POWER_GPIO_Port, &GPIO_InitStruct);
 
  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = uC_IN04_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  HAL_GPIO_Init(uC_IN04_GPIO_Port, &GPIO_InitStruct);
 
  /*Configure GPIO pins : PCPin PCPin PCPin */
  GPIO_InitStruct.Pin = uC_IN08_Pin|uC_IN03_Pin|uC_IN07_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = uC_IN02_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  HAL_GPIO_Init(uC_IN02_GPIO_Port, &GPIO_InitStruct);
 
  /*Configure GPIO pins : PBPin PBPin PBPin */
  GPIO_InitStruct.Pin = uC_IN06_Pin|uC_IN01_Pin|uC_IN05_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
}

we dont need to firmware by ourselves, lets talk
Herve PIERROT
ST Employee

Hello @Javier Muñoz​ ,

Maybe this could give you some hints if you are in this case :

Reuse-swd-pins-on-stm32f0

Thanks @Herve PIERROT​ , ill give it a look to AN4989 and get back to you with my findings.

What troubles me is... i never had this problem before untill now, and im using both SW pins as alternative functions in the same hardware with other projects.

Ill downgrade to cubeMX 6.3.0 also

we dont need to firmware by ourselves, lets talk

@Herve PIERROT​ , i already fixed it , there is nothing wrong with cubeMX nor the firmware package.

I just deleted the project, generated everything again with cubeMX 6.6.1, copied my libraries and now its fine.

Something went wrong when i updated CUBEMX and regenerated the progect, i believe the issue was in the files autogenerated by cubeMX at that point.... but i dont have the time to figure out what, anyway everything is working now.

we dont need to firmware by ourselves, lets talk
Herve PIERROT
ST Employee

perfect, thanks for the feedback, most important is that it works now :thumbs_up: