Info: 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.
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->MODER = 0x00010000;
// Set PUSH-PULL mode
GPIOA->OTYPER = 0x00000000;
// Set pin speed
GPIOA->OSPEEDR = 0x64010000;
// Set not pull
GPIOA->PUPDR = 0x64000000;
// Set pin bit
GPIOA->BSRR = 0x00000100;
static int pin_state = 0;
while (1)
{
// LED blink
if(pin_state == 0) {
// Bit set
GPIOA->BSRR = 0x00000100;
pin_state = 1;
} else {
// Bit clear
GPIOA->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(&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(&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
In the STM32F334K8Tx datasheet, I did not find much information about setting registers for SWD contacts (which mode, setting the clock, pull-up, and more).
Question: how can this be done? Or where can I find information?