{"id":391824,"date":"2024-06-29T10:02:54","date_gmt":"2024-06-29T10:02:54","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=391824"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=391824","title":{"rendered":"<span>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a GPIO. \u0418\u043b\u0438 GPIO \u043a\u0430\u043a constexpr \u043a\u043b\u0430\u0441\u0441. \u0421++<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c, \u0436\u0438\u0442\u0435\u043b\u0438 \u0425\u0430\u0431\u0440\u0430. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043d\u0430 C++, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e constexpr \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0446\u0435\u043b\u044c\u044e \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u0443\u0440\u043e\u0432\u043d\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. <\/p>\n<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f: &#171;\u043d\u0435\u043b\u044c\u0437\u044f \u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a GPIO \u043f\u043e\u0440\u0442\u0430\u043c \u043d\u0430 STM32, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e  \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u043a\u043e\u0434\u0430 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438&#187;. \u0427\u0442\u043e \u044f \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c:<\/p>\n<ol>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0445 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043e\u043a \u0438 \u0430\u0432\u0442\u043e\u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 GPIO.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. 1-2 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<\/ol>\n<p>\u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u044f \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u043a\u0430\u043a \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u043e\u0440\u0442\u0430\u043c \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 Arduino, \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u0435\u043d \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0438\u0441\u043a \u043f\u043e\u0440\u0442\u0430 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435. \u0422\u0443\u0442 \u043c\u043d\u0435 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u043f\u0440\u0438\u0448\u043b\u0430 \u043c\u044b\u0441\u043b\u044c \u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 constexpr \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u043e\u0438\u0445 \u043f\u0443\u043d\u043a\u0442\u043e\u0432 \u0441\u0440\u0430\u0437\u0443. \u0418\u0442\u0430\u043a \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c. \u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0434 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043a\u0440\u043e\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u043c, \u0442.\u043a. \u043c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0447\u0442\u043e \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u044c HAL (Hardware Abstraction Layer). \u041a\u043e\u0434 \u0431\u044b\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0434\u043b\u044f \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 STM32F103xxx.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0430\u0434\u0440\u0435\u0441\u0430 \u043f\u043e\u0440\u0442\u043e\u0432. <\/p>\n<blockquote>\n<p>static constexpr const uint32_t GPIOA_BASE = 0x40010800;<\/p>\n<p>static constexpr const uint32_t GPIOB_BASE = 0x40010C00;<\/p>\n<p>static constexpr const uint32_t GPIOC_BASE = 0x40011000;<\/p>\n<\/blockquote>\n<div class=\"table\">\n<table>\n<tbody>\n<tr><\/tr>\n<tr><\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u043e\u0440\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b.<\/p>\n<blockquote>\n<p>enum class GpioMode : uint8_t {     <\/p>\n<p>InputAnalog = 0x00,<\/p>\n<p> InputFloating,<\/p>\n<p>InputWithPullup,<\/p>\n<p>OutputPushPull = 0x04,<\/p>\n<p>OutputOpenDrain,<\/p>\n<p>AlternatePushPull,<\/p>\n<p>AlternateOpenDrain <\/p>\n<p>};<\/p>\n<p>enum class GpioOutputSpeed : uint8_t {     <\/p>\n<p>Input,<\/p>\n<p>Max10Mhz,<\/p>\n<p>Max2Mhz,<\/p>\n<p>Max50Mhz <\/p>\n<p>};<\/p>\n<\/blockquote>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0440\u0442\u0430. \u041a\u043b\u0430\u0441\u0441 \u043e\u0444\u043e\u0440\u043c\u0438\u043c \u0432 \u0432\u0438\u0434\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0430. \u0412\u0441\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043a\u0430\u043a static inline. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430. \u0428\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u043e\u0440\u0432 \u0432 \u0432\u0438\u0434\u0435 constexpr \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0422.\u0435. \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0430 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d \u0434\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438. \u0412 \u0438\u0434\u0435\u0430\u043b\u0435 \u0434\u043e \u043e\u0434\u043d\u043e\u0439-\u0434\u0432\u0443\u0445 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u043a \u043f\u043e\u0440\u0442\u0443, \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0441 \u043e\u043f\u0446\u0438\u0435\u0439 &#171;-O0&#187;. \u0412 \u0432\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u043e\u0440\u0442\u0430\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0431\u0430\u0440\u044c\u0435\u0440\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 dsb. <\/p>\n<p>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435. \u041d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f\u0445 \u0447\u0430\u0441\u0442\u043e \u0437\u0430\u0434\u0430\u044e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u043f\u0440\u043e volatile, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044f\u0433\u043a\u043e \u0433\u043e\u0432\u043e\u0440\u044f \u0437\u0430\u0434\u043e\u043b\u0431\u0430\u043b\u0438 \u0443\u0436\u0435. \u0423 \u043c\u0435\u043d\u044f \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0441\u044c\u0431\u0430 \u043a \u0442\u0435\u043c \u043a\u0442\u043e \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0441\u0444\u0435\u0440\u0435 embedded: &#171;\u043d\u0435 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0432\u044b \u0441 \u0445\u043e\u0434\u0443, \u043d\u0435 \u043f\u043e\u0434\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u044f, \u0441\u0432\u043e\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u044b \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 dmb, dsb \u0438 isb \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043a\u043e\u043c\u0430\u043d\u0434 arm&#187;? \u041f\u043e\u043b\u0430\u0433\u0430\u044e, \u0432\u043e\u043f\u0440\u043e\u0441 \u043f\u0440\u043e volatile \u043e\u0442\u043f\u0430\u0434\u0435\u0442 \u0441\u0430\u043c \u0441\u043e\u0431\u043e\u0439.<\/p>\n<pre><code>template&lt;uint32_t GpioAddr, uint8_t pinNo>  struct GpioPin {       static constexpr const uint32_t GpioAddress = GpioAddr; static constexpr const uint8_t  GpioPinNo = pinNo; static constexpr const uint32_t GpioPinMask = (1 &lt;&lt; pinNo); static constexpr const uint32_t GpioConfPerReg = 8;  static inline void mode(const GpioMode mode, const GpioOutputSpeed oSpeed = GpioOutputSpeed::Input){     if constexpr (GpioPinNo &lt; GpioConfPerReg){         static constexpr const uint32_t maskBitCount = 4;         static constexpr const uint32_t maskOffset = (pinNo * maskBitCount) &amp; 0x1F;         static constexpr const uint32_t mask = (1 &lt;&lt; (maskBitCount + 1)) - 1;         reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->CRL &amp;= ~(mask &lt;&lt; maskOffset);         reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->CRL |= ((static_cast&lt;uint32_t>(mode) &amp; 0x03) &lt;&lt; maskOffset);         reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->CRL |= ((static_cast&lt;uint32_t>(oSpeed) &amp; 0x03) &lt;&lt; (maskOffset + 2));     } else {         \/\/ Error         \/\/ TO DO: add error compile time error message.      } }  static inline bool get() {     return (reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->IDR &amp; GpioPinMask); }  static inline void set() {     reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->BSRR = GpioPinMask;     asm volatile(\"dsb;\"); }  static inline void reset(){     reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->BRR = GpioPinMask;     asm volatile(\"dsb;\"); }  static inline void invert(){     reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->ODR ^= GpioPinMask;     asm volatile(\"dsb;\"); }  }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u043e\u0432 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0440\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043a \u0442\u0438\u043f\u0443 \u0430\u0434\u0440\u0435\u0441\u043e\u0432.<\/p>\n<blockquote>\n<p>#define GPIOA (reinterpret_cast&lt;volatile GPIO* const>(GPIOA_BASE)) <\/p>\n<p>#define GPIOB (reinterpret_cast&lt;volatile GPIO* const>(GPIOB_BASE))<\/p>\n<p> #define GPIOC (reinterpret_cast&lt;volatile GPIO* const>(GPIOC_BASE))<\/p>\n<\/blockquote>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c constexpr \u043a\u043b\u0430\u0441\u0441\u044b:<\/p>\n<p>constexpr const GpioPin&lt;GPIOA_BASE, 0> PA0; <\/p>\n<p>constexpr const GpioPin&lt;GPIOA_BASE, 1> PA1; <\/p>\n<p>constexpr const GpioPin&lt;GPIOA_BASE, 2> PA2;<\/p>\n<p>constexpr const GpioPin&lt;GPIOB_BASE, 0> PB0;<\/p>\n<p> constexpr const GpioPin&lt;GPIOB_BASE, 1> PB1; <\/p>\n<p>constexpr const GpioPin&lt;GPIOB_BASE, 2> PB2; <\/p>\n<p>constexpr const GpioPin&lt;GPIOB_BASE, 3> PB3;<\/p>\n<p>&#8230;..<\/p>\n<p>constexpr const GpioPin&lt;GPIOC_BASE, 0> PC0; <\/p>\n<p>constexpr const GpioPin&lt;GPIOC_BASE, 1> PC1;<\/p>\n<p>constexpr const GpioPin&lt;GPIOC_BASE, 2> PC2; <\/p>\n<p>\u0427\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0440\u043e\u0432\u0430\u0442\u044c? \u0412\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0430\u0434\u0440\u0435\u0441\u043e\u0432.<\/p>\n<p>\u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043d\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u043f\u0438\u0440\u0443\u0435\u0442\u0441\u0441\u044f \u0432 2-3 \u0438\u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0430\u0432\u0442\u043e\u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043f\u043e\u043a\u0440\u0430\u0439\u043d\u0435 \u043c\u0435\u0440\u0435 \u0432 eclipse.<\/p>\n<p>PA0.set();<\/p>\n<p> PA0.invert();<\/p>\n<p> PA0.set();<\/p>\n<p> PA0.reset();<\/p>\n<p> PA0.invert();<\/p>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>\u041a\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435:<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p><a href=\"https:\/\/github.com\/hwswdevelop\/BluePillUsbDebugPrototyping\/blob\/main\/Template\/System\/Core\/gpio.h\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/hwswdevelop\/BluePillUsbDebugPrototyping\/blob\/main\/Template\/System\/Core\/gpio.h<\/a><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/578836\/\"> https:\/\/habr.com\/ru\/articles\/578836\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c, \u0436\u0438\u0442\u0435\u043b\u0438 \u0425\u0430\u0431\u0440\u0430. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043d\u0430 C++, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e constexpr \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0446\u0435\u043b\u044c\u044e \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u0443\u0440\u043e\u0432\u043d\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. <\/p>\n<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f: &#171;\u043d\u0435\u043b\u044c\u0437\u044f \u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a GPIO \u043f\u043e\u0440\u0442\u0430\u043c \u043d\u0430 STM32, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e  \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u043a\u043e\u0434\u0430 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438&#187;. \u0427\u0442\u043e \u044f \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c:<\/p>\n<ol>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0445 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043e\u043a \u0438 \u0430\u0432\u0442\u043e\u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 GPIO.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. 1-2 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<\/ol>\n<p>\u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u044f \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u043a\u0430\u043a \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u043e\u0440\u0442\u0430\u043c \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 Arduino, \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u0435\u043d \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0438\u0441\u043a \u043f\u043e\u0440\u0442\u0430 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435. \u0422\u0443\u0442 \u043c\u043d\u0435 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u043f\u0440\u0438\u0448\u043b\u0430 \u043c\u044b\u0441\u043b\u044c \u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 constexpr \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u043e\u0438\u0445 \u043f\u0443\u043d\u043a\u0442\u043e\u0432 \u0441\u0440\u0430\u0437\u0443. \u0418\u0442\u0430\u043a \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c. \u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0434 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043a\u0440\u043e\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u043c, \u0442.\u043a. \u043c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0447\u0442\u043e \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u044c HAL (Hardware Abstraction Layer). \u041a\u043e\u0434 \u0431\u044b\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0434\u043b\u044f \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 STM32F103xxx.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0430\u0434\u0440\u0435\u0441\u0430 \u043f\u043e\u0440\u0442\u043e\u0432. <\/p>\n<blockquote>\n<p>static constexpr const uint32_t GPIOA_BASE = 0x40010800;<\/p>\n<p>static constexpr const uint32_t GPIOB_BASE = 0x40010C00;<\/p>\n<p>static constexpr const uint32_t GPIOC_BASE = 0x40011000;<\/p>\n<\/blockquote>\n<div class=\"table\">\n<table>\n<tbody>\n<tr><\/tr>\n<tr><\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u043e\u0440\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b.<\/p>\n<blockquote>\n<p>enum class GpioMode : uint8_t {     <\/p>\n<p>InputAnalog = 0x00,<\/p>\n<p> InputFloating,<\/p>\n<p>InputWithPullup,<\/p>\n<p>OutputPushPull = 0x04,<\/p>\n<p>OutputOpenDrain,<\/p>\n<p>AlternatePushPull,<\/p>\n<p>AlternateOpenDrain <\/p>\n<p>};<\/p>\n<p>enum class GpioOutputSpeed : uint8_t {     <\/p>\n<p>Input,<\/p>\n<p>Max10Mhz,<\/p>\n<p>Max2Mhz,<\/p>\n<p>Max50Mhz <\/p>\n<p>};<\/p>\n<\/blockquote>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0440\u0442\u0430. \u041a\u043b\u0430\u0441\u0441 \u043e\u0444\u043e\u0440\u043c\u0438\u043c \u0432 \u0432\u0438\u0434\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0430. \u0412\u0441\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043a\u0430\u043a static inline. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430. \u0428\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u043e\u0440\u0432 \u0432 \u0432\u0438\u0434\u0435 constexpr \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0422.\u0435. \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0430 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d \u0434\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438. \u0412 \u0438\u0434\u0435\u0430\u043b\u0435 \u0434\u043e \u043e\u0434\u043d\u043e\u0439-\u0434\u0432\u0443\u0445 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u043a \u043f\u043e\u0440\u0442\u0443, \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0441 \u043e\u043f\u0446\u0438\u0435\u0439 &#171;-O0&#187;. \u0412 \u0432\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u043e\u0440\u0442\u0430\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0431\u0430\u0440\u044c\u0435\u0440\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 dsb. <\/p>\n<p>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435. \u041d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f\u0445 \u0447\u0430\u0441\u0442\u043e \u0437\u0430\u0434\u0430\u044e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u043f\u0440\u043e volatile, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044f\u0433\u043a\u043e \u0433\u043e\u0432\u043e\u0440\u044f \u0437\u0430\u0434\u043e\u043b\u0431\u0430\u043b\u0438 \u0443\u0436\u0435. \u0423 \u043c\u0435\u043d\u044f \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0441\u044c\u0431\u0430 \u043a \u0442\u0435\u043c \u043a\u0442\u043e \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0441\u0444\u0435\u0440\u0435 embedded: &#171;\u043d\u0435 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0432\u044b \u0441 \u0445\u043e\u0434\u0443, \u043d\u0435 \u043f\u043e\u0434\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u044f, \u0441\u0432\u043e\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u044b \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 dmb, dsb \u0438 isb \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043a\u043e\u043c\u0430\u043d\u0434 arm&#187;? \u041f\u043e\u043b\u0430\u0433\u0430\u044e, \u0432\u043e\u043f\u0440\u043e\u0441 \u043f\u0440\u043e volatile \u043e\u0442\u043f\u0430\u0434\u0435\u0442 \u0441\u0430\u043c \u0441\u043e\u0431\u043e\u0439.<\/p>\n<pre><code>template&lt;uint32_t GpioAddr, uint8_t pinNo>  struct GpioPin {       static constexpr const uint32_t GpioAddress = GpioAddr; static constexpr const uint8_t  GpioPinNo = pinNo; static constexpr const uint32_t GpioPinMask = (1 &lt;&lt; pinNo); static constexpr const uint32_t GpioConfPerReg = 8;  static inline void mode(const GpioMode mode, const GpioOutputSpeed oSpeed = GpioOutputSpeed::Input){     if constexpr (GpioPinNo &lt; GpioConfPerReg){         static constexpr const uint32_t maskBitCount = 4;         static constexpr const uint32_t maskOffset = (pinNo * maskBitCount) &amp; 0x1F;         static constexpr const uint32_t mask = (1 &lt;&lt; (maskBitCount + 1)) - 1;         reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->CRL &amp;= ~(mask &lt;&lt; maskOffset);         reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->CRL |= ((static_cast&lt;uint32_t>(mode) &amp; 0x03) &lt;&lt; maskOffset);         reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->CRL |= ((static_cast&lt;uint32_t>(oSpeed) &amp; 0x03) &lt;&lt; (maskOffset + 2));     } else {         \/\/ Error         \/\/ TO DO: add error compile time error message.      } }  static inline bool get() {     return (reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->IDR &amp; GpioPinMask); }  static inline void set() {     reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->BSRR = GpioPinMask;     asm volatile(\"dsb;\"); }  static inline void reset(){     reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->BRR = GpioPinMask;     asm volatile(\"dsb;\"); }  static inline void invert(){     reinterpret_cast&lt;volatile GPIO* const>(GpioAddress)->ODR ^= GpioPinMask;     asm volatile(\"dsb;\"); }  }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u043e\u0432 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0440\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043a \u0442\u0438\u043f\u0443 \u0430\u0434\u0440\u0435\u0441\u043e\u0432.<\/p>\n<blockquote>\n<p>#define GPIOA (reinterpret_cast&lt;volatile GPIO* const>(GPIOA_BASE)) <\/p>\n<p>#define GPIOB (reinterpret_cast&lt;volatile GPIO* const>(GPIOB_BASE))<\/p>\n<p> #define GPIOC (reinterpret_cast&lt;volatile GPIO* const>(GPIOC_BASE))<\/p>\n<\/blockquote>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c constexpr \u043a\u043b\u0430\u0441\u0441\u044b:<\/p>\n<p>constexpr const GpioPin&lt;GPIOA_BASE, 0> PA0; <\/p>\n<p>constexpr const GpioPin&lt;GPIOA_BASE, 1> PA1; <\/p>\n<p>constexpr const GpioPin&lt;GPIOA_BASE, 2> PA2;<\/p>\n<p>constexpr const GpioPin&lt;GPIOB_BASE, 0> PB0;<\/p>\n<p> constexpr const GpioPin&lt;GPIOB_BASE, 1> PB1; <\/p>\n<p>constexpr const GpioPin&lt;GPIOB_BASE, 2> PB2; <\/p>\n<p>constexpr const GpioPin&lt;GPIOB_BASE, 3> PB3;<\/p>\n<p>&#8230;..<\/p>\n<p>constexpr const GpioPin&lt;GPIOC_BASE, 0> PC0; <\/p>\n<p>constexpr const GpioPin&lt;GPIOC_BASE, 1> PC1;<\/p>\n<p>constexpr const GpioPin&lt;GPIOC_BASE, 2> PC2; <\/p>\n<p>\u0427\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0440\u043e\u0432\u0430\u0442\u044c? \u0412\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0430\u0434\u0440\u0435\u0441\u043e\u0432.<\/p>\n<p>\u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043d\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u043f\u0438\u0440\u0443\u0435\u0442\u0441\u0441\u044f \u0432 2-3 \u0438\u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0430\u0432\u0442\u043e\u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043f\u043e\u043a\u0440\u0430\u0439\u043d\u0435 \u043c\u0435\u0440\u0435 \u0432 eclipse.<\/p>\n<p>PA0.set();<\/p>\n<p> PA0.invert();<\/p>\n<p> PA0.set();<\/p>\n<p> PA0.reset();<\/p>\n<p> PA0.invert();<\/p>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>\u041a\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435:<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p><a href=\"https:\/\/github.com\/hwswdevelop\/BluePillUsbDebugPrototyping\/blob\/main\/Template\/System\/Core\/gpio.h\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/hwswdevelop\/BluePillUsbDebugPrototyping\/blob\/main\/Template\/System\/Core\/gpio.h<\/a><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/578836\/\"> https:\/\/habr.com\/ru\/articles\/578836\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-391824","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/391824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=391824"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/391824\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=391824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=391824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=391824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}