{"id":8073,"date":"2025-06-05T17:28:46","date_gmt":"2025-06-05T09:28:46","guid":{"rendered":"https:\/\/www.wangonc.com\/?p=8073"},"modified":"2025-06-05T17:28:46","modified_gmt":"2025-06-05T09:28:46","slug":"configuring-stm32-standard-library-using-platformio","status":"publish","type":"post","link":"https:\/\/www.wangonc.com\/index.php\/2025\/06\/05\/configuring-stm32-standard-library-using-platformio\/","title":{"rendered":"\u4f7f\u7528PlatformIO\u914d\u7f6eSTM32\u6807\u51c6\u5e93"},"content":{"rendered":"<p>\u521d\u5b66STM32\u5d4c\u5165\u5f0f\u5f00\u53d1\uff0c\u65e8\u5728\u5b66\u4e60\u5d4c\u5165\u5f0f\u5f00\u53d1\u6d41\u7a0b\u548c\u539f\u7406\uff0c\u4ee5\u4fbf\u66f4\u5feb\u7684\u4e0a\u624b\u90a3\u4e9b\u4fbf\u5b9c\u7684\u56fd\u4ea7\u7684\u6ca1\u90a3\u4e48\u591a\u8d44\u6599\u7684IC\u3002<\/p>\n<p>\u9009\u7528\u7684\u662fSTM32F103C8T6\uff08\u6682\u65f6\u7528wokwi\u5e73\u53f0\uff09\uff0c\u8fd9\u4e2aIC\u662f\u652f\u6301SPL\u7684\uff0c\u4f46\u662fPIO\u5e73\u53f0\u5e76\u4e0d\u652f\u6301\u76f4\u63a5\u914d\u7f6e\uff0c\u4e0d\u77e5\u9053\u4e3a\u5565\uff0c\u6240\u4ee5\u8fd9\u91cc\u9700\u8981\u624b\u52a8\u914d\u7f6eSDK\u3002<\/p>\n<p>\u5728<a href=\"https:\/\/www.st.com.cn\/zh\/microcontrollers-microprocessors\/stm32f103c8.html#tools-software\" title=\"STM32F103C8\">STM32F103C8<\/a>\u53ef\u4ee5\u627e\u5230\u8fd9\u4e2aMCU\u7684\u6240\u6709\u8d44\u6599\uff0c\u9700\u8981\u627e\u5230\u5176SDK\u5e76\u4e0b\u8f7d\u4e0b\u6765\u3002\u4e1c\u897f\u592a\u591a\u4e86\u8fd8\u662f\u6709\u70b9\u96be\u627e<\/p>\n<p>\u4e0b\u62c9\u627e\u5230<code>MCU and MPU embedded softwar<\/code>\u90e8\u5206,\u5176\u4e2d<code>STM32CubeF1<\/code>\u5c31\u662fHAL\u4e86\uff0c\u8fd9\u91cc\u4e3a\u4e86\u66f4\u719f\u6089\u5355\u7247\u673a\u7684\u5e95\u5c42\u539f\u7406\uff0cHAL\u5c01\u88c5\u7684\u592a\u539a\u4e86\uff0c\u6240\u4ee5\u4f7f\u7528SPL\uff0c\u4e0d\u7528HAL\uff08CMSIS\u597d\u50cf\u53c8\u6709\u70b9\u592a\u5e95\u5c42\u4e86\uff0c\u4e00\u65f6\u95f4\u63a5\u53d7\u4e0d\u4e86&#8230;.\uff09\uff0c\u6240\u4ee5\u4e0d\u9009\u62e9\u8fd9\u4e2a\uff08\u8fd9\u4e2aPIO\u91cc\u9762\u4e5f\u6709\uff09\u3002<\/p>\n<p>\u8fd9\u91cc\u627e\u5230<code>STM32054<\/code>\uff0c\u540e\u9762\u7684\u63cf\u8ff0\u662fSTM32F10x\u6807\u51c6\u5916\u8bbe\u5e93\uff0c\u5c31\u662f\u4ed6\u4e86\uff0c\u70b9\u51fb\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\uff0c\u8fd9\u91cc\u9009\u62e9\u8bbf\u5ba2\u4e0b\u8f7d\uff08\u65b0\u4e00\u70b9\u7684IC\u6bd4\u5982STM32L031G6\u5df2\u7ecf\u53ea\u652f\u6301HAL\u4e86\uff09\u3002<\/p>\n<p>\u4e0b\u8f7d\u4e0b\u6765\u4e4b\u540e\uff0c\u5185\u90e8\u7684\u76ee\u5f55\u7ed3\u6784\u53ca\u5176\u4f5c\u7528\u5982\u4e0b<\/p>\n<pre><code class=\"language-ini\">STM32F10x_StdPeriph_Lib_V3.6.0\n\u251c\u2500\u2500 Libraries\n\u2502   \u251c\u2500\u2500 CMSIS &lt;-- RM Cortex-M\u7cfb\u5217\u7684\u6807\u51c6\u63a5\u53e3\n\u2502   \u2502   \u251c\u2500\u2500 CM3\n\u2502   \u2502   \u2502   \u251c\u2500\u2500 CoreSupport &lt;-- \u5305\u542bCortex-M3\u5185\u6838\u7684\u652f\u6301\u6587\u4ef6\n\u2502   \u2502   \u2502   \u2502   \u251c\u2500\u2500 core_cm3.c &lt;-- \u5185\u6838\u652f\u6301\u51fd\u6570\n\u2502   \u2502   \u2502   \u2502   \u2514\u2500\u2500 core_cm3.h &lt;-- Cortex-M3\u5185\u6838\u5b9a\u4e49\n\u2502   \u2502   \u2502   \u2514\u2500\u2500 DeviceSupport\n\u2502   \u2502   \u2502       \u2514\u2500\u2500 ST\n\u2502   \u2502   \u2502           \u2514\u2500\u2500 STM32F10x &lt;-- STM32F10x\u7cfb\u5217\u7279\u5b9a\u7684\u8bbe\u5907\u652f\u6301\u6587\u4ef6\n\u2502   \u2502   \u2502               \u251c\u2500\u2500 startup &lt;-- \u4e0d\u540cIC\u7684\u542f\u52a8\u6587\u4ef6\uff0c\u6c47\u7f16\u8bed\u8a00\u7f16\u5199\uff0c\u5b9a\u4e49\u4e2d\u65ad\u3001\u8bbe\u7f6e\u5806\u6808\u6307\u9488\u3001\u521d\u59cb\u5316\u7cfb\u7edf\u65f6\u949f\u3001\u6267\u884cmain\u51fd\u6570\uff0c\u7c7b\u4f3c\u7cfb\u7edf\u5f15\u5bfc\uff08bootloader\uff09\n\u2502   \u2502   \u2502               \u251c\u2500\u2500 LICENSE.txt\n\u2502   \u2502   \u2502               \u251c\u2500\u2500 Release_Notes.html\n\u2502   \u2502   \u2502               \u251c\u2500\u2500 stm32f10x.h &lt;-- \u6700\u6838\u5fc3\u7684\uff0c\u5305\u542b\u6240\u6709\u5bc4\u5b58\u5668\u5b9a\u4e49\n\u2502   \u2502   \u2502               \u251c\u2500\u2500 system_stm32f10x.c &lt;-- \u7cfb\u7edf\u521d\u59cb\u5316\u6e90\u6587\u4ef6\n\u2502   \u2502   \u2502               \u2514\u2500\u2500 system_stm32f10x.h &lt;-- \u7cfb\u7edf\u914d\u7f6e\u5934\u6587\u4ef6\n\u2502   \u2502   \u2514\u2500\u2500 Documentation\n\u2502   \u2514\u2500\u2500 STM32F10x_StdPeriph_Driver &lt;-- \u6807\u51c6\u5916\u8bbe\u5e93,\u4e3b\u8981\u4f7f\u7528\u8fd9\u90e8\u5206\n\u2502       \u251c\u2500\u2500 inc &lt;-- \u6240\u6709\u5916\u8bbe\u7684\u5934\u6587\u4ef6\n\u2502       \u2502   \u251c\u2500\u2500 misc.h\n\u2502       \u2502   \u251c\u2500\u2500 stm32f10x_adc.h &lt;-- ADC\u6a21\u6570\u8f6c\u6362\u5668\n\u2502       \u2502   \u251c\u2500\u2500 stm32f10x_bkp.h &lt;-- \u5907\u4efd\u5bc4\u5b58\u5668\n\u2502       \u2502   \u251c\u2500\u2500 stm32f10x_can.h &lt;-- CAN\u603b\u7ebf\n\u2502       \u2502   \u251c\u2500\u2500 ...\n\u2502       \u2502   \u2514\u2500\u2500 stm32f10x_wwdg.h &lt;-- \u7a97\u53e3\u770b\u95e8\u72d7\n\u2502       \u2514\u2500\u2500 src\n\u251c\u2500\u2500 Project\n\u2502   \u251c\u2500\u2500 STM32F10x_StdPeriph_Examples &lt;-- \u6240\u6709\u5916\u8bbe\u7684\u793a\u4f8b\u4ee3\u7801\n\u2502   \u2514\u2500\u2500 STM32F10x_StdPeriph_Template &lt;-- \u9879\u76ee\u6a21\u677f\n\u251c\u2500\u2500 Utilities\n\u2502   \u2514\u2500\u2500 STM32_EVAL &lt;-- \u5305\u542bST\u5b98\u65b9\u8bc4\u4f30\u677f\u7684\u677f\u7ea7\u652f\u6301\u5305(BSP)\uff0c\u9488\u5bf9\u5f00\u53d1\u677f\u7684\u8fdb\u4e00\u6b65\u786c\u4ef6\u62bd\u8c61\n\u2514\u2500\u2500 _htmresc &lt;-- HTML\u6587\u6863\u7684\u8d44\u6e90\u6587\u4ef6<\/code><\/pre>\n<p>\u8fd9\u91cc\u6211\u4eec\u9700\u8981\u7684\u5c31\u662fLibrary\u4e0b\u9762\u7684\u4e24\u4e2a\uff0cCMSIS\u662f\u6700\u5e95\u5c42\u7684\u652f\u6301\uff0cSTM32F10x_StdPeriph_Driver\u662f\u8981\u7528\u5230\u7684SPL\u672c\u8eab\uff0c\u6240\u4ee5\u628a\u8fd9\u4e24\u4e2a\u76ee\u5f55\u76f4\u63a5\u5b8c\u6574\u590d\u5236\u5230PIO\u9879\u76ee\u7684lib\u76ee\u5f55\u4e0b\uff0c\u4f5c\u4e3a\u5e93\u4f7f\u7528\u3002<\/p>\n<p>\u7136\u540e\u9700\u8981\u5728include\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a<code>stm32f10x_conf.h<\/code>\uff0c\u7528\u4e8e\u914d\u7f6e\u5934\u6587\u4ef6\uff0c\u5199\u5165\u4ee5\u4e0b\u5185\u5bb9\uff0c\u9700\u8981\u66f4\u591a\u5916\u8bbe\u5e93\u53ef\u4ee5\u518d\u6dfb\u52a0<\/p>\n<pre><code class=\"language-c\">#ifndef __STM32F10x_CONF_H\n#define __STM32F10x_CONF_H\n\n\/* \u5305\u542b\u9700\u8981\u7684\u5916\u8bbe\u5e93\u5934\u6587\u4ef6 *\/\n#include &quot;stm32f10x_gpio.h&quot;\n#include &quot;stm32f10x_rcc.h&quot;\n#include &quot;stm32f10x_usart.h&quot;\n#include &quot;stm32f10x_tim.h&quot;\n#include &quot;stm32f10x_adc.h&quot; \n#include &quot;stm32f10x_spi.h&quot;\n#include &quot;stm32f10x_i2c.h&quot;\n#include &quot;stm32f10x_dma.h&quot;\n\n\/* \u65ad\u8a00\u914d\u7f6e *\/\n#ifdef USE_FULL_ASSERT\n#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))\nvoid assert_failed(uint8_t* file, uint32_t line);\n#else\n#define assert_param(expr) ((void)0)\n#endif\n\n#endif \/* __STM32F10x_CONF_H *\/<\/code><\/pre>\n<p>\u8fd9\u65f6\u9879\u76ee\u662f\u4e0d\u80fd\u6b63\u5e38\u8dd1\u901a \u7684\uff0c\u56e0\u4e3a\u6ca1\u6709\u914d\u7f6e\u5bfc\u5165\u76ee\u5f55\uff0c\u9700\u8981\u914d\u7f6e\u9879\u76ee\u672c\u8eab\u7684\u8bbe\u7f6e\u3002<\/p>\n<p>\u9996\u5148\u628a\u9879\u76ee\u4fee\u6539\u6210CMSIS\u6846\u67b6\uff0c\u6700\u5e95\u5c42\u7684\uff0c\u4e0d\u9700\u8981\u4e0a\u5c42\u7684\u6846\u67b6\uff0c\u56e0\u4e3a\u6211\u4eec\u81ea\u5df1\u51c6\u5907\u4e86\u3002\u4fee\u6539<code>platformio.ini<\/code>\u4e2d\u7684framework\u4e3a<code>cmsis<\/code><\/p>\n<p>\u6dfb\u52a0\u4e0a<code>lib_extra_dirs = lib<\/code>\uff0c\u914d\u7f6elib\u4e3a\u7b2c\u4e09\u65b9\u5e93\u76ee\u5f55<\/p>\n<p>\u7136\u540e\u518d\u52a0\u4e0a\u4e00\u4e9b\u6784\u5efa\u9009\u9879\u9009\u9879\uff0c\u5982\u4e0b<\/p>\n<pre><code class=\"language-ini\">build_flags = \n    -DSTM32F10X_MD                                      ; \u5b9a\u4e49\u9884\u5904\u7406\u5668\u5b8f\uff0c\u6307\u5b9aSTM32F10x\u4e2d\u7b49\u5bb9\u91cf\u5668\u4ef6,F103C8\n    -DUSE_STDPERIPH_DRIVER                              ; \u5b9a\u4e49\u9884\u5904\u7406\u5668\u5b8f\uff0c\u544a\u8bc9\u7f16\u8bd1\u5668\u4f7f\u7528\u6807\u51c6\u5916\u8bbe\u5e93\n    -Ilib\/STM32F10x_StdPeriph_Driver\/inc                ; \u6dfb\u52a0\u5305\u542b\u8def\u5f84\uff1a\u6807\u51c6\u5916\u8bbe\u5e93\u5934\u6587\u4ef6\u76ee\u5f55\n    -Ilib\/CMSIS\/CM3\/CoreSupport                         ; \u6dfb\u52a0\u5305\u542b\u8def\u5f84\uff1aCMSIS Cortex-M3\u6838\u5fc3\u652f\u6301\u6587\u4ef6\u76ee\u5f55\n    -Ilib\/CMSIS\/CM3\/DeviceSupport\/ST\/STM32F10x          ; \u6dfb\u52a0\u5305\u542b\u8def\u5f84\uff1aSTM32F10x\u8bbe\u5907\u7279\u5b9a\u652f\u6301\u6587\u4ef6\u76ee\u5f55  \n    -Iinclude                                           ; \u6dfb\u52a0\u5305\u542b\u8def\u5f84\uff1a\u9879\u76ee\u81ea\u5b9a\u4e49\u5934\u6587\u4ef6\u76ee\u5f55<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u6109\u5feb\u7684\u7528\u6807\u51c6\u5e93\u7528STM32\u5199\u4ee3\u7801\u4e86\uff0c\u4f46\u662f\u4e0d\u80fd\u6109\u5feb\u7684\u7f16\u8bd1\u3002\u56e0\u4e3a\u53ea\u5236\u5b9a\u4e86-I\u7684\u5934\u6587\u4ef6\u76ee\u5f55\uff0c\u627e\u4e0d\u5230\u6e90\u4ee3\u7801\u76ee\u5f55\uff0c\u6211\u4eec\u6ca1\u6709\u6307\u5b9a\u3002<\/p>\n<p>\u901a\u8fc7build_src_filter\u6765\u6307\u5b9a\u6e90\u4ee3\u7801\u76ee\u5f55\uff0c\u5982\u4e0b\uff0c\u5236\u5b9a\u4e86\u6807\u51c6\u5e93\u4e0b\u7684src\u76ee\u5f55\uff0c\u6b64\u65f6\u5c31\u80fd\u6b63\u5e38\u7f16\u8bd1\u901a\u8fc7\u4e86<\/p>\n<pre><code class=\"language-ini\">build_src_filter =\n    +&lt;*&gt;\n    +&lt;..\/lib\/STM32F10x_StdPeriph_Driver\/src\/&gt;<\/code><\/pre>\n<p>\u5f53\u7136\u4e5f\u6709\u5f88\u591a\u7684\u6559\u7a0b\u9009\u62e9\u76f4\u63a5\u628a\u6e90\u4ee3\u7801\u62ff\u51fa\u6765\u653e\u5728\u9879\u76ee\u91cc\u9762\uff0c\u8fd9\u6837\u6bd5\u7adf\u4e0d\u662f\u5f88\u4f18\u96c5\uff0c\u8fd8\u8981\u52a8\u4eba\u5bb6\u7684\u5e93\u76ee\u5f55<\/p>\n<p>\u66f4\u591aPIO\u914d\u7f6e\u53c2\u8003<a href=\"https:\/\/docs.platformio.org\/en\/latest\/projectconf\/sections\/env\/options\/build\/index.html\" title=\"Build options \u2014 PlatformIO latest documentation\">Build options<\/a>\u3002<\/p>\n<p>\u6b64\u65f6\u5c31\u53ef\u4ee5\u6b63\u5e38\u7f16\u5199\u4ee3\u7801\u4e86\uff0c\u70b9\u4e2a\u706f\u8bd5\u4e00\u4e0b<\/p>\n<pre><code class=\"language-c\">#include &quot;stm32f10x.h&quot;\n\nint main(void) {\n\n    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);\n    GPIO_InitTypeDef GPIO_InitStructure;\n    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;\n    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;\n    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;\n    GPIO_Init(GPIOA, &amp;GPIO_InitStructure);\n    GPIO_WriteBit(GPIOA, GPIO_Pin_5, Bit_SET);\n}<\/code><\/pre>\n<p>\u6b63\u5e38\u7f16\u8bd1\uff0c\u53ef\u4ee5\u4eae\u706f\uff0c\u914d\u7f6e\u5b8c\u6bd5<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521d\u5b66STM32\u5d4c\u5165\u5f0f\u5f00\u53d1\uff0c\u65e8\u5728\u5b66\u4e60\u5d4c\u5165\u5f0f\u5f00\u53d1\u6d41\u7a0b\u548c\u539f\u7406\uff0c\u4ee5\u4fbf\u66f4\u5feb\u7684\u4e0a\u624b\u90a3\u4e9b\u4fbf\u5b9c\u7684\u56fd\u4ea7\u7684\u6ca1\u90a3\u4e48\u591a\u8d44\u6599\u7684IC\u3002 \u9009 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[142,144,143,104],"series":[],"class_list":["post-8073","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-platformio","tag-spl","tag-stm32","tag-104"],"_links":{"self":[{"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/posts\/8073","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/comments?post=8073"}],"version-history":[{"count":2,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/posts\/8073\/revisions"}],"predecessor-version":[{"id":8075,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/posts\/8073\/revisions\/8075"}],"wp:attachment":[{"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/media?parent=8073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/categories?post=8073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/tags?post=8073"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/series?post=8073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}