{"id":67,"date":"2021-07-30T15:48:00","date_gmt":"2021-07-30T15:48:00","guid":{"rendered":"https:\/\/zhewana.cn\/?p=67"},"modified":"2021-07-30T15:48:00","modified_gmt":"2021-07-30T15:48:00","slug":"67","status":"publish","type":"post","link":"https:\/\/zhewana.cn\/?p=67","title":{"rendered":"HAL\u5e93\u57fa\u672c\u51fd\u6570\uff08\u4e0b\uff09"},"content":{"rendered":"<h2>\u7cfb\u7edf\u76f8\u5173\u51fd\u6570<\/h2>\n<p>\u83b7\u53d6\u5f53\u524d\u7cfb\u7edf\u8fd0\u884c\u65f6\u95f4\u51fd\u6570\uff1a\u8fd4\u56de\u5f53\u524d\u7cfb\u7edf\u8fd0\u884c\u65f6\u95f4<\/p>\n<pre><code class=\"lang-C\">__weak uint32_t HAL_GetTick(void)\n{\n  return uwTick;\n}<\/code><\/pre>\n<p>\u5ef6\u65f6\u51fd\u6570\uff1a\u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d\u8fdb\u884c\u5ef6\u65f6<\/p>\n<pre><code class=\"lang-C\">__weak void HAL_Delay(uint32_t Delay)\n{\n  \/\/\u83b7\u53d6\u5f53\u524d\u7cfb\u7edf\u8fd0\u884c\u65f6\u95f4\n  uint32_t tickstart = HAL_GetTick();\n  uint32_t wait = Delay;\n\n  if (wait &lt; HAL_MAX_DELAY)\n  {\n    wait += (uint32_t)(uwTickFreq);\n  }\n\n  while((HAL_GetTick() - tickstart) &lt; wait)\n  {\n  }\n}<\/code><\/pre>\n<h2>\u5b9a\u65f6\u5668\u51fd\u6570<\/h2>\n<blockquote>\n<p>\u7531\u4e8e\u5305\u62ec\u5b9a\u65f6\u5668\u51fd\u6570\u5728\u5185\u7684\u5176\u4ed6\u51fd\u6570\u5185\u90e8\u5b9e\u73b0\u76f8\u8f83GPIO\u800c\u8a00\u6bd4\u8f83\u590d\u6742\uff0c\u56e0\u6b64\u5728\u6b64\u4e0d\u4f5c\u89e3\u8bfb\uff0c\u53ea\u662f\u7ed9\u51fa\u5e38\u7528\u51fd\u6570\u4f5c\u4e3a\u53c2\u8003<\/p>\n<\/blockquote>\n<pre><code class=\"lang-C\">\/\/\u5b9a\u65f6\u5668\u57fa\u7840\u529f\u80fd\u5f00\u542f\nHAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim);\n\/\/\u5b9a\u65f6\u5668\u57fa\u7840\u529f\u80fd\u5173\u95ed\nHAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim);\n\/\/\u5b9a\u65f6\u5668\u4e2d\u65ad\u529f\u80fd\u5f00\u542f\nHAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim);\n\/\/\u5b9a\u65f6\u5668\u4e2d\u65ad\u529f\u80fd\u5173\u95ed\nHAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim);\n\/\/\u5b9a\u65f6\u5668\u8f93\u51fa\u6bd4\u8f83\u5f00\u542f\nHAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel);\n\/\/\u5b9a\u65f6\u5668\u8f93\u51fa\u6bd4\u8f83\u5173\u95ed\nHAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);\n\/\/\u5b9a\u65f6\u5668\u8f93\u51fa\u6bd4\u8f83\u4e2d\u65ad\u5f00\u542f\nHAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);\n\/\/\u5b9a\u65f6\u5668\u8f93\u51fa\u6bd4\u8f83\u4e2d\u65ad\u5173\u95ed\nHAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);\n\/\/PWM\u8f93\u51fa\u5f00\u542f\nHAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel);\n\/\/PWM\u8f93\u51fa\u5173\u95ed\nHAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);<\/code><\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u8bb0\u5f97\u5728\u4f7f\u7528\u5b9a\u65f6\u5668\u76f8\u5173\u529f\u80fd\u4e4b\u524d\u5148\u6253\u5f00\u5bf9\u5e94\u7684\u529f\u80fd\uff0c\u5426\u5219\u5728\u67e5\u4e86\u4e00\u5929\u7684bug\u4e4b\u540e\u53d1\u73b0\u81ea\u5df1\u6ca1\u5f00\u5bf9\u5e94\u529f\u80fd\u7684\u90a3\u79cd\u611f\u89c9\u771f\u7684\u7ec8\u751f\u96be\u5fd8\u3002<\/p>\n<h2>\u4e32\u53e3\u51fd\u6570<\/h2>\n<pre><code class=\"lang-C\">\/\/\u4e32\u53e3\u53d1\u9001\u51fd\u6570\nHAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);\n\/\/\u4e32\u53e3\u63a5\u6536\u51fd\u6570\uff08\u963b\u585e\u6a21\u5f0f\uff09\nHAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);\n\/\/\u4e32\u53e3\u4e2d\u65ad\u53d1\u9001\u51fd\u6570\nHAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);\n\/\/\u4e32\u53e3\u4e2d\u65ad\u63a5\u6536\u51fd\u6570\uff08\u975e\u963b\u585e\u6a21\u5f0f\uff09\nHAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);\n\/\/\u4e32\u53e3DMA\u6a21\u5f0f\u53d1\u9001\u51fd\u6570\nHAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);\n\/\/\u4e32\u53e3DMA\u6a21\u5f0f\u63a5\u6536\u51fd\u6570\nHAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);<\/code><\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u4e32\u53e3\u63a5\u6536\u51fd\u6570\u5c31\u50cfscanf\u51fd\u6570\u4e00\u6837\uff0c\u4f1a\u963b\u585e\u7a0b\u5e8f\u7684\u8fd0\u884c\uff0c\u800c\u4e32\u53e3\u4e2d\u65ad\u51fd\u6570\u5219\u4e0d\u4f1a\u963b\u585e\u7a0b\u5e8f\u7684\u8fd0\u884c\u3002<\/p>\n<h3>\u5173\u4e8e\u4e32\u53e3\u91cd\u5b9a\u5411<\/h3>\n<p>MDK\u73af\u5883\u4e0b\u7684\u4e32\u53e3\u91cd\u5b9a\u5411\uff1a<\/p>\n<pre><code class=\"lang-C\">\/\/printf\u7684\u91cd\u5b9a\u5411\nint fputc(int ch, FILE *f){\n  HAL_UART_Transmit(&amp;huart1, (uint8_t *)&amp;ch, 1, 0xffff);\n  return ch;\n}\n\n\n\/\/scanf\u7684\u91cd\u5b9a\u5411\nint fgetc(FILE *f){\n  uint8_t ch = 0;\n  HAL_UART_Receive(&amp;huart1, &amp;ch, 1, 0xffff);\n  return ch;\n}<\/code><\/pre>\n<p>gcc\u73af\u5883\u4e0b\u7684\u4e32\u53e3\u91cd\u5b9a\u5411\uff1a<\/p>\n<pre><code class=\"lang-C\">\/\/\u5934\u6587\u4ef6\u5305\u542b\n#include &quot;stdio.h&quot;\n#include &quot;stdarg.h&quot;\n\/\/printf\u91cd\u5b9a\u5411\nint UART_printf(UART_HandleTypeDef *huart, const char *fmt, ...)\n{\n  va_list ap;\n  va_start(ap, fmt);\n\n  int length;\n  char buffer[128];\n    \n  length = vsnprintf(buffer, 128, fmt, ap);\n    \n  HAL_UART_Transmit(huart, (uint8_t *)buffer, length, HAL_MAX_DELAY);\n    \n  va_end(ap);\n  return length;\n}<\/code><\/pre>\n<p>\u66f4\u8be6\u7ec6\u7684\u65b9\u6cd5\u5728<a href=\"https:\/\/zhewana.cn\/index.php\/archives\/215\/\">\u8fd9\u7bc7\u6587\u7ae0<\/a>\u91cc\u9762\u6709\u8bf4\u8fc7\uff0c\u611f\u5174\u8da3\u7684\u8bdd\u53ef\u4ee5\u770b\u770b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7cfb\u7edf\u76f8\u5173\u51fd\u6570 \u83b7\u53d6\u5f53\u524d\u7cfb\u7edf\u8fd0\u884c\u65f6\u95f4\u51fd\u6570\uff1a\u8fd4\u56de\u5f53\u524d\u7cfb\u7edf\u8fd0\u884c\u65f6\u95f4 __weak uint32_t HAL_GetT [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[12],"class_list":["post-67","post","type-post","status-publish","format-standard","hentry","category-embedded","tag-12"],"_links":{"self":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts\/67","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=67"}],"version-history":[{"count":0,"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts\/67\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=67"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=67"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=67"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}