title: How to configure SWD pins using registers in STM32?
body: <p><strong>Info:</strong> I create Blink using registers in STM32. This works, except that after the firmware the SWD connector stops working for me. The reason most likely is that the SWD is on the same port along with the LED. When configuring the port and the LED pin, I probably reset the SWD settings.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>#include "main.h"
  
  void SystemClock_Config(void);
  
  int main(void)
  {
    HAL_Init();
    SystemClock_Config();
  
    __HAL_RCC_GPIOA_CLK_ENABLE();
    // Set PA8 to OUTPUT mode
    GPIOA-&gt;MODER = 0x00010000;
    // Set PUSH-PULL mode
    GPIOA-&gt;OTYPER = 0x00000000;
    // Set pin speed
    GPIOA-&gt;OSPEEDR = 0x64010000;
    // Set not pull
    GPIOA-&gt;PUPDR = 0x64000000;
    // Set pin bit
    GPIOA-&gt;BSRR = 0x00000100;
  
    static int pin_state = 0;
  
    while (1)
    {
        // LED blink
        if(pin_state == 0) {
          // Bit set
          GPIOA-&gt;BSRR = 0x00000100;
          pin_state = 1;
        } else {
          // Bit clear
          GPIOA-&gt;BSRR = 0x01000000;
          pin_state = 0;
        }
  
        HAL_Delay(3000);
  
    }
  }
  
  void SystemClock_Config(void)
  {
    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  
    /** Initializes the CPU, AHB and APB busses clocks 
    */
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
    RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
    if (HAL_RCC_OscConfig(&amp;RCC_OscInitStruct) != HAL_OK)
    {
      Error_Handler();
    }
    /** Initializes the CPU, AHB and APB busses clocks 
    */
    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                                |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  
    if (HAL_RCC_ClockConfig(&amp;RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
    {
      Error_Handler();
    }
  }
  
  void Error_Handler(void) {}
  
  #ifdef  USE_FULL_ASSERT
  void assert_failed(char *file, uint32_t line) {}
  #endif
  </code></pre>
  
  <p>In the <a href="https://www.st.com/resource/en/reference_manual/dm00093941-stm32f334xx-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf" rel="nofollow noreferrer">STM32F334K8Tx</a> datasheet, I did not find much information about setting registers for SWD contacts (which mode, setting the clock, pull-up, and more).</p>
  
  <p><strong>Question:</strong> how can this be done? Or where can I find information?</p>