<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[STM32 HAL 点亮 LED:最小可运行工程(示例帖)]]></title><description><![CDATA[<p dir="auto">这是论坛的第一篇示例教程,演示代码高亮与发帖模板是否正常工作。</p>
<h2>目标</h2>
<p dir="auto">用 STM32 HAL 库点亮一块 LED,理解 GPIO 输出的基本流程。</p>
<h2>代码</h2>
<pre><code class="language-c">#include "main.h"

int main(void)
{
	HAL_Init();
	__HAL_RCC_GPIOA_CLK_ENABLE();  // 先开 GPIOA 时钟

	GPIO_InitTypeDef gpio = {0};
	gpio.Pin = GPIO_PIN_5;
	gpio.Mode = GPIO_MODE_OUTPUT_PP;
	gpio.Pull = GPIO_NOPULL;
	gpio.Speed = GPIO_SPEED_FREQ_LOW;
	HAL_GPIO_Init(GPIOA, &amp;gpio);

	while (1) {
		HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
		HAL_Delay(500);
	}
}
</code></pre>
<h2>要点</h2>
<ol>
<li>操作任何外设前先使能对应总线时钟,这是新手最常踩的坑。</li>
<li><code>HAL_Delay</code> 依赖 SysTick,确保 <code>HAL_Init()</code> 已调用。</li>
<li>LED 不亮时先用万用表量引脚电平,二分法定位是软件还是硬件问题。</li>
</ol>
]]></description><link>https://www.potatochip.dev/topic/15/stm32-hal-点亮-led-最小可运行工程-示例帖</link><generator>RSS for Node</generator><lastBuildDate>Fri, 09 Oct 2026 20:40:56 GMT</lastBuildDate><atom:link href="https://www.potatochip.dev/topic/15.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 01 Oct 2026 14:46:54 GMT</pubDate><ttl>60</ttl></channel></rss>