Code Implementation
#include "stm32f1xx_hal.h"
int main(void) {
HAL_Init(); // Initialize the HAL library
SystemClock_Config(); // Configure the system clock
__HAL_RCC_GPIOC_CLK_ENABLE(); // Enable the GPIOC clock
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_13; // Select the PC13 pin
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // Configure as push-pull output
GPIO_InitStruct.Pull = GPIO_NOPULL; // No pull-up/down resistor
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; // Low-speed mode
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); // Initialize the GPIO
while (1) {
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); // Toggle the state of PC13 pin
HAL_Delay(500); // Delay for 500ms
}
}
The following is a simple STM32 program example that uses the HAL library to light up an LED.
Snippet Description
- In actual development, adjust the pin and clock configurations according to your specific STM32 model.
- After compiling the program, burn it into the STM32 chip using a debugging tool such as ST-Link or J-Link. If everything works properly, you will see the LED blink at 500ms intervals.
Recommended Snippets
Hello World
C Language Hello World Example, C is an efficient systems-level programming language and the foundation of many modern languages
JavaScript Debounce Async Function
In JavaScript, the debounce function is a core tool for optimizing high-frequency and time-consuming operations. Its core logic lies in delaying function execution while canceling repeated delays. This ensures that when a function is triggered multiple times within a short period, it will only execute after waiting for a specified delay following the last trigger. This avoids performance overhead caused by unnecessary invocations. The working principle can be analogized to "an elevator closing its doors": After an elevator opens, it waits for a fixed period (e.g., 2 seconds) by default before closing. If a new passenger enters during this waiting period (corresponding to a new trigger of the function), the original waiting timer is canceled and the countdown restarts. Only when no new triggers occur after the countdown ends will the "door-closing" action (corresponding to the function execution) take place.
Hello World
Perl Hello World Example, Perl is a powerful text processing language, known for its flexibility and rich regular expression support